Skip to content

Commit d96302a

Browse files
gregkhTim Tianyang Chen
authored andcommitted
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]> (cherry picked from commit bd7a3fe) Orabug: 27207211 CVE: CVE-2017-16531 Signed-off-by: Tim Tianyang Chen <[email protected]> Reviewed-by: Reviewed-by: Jack Vogel <[email protected]>
1 parent d49dcb4 commit d96302a

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
@@ -521,15 +521,23 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
521521

522522
} else if (header->bDescriptorType ==
523523
USB_DT_INTERFACE_ASSOCIATION) {
524+
struct usb_interface_assoc_descriptor *d;
525+
526+
d = (struct usb_interface_assoc_descriptor *)header;
527+
if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {
528+
dev_warn(ddev,
529+
"config %d has an invalid interface association descriptor of length %d, skipping\n",
530+
cfgno, d->bLength);
531+
continue;
532+
}
533+
524534
if (iad_num == USB_MAXIADS) {
525535
dev_warn(ddev, "found more Interface "
526536
"Association Descriptors "
527537
"than allocated for in "
528538
"configuration %d\n", cfgno);
529539
} else {
530-
config->intf_assoc[iad_num] =
531-
(struct usb_interface_assoc_descriptor
532-
*)header;
540+
config->intf_assoc[iad_num] = d;
533541
iad_num++;
534542
}
535543

include/uapi/linux/usb/ch9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ struct usb_interface_assoc_descriptor {
705705
__u8 iFunction;
706706
} __attribute__ ((packed));
707707

708+
#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
708709

709710
/*-------------------------------------------------------------------------*/
710711

0 commit comments

Comments
 (0)