USB: digi_acceleport: do sanity checking for the number of ports
authorOliver Neukum <oneukum@suse.com>
Thu, 31 Mar 2016 16:04:26 +0000 (12:04 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 30 Apr 2016 22:05:22 +0000 (00:05 +0200)
commit 5a07975ad0a36708c6b0a5b9fea1ff811d0b0c1f upstream.

The driver can be crashed with devices that expose crafted descriptors
with too few endpoints.

See: http://seclists.org/bugtraq/2016/Mar/61

Signed-off-by: Oliver Neukum <ONeukum@suse.com>
[johan: fix OOB endpoint check and add error messages ]
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/usb/serial/digi_acceleport.c

index e92cbef..e59bd95 100644 (file)
@@ -1489,12 +1489,30 @@ static int digi_startup_device(struct usb_serial *serial)
 static int digi_startup(struct usb_serial *serial)
 {
 
+       struct device *dev = &serial->interface->dev;
        int i;
        struct digi_port *priv;
        struct digi_serial *serial_priv;
 
        dbg("digi_startup: TOP");
 
+       /* check whether the device has the expected number of endpoints */
+       if (serial->num_port_pointers < serial->type->num_ports + 1) {
+               dev_err(dev, "OOB endpoints missing\n");
+               return -ENODEV;
+       }
+
+       for (i = 0; i < serial->type->num_ports + 1 ; i++) {
+               if (!serial->port[i]->read_urb) {
+                       dev_err(dev, "bulk-in endpoint missing\n");
+                       return -ENODEV;
+               }
+               if (!serial->port[i]->write_urb) {
+                       dev_err(dev, "bulk-out endpoint missing\n");
+                       return -ENODEV;
+               }
+       }
+
        /* allocate the private data structures for all ports */
        /* number of regular ports + 1 for the out-of-band port */
        for (i = 0; i < serial->type->num_ports + 1; i++) {