Skip to content

Commit

Permalink
usb: misc: usbtest: Fix overflow in usbtest_do_ioctl()
Browse files Browse the repository at this point in the history
There used to be a test against "if (param->sglen > MAX_SGLEN)" but it
was removed during a refactor.  It leads to an integer overflow and a
stack overflow in test_queue() if we try to create a too large urbs[]
array on the stack.

There is a second integer overflow in test_queue() as well if
"param->iterations" is too high.  I don't immediately see that it's
harmful but I've added a check to prevent it and silence the static
checker warning.

Fixes: 18fc4eb ("usb: misc: usbtest: Remove timeval usage")
Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Dan Carpenter authored and Felipe Balbi committed Oct 11, 2017
1 parent 29c7f3e commit cb84f56
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/usb/misc/usbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,9 @@ test_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param,
int status = 0;
struct urb *urbs[param->sglen];

if (!param->sglen || param->iterations > UINT_MAX / param->sglen)
return -EINVAL;

memset(&context, 0, sizeof(context));
context.count = param->iterations * param->sglen;
context.dev = dev;
Expand Down Expand Up @@ -2087,6 +2090,8 @@ usbtest_do_ioctl(struct usb_interface *intf, struct usbtest_param_32 *param)

if (param->iterations <= 0)
return -EINVAL;
if (param->sglen > MAX_SGLEN)
return -EINVAL;
/*
* Just a bunch of test cases that every HCD is expected to handle.
*
Expand Down

0 comments on commit cb84f56

Please sign in to comment.