Skip to content

Commit 13713e6

Browse files
committed
USB: fix out-of-bounds in usb_set_configuration
commit bd7a3fe770ebd8391d1c7d072ff88e9e76d063eb upstream. Andrey Konovalov reported a possible out-of-bounds problem for a USB interface association descriptor. He writes: It seems there's no proper size check of a USB_DT_INTERFACE_ASSOCIATION descriptor. It's only checked that the size is >= 2 in usb_parse_configuration(), so find_iad() might do out-of-bounds access to intf_assoc->bInterfaceCount. And he's right, we don't check for crazy descriptors of this type very well, so resolve this problem. Yet another issue found by syzkaller... Reported-by: Andrey Konovalov <andreyknvl@google.com> Tested-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ddcbaf8 commit 13713e6

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/usb/core/config.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,23 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
609609

610610
} else if (header->bDescriptorType ==
611611
USB_DT_INTERFACE_ASSOCIATION) {
612+
struct usb_interface_assoc_descriptor *d;
613+
614+
d = (struct usb_interface_assoc_descriptor *)header;
615+
if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {
616+
dev_warn(ddev,
617+
"config %d has an invalid interface association descriptor of length %d, skipping\n",
618+
cfgno, d->bLength);
619+
continue;
620+
}
621+
612622
if (iad_num == USB_MAXIADS) {
613623
dev_warn(ddev, "found more Interface "
614624
"Association Descriptors "
615625
"than allocated for in "
616626
"configuration %d\n", cfgno);
617627
} else {
618-
config->intf_assoc[iad_num] =
619-
(struct usb_interface_assoc_descriptor
620-
*)header;
628+
config->intf_assoc[iad_num] = d;
621629
iad_num++;
622630
}
623631

include/uapi/linux/usb/ch9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ struct usb_interface_assoc_descriptor {
717717
__u8 iFunction;
718718
} __attribute__ ((packed));
719719

720+
#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
720721

721722
/*-------------------------------------------------------------------------*/
722723

0 commit comments

Comments
 (0)