Skip to content
Browse files

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

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 <>
Signed-off-by: Alan Stern <>
Tested-by: Andrey Konovalov <>
CC: <>
Signed-off-by: Greg Kroah-Hartman <>
  • Loading branch information
AlanStern authored and gregkh committed Oct 18, 2017
1 parent 671632a commit 1c0edc3633b56000e18d82fc241e3995ca18a69e
Showing with 4 additions and 2 deletions.
  1. +4 −2 drivers/usb/core/config.c
@@ -960,10 +960,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;
length = cap->bLength;
total_len -= length;

if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {

0 comments on commit 1c0edc3

Please sign in to comment.
You can’t perform that action at this time.