Skip to content

Commit 9dff499

Browse files
AlanSterngregkh
authored andcommitted
USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor()
commit 1c0edc3633b56000e18d82fc241e3995ca18a69e 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>
1 parent abe43c9 commit 9dff499

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/usb/core/config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,12 @@ int usb_get_bos_descriptor(struct usb_device *dev)
926926
for (i = 0; i < num; i++) {
927927
buffer += length;
928928
cap = (struct usb_dev_cap_header *)buffer;
929-
length = cap->bLength;
930929

931-
if (total_len < length)
930+
if (total_len < sizeof(*cap) || total_len < cap->bLength) {
931+
dev->bos->desc->bNumDeviceCaps = i;
932932
break;
933+
}
934+
length = cap->bLength;
933935
total_len -= length;
934936

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

0 commit comments

Comments
 (0)