Skip to content

Commit 5b22f67

Browse files
Shuah Khangregkh
authored andcommitted
usbip: vhci_hcd: check rhport before using in vhci_hub_control()
Validate !rhport < 0 before using it to access port_status array. Signed-off-by: Shuah Khan <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 83a62c5 commit 5b22f67

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/usb/usbip/vhci_hcd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
354354
usbip_dbg_vhci_rh(" ClearHubFeature\n");
355355
break;
356356
case ClearPortFeature:
357+
if (rhport < 0)
358+
goto error;
357359
switch (wValue) {
358360
case USB_PORT_FEAT_SUSPEND:
359361
if (hcd->speed == HCD_USB3) {
@@ -511,11 +513,16 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
511513
goto error;
512514
}
513515

516+
if (rhport < 0)
517+
goto error;
518+
514519
vhci_hcd->port_status[rhport] |= USB_PORT_STAT_SUSPEND;
515520
break;
516521
case USB_PORT_FEAT_POWER:
517522
usbip_dbg_vhci_rh(
518523
" SetPortFeature: USB_PORT_FEAT_POWER\n");
524+
if (rhport < 0)
525+
goto error;
519526
if (hcd->speed == HCD_USB3)
520527
vhci_hcd->port_status[rhport] |= USB_SS_PORT_STAT_POWER;
521528
else
@@ -524,6 +531,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
524531
case USB_PORT_FEAT_BH_PORT_RESET:
525532
usbip_dbg_vhci_rh(
526533
" SetPortFeature: USB_PORT_FEAT_BH_PORT_RESET\n");
534+
if (rhport < 0)
535+
goto error;
527536
/* Applicable only for USB3.0 hub */
528537
if (hcd->speed != HCD_USB3) {
529538
pr_err("USB_PORT_FEAT_BH_PORT_RESET req not "
@@ -534,6 +543,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
534543
case USB_PORT_FEAT_RESET:
535544
usbip_dbg_vhci_rh(
536545
" SetPortFeature: USB_PORT_FEAT_RESET\n");
546+
if (rhport < 0)
547+
goto error;
537548
/* if it's already enabled, disable */
538549
if (hcd->speed == HCD_USB3) {
539550
vhci_hcd->port_status[rhport] = 0;
@@ -554,6 +565,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
554565
default:
555566
usbip_dbg_vhci_rh(" SetPortFeature: default %d\n",
556567
wValue);
568+
if (rhport < 0)
569+
goto error;
557570
if (hcd->speed == HCD_USB3) {
558571
if ((vhci_hcd->port_status[rhport] &
559572
USB_SS_PORT_STAT_POWER) != 0) {

0 commit comments

Comments
 (0)