Skip to content

Commit f883b50

Browse files
matnymangregkh
authored andcommitted
xhci: Fix NULL pointer dereference when cleaning up streams for removed host
commit 4b89586 upstream. This off by one in stream_id indexing caused NULL pointer dereference and soft lockup on machines with USB attached SCSI devices connected to a hotpluggable xhci controller. The code that cleans up pending URBs for dead hosts tried to dereference a stream ring at the invalid stream_id 0. ep->stream_info->stream_rings[0] doesn't point to a ring. Start looping stream_id from 1 like in all the other places in the driver, and check that the ring exists before trying to kill URBs on it. Reported-by: rocko r <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 09364c7 commit f883b50

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,16 @@ static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci,
856856
(ep->ep_state & EP_GETTING_NO_STREAMS)) {
857857
int stream_id;
858858

859-
for (stream_id = 0; stream_id < ep->stream_info->num_streams;
859+
for (stream_id = 1; stream_id < ep->stream_info->num_streams;
860860
stream_id++) {
861+
ring = ep->stream_info->stream_rings[stream_id];
862+
if (!ring)
863+
continue;
864+
861865
xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
862866
"Killing URBs for slot ID %u, ep index %u, stream %u",
863-
slot_id, ep_index, stream_id + 1);
864-
xhci_kill_ring_urbs(xhci,
865-
ep->stream_info->stream_rings[stream_id]);
867+
slot_id, ep_index, stream_id);
868+
xhci_kill_ring_urbs(xhci, ring);
866869
}
867870
} else {
868871
ring = ep->ring;

0 commit comments

Comments
 (0)