usb: gadget: ether: Fix race between gether_disconnect and rx_submit
authorKiruthika Varadarajan <Kiruthika.Varadarajan@harman.com>
Tue, 18 Jun 2019 08:39:06 +0000 (08:39 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 21 Jul 2019 07:04:34 +0000 (09:04 +0200)
commit d29fcf7078bc8be2b6366cbd4418265b53c94fac upstream.

On spin lock release in rx_submit, gether_disconnect get a chance to
run, it makes port_usb NULL, rx_submit access NULL port USB, hence null
pointer crash.

Fixed by releasing the lock in rx_submit after port_usb is used.

Fixes: 2b3d942c4878 ("usb ethernet gadget: split out network core")
Cc: <stable@vger.kernel.org>
Signed-off-by: Kiruthika Varadarajan <Kiruthika.Varadarajan@harman.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/u_ether.c

index 3a0e4f5d7b839af44b49a8c1a18d1f53eab448ac..81d84e0c3c6cd6188b35b285bbae06693cf76ace 100644 (file)
@@ -190,11 +190,12 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
                out = dev->port_usb->out_ep;
        else
                out = NULL;
-       spin_unlock_irqrestore(&dev->lock, flags);
 
        if (!out)
+       {
+               spin_unlock_irqrestore(&dev->lock, flags);
                return -ENOTCONN;
-
+       }
 
        /* Padding up to RX_EXTRA handles minor disagreements with host.
         * Normally we use the USB "terminate on short read" convention;
@@ -218,6 +219,7 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
 
        if (dev->port_usb->is_fixed)
                size = max_t(size_t, size, dev->port_usb->fixed_out_len);
+       spin_unlock_irqrestore(&dev->lock, flags);
 
        skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags);
        if (skb == NULL) {