Skip to contentSkip to conversation

USB: core: prevent malicious bNumInterfaces overflow

DISCUSSION Greg KH 1 participant 1 message Dec 13, 2017 USB

lore
Share & tools
lore

Greg KH

author
#0 lore raw
Quoted 31 lines · Peter Chen
Quoted 30 lines · Alan Stern

A malicious USB device with crafted descriptors can cause the kernel to access unallocated memory by setting the bNumInterfaces value too high in a configuration descriptor. Although the value is adjusted during parsing, this adjustment is skipped in one of the error return paths.

This patch prevents the problem by setting bNumInterfaces to 0 initially. The existing code already sets it to the proper value after parsing is complete.

---

[as1855]

 drivers/usb/core/config.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: usb-4.x/drivers/usb/core/config.c
===================================================================

drivers/usb/core/config.c +0 -0
@@ -555,6 +555,9 @@ static int usb_parse_configuration(struc
 	unsigned iad_num = 0;
 
Quoted 6 lines

drivers/usb/core/config.c static int usb_parse_configuration(struc · line 560

Quoted 4 lines
drivers/usb/core/config.c +3 -0
 	memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
+	nintf = nintf_orig = config->desc.bNumInterfaces;
+	config->desc.bNumInterfaces = 0;	// Adjusted later
+

The comment format?

Is fine, I've given up that fight :)

greg k-h
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html