All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: Valentina Manea <valentina.manea.m@gmail.com>,
	Shuah Khan <shuah@kernel.org>
Cc: linux-usb@vger.kernel.org
Subject: usbip: vhci_hcd: Check rhport everywhere in vhci_hub_control()
Date: Thu, 11 Oct 2018 06:30:57 +0100	[thread overview]
Message-ID: <20181011053057.GA3375@decadent.org.uk> (raw)

Commit 5b22f676118f "usbip: vhci_hcd: check rhport before using in
vhci_hub_control()" added some validation of rhport, but left
several problems:

- If VHCI_HC_PORTS < 256, we can get rhport >= VHCI_HC_PORTS which
  is also out of range.  To keep things simple, set rhport to -1 if
  this would happen.
- For GetPortStatus, we range-check wIndex (and by implication
  rhport) and report an error, but *don't* skip the following code.
  Add a goto to the error path.
- At the end of the function, there's one last port_status lookup
  that's not protected by any range check.

Fixes: 5b22f676118f ("usbip: vhci_hcd: check rhport before using in ...")
Cc: stable@vger.kernel.org
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 drivers/usb/usbip/vhci_hcd.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index d11f3f8dad40..e259d3812641 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -334,9 +334,12 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 	usbip_dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue,
 			  wIndex);
 
-	if (wIndex > VHCI_HC_PORTS)
+	if (wIndex > VHCI_HC_PORTS) {
 		pr_err("invalid port number %d\n", wIndex);
-	rhport = wIndex - 1;
+		rhport = -1;
+	} else {
+		rhport = wIndex - 1;
+	}
 
 	vhci_hcd = hcd_to_vhci_hcd(hcd);
 	vhci = vhci_hcd->vhci;
@@ -414,10 +417,10 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 		*(__le32 *) buf = cpu_to_le32(0);
 		break;
 	case GetPortStatus:
-		usbip_dbg_vhci_rh(" GetPortStatus port %x\n", wIndex);
-		if (wIndex < 1) {
-			pr_err("invalid port number %d\n", wIndex);
-			retval = -EPIPE;
+		usbip_dbg_vhci_rh(" GetPortStatus port %x\n", rhport);
+		if (rhport < 0) {
+			pr_err("invalid port number %d\n", rhport);
+			goto error;
 		}
 
 		/* we do not care about resume. */
@@ -618,7 +621,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 
 	spin_unlock_irqrestore(&vhci->lock, flags);
 
-	if ((vhci_hcd->port_status[rhport] & PORT_C_MASK) != 0)
+	if (rhport >= 0 && (vhci_hcd->port_status[rhport] & PORT_C_MASK) != 0)
 		usb_hcd_poll_rh_status(hcd);
 
 	return retval;

             reply	other threads:[~2018-10-11  5:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11  5:30 Ben Hutchings [this message]
2018-10-11 14:37 usbip: vhci_hcd: Check rhport everywhere in vhci_hub_control() Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181011053057.GA3375@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=valentina.manea.m@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.