usbnet: sanity check for maxpacket
authorOliver Neukum <oneukum@suse.com>
Thu, 21 Oct 2021 12:29:44 +0000 (14:29 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 21 Oct 2021 13:44:53 +0000 (06:44 -0700)
maxpacket of 0 makes no sense and oopses as we need to divide
by it. Give up.

V2: fixed typo in log and stylistic issues

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Reported-by: syzbot+76bb1d34ffa0adc03baa@syzkaller.appspotmail.com
Reviewed-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20211021122944.21816-1-oneukum@suse.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/usb/usbnet.c

index 840c1c2..80432ee 100644 (file)
@@ -1788,6 +1788,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
        if (!dev->rx_urb_size)
                dev->rx_urb_size = dev->hard_mtu;
        dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
+       if (dev->maxpacket == 0) {
+               /* that is a broken device */
+               goto out4;
+       }
 
        /* let userspace know we have a random address */
        if (ether_addr_equal(net->dev_addr, node_id))