Skip to content

Commit 34955d6

Browse files
AlanSternKirtikar Kashyap
authored andcommitted
USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor()
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 <[email protected]> Signed-off-by: Alan Stern <[email protected]> Tested-by: Andrey Konovalov <[email protected]> CC: <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 1c0edc3) Orabug: 27207955 CVE: CVE-2017-16535 Signed-off-by: Kirtikar Kashyap <[email protected]> Reviewed-by: Jack Vogel <[email protected]>
1 parent 6ab2d4c commit 34955d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/usb/core/config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,12 @@ int usb_get_bos_descriptor(struct usb_device *dev)
830830
for (i = 0; i < num; i++) {
831831
buffer += length;
832832
cap = (struct usb_dev_cap_header *)buffer;
833-
length = cap->bLength;
834833

835-
if (total_len < length)
834+
if (total_len < sizeof(*cap) || total_len < cap->bLength) {
835+
dev->bos->desc->bNumDeviceCaps = i;
836836
break;
837+
}
838+
length = cap->bLength;
837839
total_len -= length;
838840

839841
if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {

0 commit comments

Comments
 (0)