Skip to content

Commit 2e1c423

Browse files
committed
USB: core: harden cdc_parse_cdc_header
Andrey Konovalov reported a possible out-of-bounds problem for the cdc_parse_cdc_header function. He writes: It looks like cdc_parse_cdc_header() doesn't validate buflen before accessing buffer[1], buffer[2] and so on. The only check present is while (buflen > 0). So fix this issue up by properly validating the buffer length matches what the descriptor says it is. 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 60e70ec commit 2e1c423

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/usb/core/message.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,10 @@ int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr,
20692069
elength = 1;
20702070
goto next_desc;
20712071
}
2072+
if ((buflen < elength) || (elength < 3)) {
2073+
dev_err(&intf->dev, "invalid descriptor buffer length\n");
2074+
break;
2075+
}
20722076
if (buffer[1] != USB_DT_CS_INTERFACE) {
20732077
dev_err(&intf->dev, "skipping garbage\n");
20742078
goto next_desc;

0 commit comments

Comments
 (0)