]> www.infradead.org Git - users/willy/xarray.git/commitdiff
xhci: guard accesses to ep_state in xhci_endpoint_reset()
authorJonathan Bell <jonathan@raspberrypi.com>
Fri, 8 Oct 2021 09:25:43 +0000 (12:25 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Oct 2021 05:42:18 +0000 (07:42 +0200)
See https://github.com/raspberrypi/linux/issues/3981

Two read-modify-write cycles on ep->ep_state are not guarded by
xhci->lock. Fix these.

Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset")
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20211008092547.3996295-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci.c

index 93c38b557afd379eb16020d111e02c426f8c8d0e..541fe4dcc43a22d51704c145f9291dd91545b973 100644 (file)
@@ -3214,10 +3214,13 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
                return;
 
        /* Bail out if toggle is already being cleared by a endpoint reset */
+       spin_lock_irqsave(&xhci->lock, flags);
        if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) {
                ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE;
+               spin_unlock_irqrestore(&xhci->lock, flags);
                return;
        }
+       spin_unlock_irqrestore(&xhci->lock, flags);
        /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */
        if (usb_endpoint_xfer_control(&host_ep->desc) ||
            usb_endpoint_xfer_isoc(&host_ep->desc))
@@ -3303,8 +3306,10 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
        xhci_free_command(xhci, cfg_cmd);
 cleanup:
        xhci_free_command(xhci, stop_cmd);
+       spin_lock_irqsave(&xhci->lock, flags);
        if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE)
                ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
+       spin_unlock_irqrestore(&xhci->lock, flags);
 }
 
 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,