aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc/usbtest.c
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2017-09-30 04:15:29 -0400
committerFelipe Balbi <felipe.balbi@linux.intel.com>2017-10-11 06:14:09 -0400
commitcb84f56861eb333af0a5bab475d741b13067c05c (patch)
treed74aad2ca497cf19faeca8e6f9a6e3071ac46c3b /drivers/usb/misc/usbtest.c
parent29c7f3e68eec4ae94d85ad7b5dfdafdb8089f513 (diff)
usb: misc: usbtest: Fix overflow in usbtest_do_ioctl()
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: 18fc4ebdc705 ("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>
Diffstat (limited to 'drivers/usb/misc/usbtest.c')
-rw-r--r--drivers/usb/misc/usbtest.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index eee82ca55b7b..113e38bfe0ef 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -1964,6 +1964,9 @@ test_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param,
1964 int status = 0; 1964 int status = 0;
1965 struct urb *urbs[param->sglen]; 1965 struct urb *urbs[param->sglen];
1966 1966
1967 if (!param->sglen || param->iterations > UINT_MAX / param->sglen)
1968 return -EINVAL;
1969
1967 memset(&context, 0, sizeof(context)); 1970 memset(&context, 0, sizeof(context));
1968 context.count = param->iterations * param->sglen; 1971 context.count = param->iterations * param->sglen;
1969 context.dev = dev; 1972 context.dev = dev;
@@ -2087,6 +2090,8 @@ usbtest_do_ioctl(struct usb_interface *intf, struct usbtest_param_32 *param)
2087 2090
2088 if (param->iterations <= 0) 2091 if (param->iterations <= 0)
2089 return -EINVAL; 2092 return -EINVAL;
2093 if (param->sglen > MAX_SGLEN)
2094 return -EINVAL;
2090 /* 2095 /*
2091 * Just a bunch of test cases that every HCD is expected to handle. 2096 * Just a bunch of test cases that every HCD is expected to handle.
2092 * 2097 *