Skip to content

Commit 1c0edc3

Browse files
AlanSterngregkh
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]>
1 parent 671632a commit 1c0edc3

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
@@ -960,10 +960,12 @@ int usb_get_bos_descriptor(struct usb_device *dev)
960960
for (i = 0; i < num; i++) {
961961
buffer += length;
962962
cap = (struct usb_dev_cap_header *)buffer;
963-
length = cap->bLength;
964963

965-
if (total_len < length)
964+
if (total_len < sizeof(*cap) || total_len < cap->bLength) {
965+
dev->bos->desc->bNumDeviceCaps = i;
966966
break;
967+
}
968+
length = cap->bLength;
967969
total_len -= length;
968970

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

0 commit comments

Comments
 (0)