Skip to content

Commit

Permalink
usbip: fix stub_rx: get_pipe() to validate endpoint number
Browse files Browse the repository at this point in the history
get_pipe() routine doesn't validate the input endpoint number
and uses to reference ep_in and ep_out arrays. Invalid endpoint
number can trigger BUG(). Range check the epnum and returning
error instead of calling BUG().

Change caller stub_recv_cmd_submit() to handle the get_pipe()
error return.

Reported-by: Secunia Research <vuln@secunia.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Shuah Khan authored and Greg Kroah-Hartman committed Dec 8, 2017
1 parent 82a2b82 commit 635f545
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions drivers/usb/usbip/stub_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir)
struct usb_host_endpoint *ep;
struct usb_endpoint_descriptor *epd = NULL;

if (epnum < 0 || epnum > 15)
goto err_ret;

if (dir == USBIP_DIR_IN)
ep = udev->ep_in[epnum & 0x7f];
else
ep = udev->ep_out[epnum & 0x7f];
if (!ep) {
dev_err(&sdev->udev->dev, "no such endpoint?, %d\n",
epnum);
BUG();
}
if (!ep)
goto err_ret;

epd = &ep->desc;
if (usb_endpoint_xfer_control(epd)) {
Expand Down Expand Up @@ -367,9 +367,10 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir)
return usb_rcvisocpipe(udev, epnum);
}

err_ret:
/* NOT REACHED */
dev_err(&sdev->udev->dev, "get pipe, epnum %d\n", epnum);
return 0;
dev_err(&sdev->udev->dev, "get pipe() invalid epnum %d\n", epnum);
return -1;
}

static void masking_bogus_flags(struct urb *urb)
Expand Down Expand Up @@ -435,6 +436,9 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
struct usb_device *udev = sdev->udev;
int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction);

if (pipe == -1)
return;

priv = stub_priv_alloc(sdev, pdu);
if (!priv)
return;
Expand Down

0 comments on commit 635f545

Please sign in to comment.