]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
usb: gadget: composite: fix incorrect handling of OS desc requests
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 1 Jan 2018 02:59:42 +0000 (18:59 -0800)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 14 Aug 2018 10:28:50 +0000 (12:28 +0200)
commit50fe56f456d2151dde735e540ac9191b6e48be19
tree9bd731b3d7a9f321781058fd8308f45ad9106136
parenta9e4c8304bb1f3c486b2348b6f8760a6fdd10061
usb: gadget: composite: fix incorrect handling of OS desc requests

BugLink: http://bugs.launchpad.net/bugs/1783418
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/usb/gadget/composite.c
include/linux/usb/composite.h