summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2017-12-31 18:59:42 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-30 07:47:42 +0200
commit40c1020f0ef83fc07b0d746bc71ff88151508fe3 (patch)
tree30660f5fc8c0d9dbeb3a0deb5ec8f05ea810015e /include
parent10bedea0174a764bc5608890a161e619b1eb1870 (diff)
downloadlinux-stable-40c1020f0ef83fc07b0d746bc71ff88151508fe3.tar.gz
linux-stable-40c1020f0ef83fc07b0d746bc71ff88151508fe3.tar.bz2
linux-stable-40c1020f0ef83fc07b0d746bc71ff88151508fe3.zip
usb: gadget: composite: fix incorrect handling of OS desc requests
[ Upstream commit 5d6ae4f0da8a64a185074dabb1b2f8c148efa741 ] When handling an OS descriptor request, one of the first operations is to zero out the request buffer using the wLength from the setup packet. There is no bounds checking, so a wLength > 4096 would clobber memory adjacent to the request buffer. Fix this by taking the min of wLength and the request buffer length prior to the memset. While at it, define the buffer length in a header file so that magic numbers don't appear throughout the code. When returning data to the host, the data length should be the min of the wLength and the valid data we have to return. Currently we are returning wLength, thus requests for a wLength greater than the amount of data in the OS descriptor buffer would return invalid (albeit zero'd) data following the valid descriptor data. Fix this by counting the number of bytes when constructing the data and using this when determining the length of the request. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/usb/composite.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index c330f5ef42cf..c3f4904ea021 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -53,6 +53,9 @@
/* big enough to hold our biggest descriptor */
#define USB_COMP_EP0_BUFSIZ 1024
+/* OS feature descriptor length <= 4kB */
+#define USB_COMP_EP0_OS_DESC_BUFSIZ 4096
+
#define USB_MS_TO_HS_INTERVAL(x) (ilog2((x * 1000 / 125)) + 1)
struct usb_configuration;