Skip to contentSkip to conversation

USB: array-index-out-of-bounds in ehci_brcm_hub_control

PATCH In review Haimin Zhang 2 participants 2 messages Nov 2, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: array-index-out-of-bounds in ehci_brcm_hub_control

There isn't enough check parameter wIndex in the function ehci_brcm_hub_control;due to the size of array port_status is 15, so it may lead to out of bounds.

---
 drivers/usb/host/ehci-brcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-brcm.c +2 -1
index d3626bfa966b..4ca3eb9fcda9 100644
@@ -63,7 +63,8 @@ static int ehci_brcm_hub_control(
 	unsigned long flags;
 	int retval, irq_disabled = 0;
 
-	status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
+	if (wIndex && wIndex <= ports)
+		status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
 
 	/*
 	 * RESUME is cleared when GetPortStatus() is called 20ms after start
maintainer
#1 lore raw
Quoted 15 lines · Haimin Zhang

There isn't enough check parameter wIndex in the function ehci_brcm_hub_control;due to the size of array port_status is 15, so it may lead to out of bounds.

---
 drivers/usb/host/ehci-brcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-brcm.c +0 -0
index d3626bfa966b..4ca3eb9fcda9 100644

drivers/usb/host/ehci-brcm.c static int ehci_brcm_hub_control( · line 67

Quoted 6 lines
drivers/usb/host/ehci-brcm.c +2 -1
@@ -63,7 +63,8 @@ static int ehci_brcm_hub_control(
 	unsigned long flags;
 	int retval, irq_disabled = 0;
 
-	status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
+	if (wIndex && wIndex <= ports)
+		status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];

This isn't quite right because it won't work properly if the upper byte of wIndex is nonzero. You should do something like:

	u32 temp;

	temp = (wIndex & 0xff) - 1;
	if (temp < ports)
		status_reg = &ehci->regs->port_status[temp];

Alan Stern