Re: [PATCH 1/1] usb: xhci: Fix NULL pointer dereference on certain command aborts

From: Michal Pecio
Date: Wed Dec 04 2024 - 14:33:52 EST


I confirmed that the bug is real and behaves exactly as expected, using
a USB microcontroller programmed to NAK the status stage of SET_ADDRESS
requests forever and to reconnect if the host gives up enumerating it.

Command timeout was reduced to 500ms to sooner reach the segment's end
and some relevant debug info was added, hopefully self-explanatory:

[ +0,378926] usb 10-1: new full-speed USB device number 109 using xhci_hcd
[ +0,501006] xhci_hcd 0000:03:00.0: cur_cmd 0000000000000000 enq ffff88814671bff0 deq ffff88814671b000
[ +0,000001] xhci_hcd 0000:03:00.0: Timeout while waiting for setup device command
[ +0,000005] xhci_hcd 0000:03:00.0: !!! avoiding dereferencing a NULL pointer !!!
[ +0,712001] xhci_hcd 0000:03:00.0: cur_cmd 0000000000000000 enq ffff88814671b010 deq ffff88814671b010
[ +0,000001] xhci_hcd 0000:03:00.0: Timeout while waiting for setup device command
[ +0,207981] usb 10-1: device not accepting address 109, error -62

The driver and host controller continue working normally after one hour
of testing and several avoided crashes.

The only thing I haven't tried is actually crashing the kernel, but
considering what's inside xhci_mod_cmd_timer() I think it's obvious
that this is exactly what would happen next without this patch.

Regards,
Michal