Skip to content

Commit

Permalink
USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor()
Browse files Browse the repository at this point in the history
commit 1c0edc3 upstream.

Andrey used the syzkaller fuzzer to find an out-of-bounds memory access
in usb_get_bos_descriptor().  The code wasn't checking that the next
usb_dev_cap_header structure could fit into the remaining buffer space.

This patch fixes the error and also reduces the bNumDeviceCaps field in
the header to match the actual number of capabilities found, in cases
where there are fewer than expected.

Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
Jeroen Roovers committed Feb 23, 2018
1 parent e678ffb commit 2036dc7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/usb/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,12 @@ int usb_get_bos_descriptor(struct usb_device *dev)
for (i = 0; i < num; i++) {
buffer += length;
cap = (struct usb_dev_cap_header *)buffer;
length = cap->bLength;

if (total_len < length)
if (total_len < sizeof(*cap) || total_len < cap->bLength) {
dev->bos->desc->bNumDeviceCaps = i;
break;
}
length = cap->bLength;
total_len -= length;

if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
Expand Down

0 comments on commit 2036dc7

Please sign in to comment.