diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2017-09-22 16:43:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-09-25 04:57:13 -0400 |
commit | 57999d1107c1e60c2ca7088f2ac0f819e2f554b3 (patch) | |
tree | 6081b8b694eeae7c08ea2cc082c9966517cdb838 | |
parent | 1fbbb78f25d1291274f320462bf6908906f538db (diff) |
USB: devio: Prevent integer overflow in proc_do_submiturb()
There used to be an integer overflow check in proc_do_submiturb() but
we removed it. It turns out that it's still required. The
uurb->buffer_length variable is a signed integer and it's controlled by
the user. It can lead to an integer overflow when we do:
num_sgs = DIV_ROUND_UP(uurb->buffer_length, USB_SG_SIZE);
If we strip away the macro then that line looks like this:
num_sgs = (uurb->buffer_length + USB_SG_SIZE - 1) / USB_SG_SIZE;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It's the first addition which can overflow.
Fixes: 1129d270cbfb ("USB: Increase usbfs transfer limit")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/core/devio.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 318bb3b96687..e9326f31db8d 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -140,6 +140,9 @@ module_param(usbfs_memory_mb, uint, 0644); | |||
140 | MODULE_PARM_DESC(usbfs_memory_mb, | 140 | MODULE_PARM_DESC(usbfs_memory_mb, |
141 | "maximum MB allowed for usbfs buffers (0 = no limit)"); | 141 | "maximum MB allowed for usbfs buffers (0 = no limit)"); |
142 | 142 | ||
143 | /* Hard limit, necessary to avoid arithmetic overflow */ | ||
144 | #define USBFS_XFER_MAX (UINT_MAX / 2 - 1000000) | ||
145 | |||
143 | static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ | 146 | static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ |
144 | 147 | ||
145 | /* Check whether it's okay to allocate more memory for a transfer */ | 148 | /* Check whether it's okay to allocate more memory for a transfer */ |
@@ -1460,6 +1463,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb | |||
1460 | USBDEVFS_URB_ZERO_PACKET | | 1463 | USBDEVFS_URB_ZERO_PACKET | |
1461 | USBDEVFS_URB_NO_INTERRUPT)) | 1464 | USBDEVFS_URB_NO_INTERRUPT)) |
1462 | return -EINVAL; | 1465 | return -EINVAL; |
1466 | if ((unsigned int)uurb->buffer_length >= USBFS_XFER_MAX) | ||
1467 | return -EINVAL; | ||
1463 | if (uurb->buffer_length > 0 && !uurb->buffer) | 1468 | if (uurb->buffer_length > 0 && !uurb->buffer) |
1464 | return -EINVAL; | 1469 | return -EINVAL; |
1465 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && | 1470 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && |