Skip to content

Commit a2bc47c

Browse files
matnymangregkh
authored andcommitted
xhci: Fix null pointer dereference when host dies
Make sure xhci_free_dev() and xhci_kill_endpoint_urbs() do not race and cause null pointer dereference when host suddenly dies. Usb core may call xhci_free_dev() which frees the xhci->devs[slot_id] virt device at the same time that xhci_kill_endpoint_urbs() tries to loop through all the device's endpoints, checking if there are any cancelled urbs left to give back. hold the xhci spinlock while freeing the virt device Cc: [email protected] Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e8fb5bc commit a2bc47c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/usb/host/xhci.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,7 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
39743974
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
39753975
struct xhci_virt_device *virt_dev;
39763976
struct xhci_slot_ctx *slot_ctx;
3977+
unsigned long flags;
39773978
int i, ret;
39783979

39793980
/*
@@ -4000,7 +4001,11 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
40004001
virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING;
40014002
virt_dev->udev = NULL;
40024003
xhci_disable_slot(xhci, udev->slot_id);
4004+
4005+
spin_lock_irqsave(&xhci->lock, flags);
40034006
xhci_free_virt_device(xhci, udev->slot_id);
4007+
spin_unlock_irqrestore(&xhci->lock, flags);
4008+
40044009
}
40054010

40064011
int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)

0 commit comments

Comments
 (0)