Skip to content

Commit 0ce5c0d

Browse files
Michal Peciogregkh
authored andcommitted
usb: xhci: Fix NULL pointer dereference on certain command aborts
commit 1e0a199 upstream. If a command is queued to the final usable TRB of a ring segment, the enqueue pointer is advanced to the subsequent link TRB and no further. If the command is later aborted, when the abort completion is handled the dequeue pointer is advanced to the first TRB of the next segment. If no further commands are queued, xhci_handle_stopped_cmd_ring() sees the ring pointers unequal and assumes that there is a pending command, so it calls xhci_mod_cmd_timer() which crashes if cur_cmd was NULL. Don't attempt timer setup if cur_cmd is NULL. The subsequent doorbell ring likely is unnecessary too, but it's harmless. Leave it alone. This is probably Bug 219532, but no confirmation has been received. The issue has been independently reproduced and confirmed fixed using a USB MCU programmed to NAK the Status stage of SET_ADDRESS forever. Everything continued working normally after several prevented crashes. Link: https://bugzilla.kernel.org/show_bug.cgi?id=219532 Fixes: c311e39 ("xhci: rework command timeout and cancellation,") CC: [email protected] Signed-off-by: Michal Pecio <[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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c843515 commit 0ce5c0d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci,
422422
if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) &&
423423
!(xhci->xhc_state & XHCI_STATE_DYING)) {
424424
xhci->current_cmd = cur_cmd;
425-
xhci_mod_cmd_timer(xhci);
425+
if (cur_cmd)
426+
xhci_mod_cmd_timer(xhci);
426427
xhci_ring_cmd_db(xhci);
427428
}
428429
}

0 commit comments

Comments
 (0)