Skip to content

Commit bd7a3fe

Browse files
committed
USB: fix out-of-bounds in usb_set_configuration
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 <[email protected]> Tested-by: Andrey Konovalov <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bcd6a7a commit bd7a3fe

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/usb/core/config.c

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

644644
} else if (header->bDescriptorType ==
645645
USB_DT_INTERFACE_ASSOCIATION) {
646+
struct usb_interface_assoc_descriptor *d;
647+
648+
d = (struct usb_interface_assoc_descriptor *)header;
649+
if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {
650+
dev_warn(ddev,
651+
"config %d has an invalid interface association descriptor of length %d, skipping\n",
652+
cfgno, d->bLength);
653+
continue;
654+
}
655+
646656
if (iad_num == USB_MAXIADS) {
647657
dev_warn(ddev, "found more Interface "
648658
"Association Descriptors "
649659
"than allocated for in "
650660
"configuration %d\n", cfgno);
651661
} else {
652-
config->intf_assoc[iad_num] =
653-
(struct usb_interface_assoc_descriptor
654-
*)header;
662+
config->intf_assoc[iad_num] = d;
655663
iad_num++;
656664
}
657665

include/uapi/linux/usb/ch9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ struct usb_interface_assoc_descriptor {
780780
__u8 iFunction;
781781
} __attribute__ ((packed));
782782

783+
#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
783784

784785
/*-------------------------------------------------------------------------*/
785786

0 commit comments

Comments
 (0)