usb: dwc3: gadget: Don't setup more than requested
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Fri, 7 Aug 2020 02:46:23 +0000 (19:46 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:29:48 +0000 (11:29 +0200)
commitd884a90cec5ace7ca767788ca574e68f9af2998a
tree71d4fa69a24b725bd628c6baa8518c1d7cbbc468
parent3b9953fe57234e19f0ca333c5ff05b22e38790e2
usb: dwc3: gadget: Don't setup more than requested

commit 5d187c0454ef4c5e046a81af36882d4d515922ec upstream.

The SG list may be set up with entry size more than the requested
length. Check the usb_request->length and make sure that we don't setup
the TRBs to send/receive more than requested. This case may occur when
the SG entry is allocated up to a certain minimum size, but the request
length is less than that. It can also occur when the request is reused
for a different request length.

Cc: <stable@vger.kernel.org> # v4.18+
Fixes: a31e63b608ff ("usb: dwc3: gadget: Correct handling of scattergather lists")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/gadget.c