aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/devio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/core/devio.c')
-rw-r--r--drivers/usb/core/devio.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 318bb3b96687..4664e543cf2f 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -140,6 +140,9 @@ module_param(usbfs_memory_mb, uint, 0644);
140MODULE_PARM_DESC(usbfs_memory_mb, 140MODULE_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
143static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ 146static 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 &&
@@ -1571,7 +1576,11 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
1571 totlen += isopkt[u].length; 1576 totlen += isopkt[u].length;
1572 } 1577 }
1573 u *= sizeof(struct usb_iso_packet_descriptor); 1578 u *= sizeof(struct usb_iso_packet_descriptor);
1574 uurb->buffer_length = totlen; 1579 if (totlen <= uurb->buffer_length)
1580 uurb->buffer_length = totlen;
1581 else
1582 WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
1583 totlen, uurb->buffer_length);
1575 break; 1584 break;
1576 1585
1577 default: 1586 default: