usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup()
Subsystems (2)
PATCH 1/1 usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup()
If xhci_mem_init() fails, it calls into xhci_mem_cleanup() to mop up the damage. If it fails early enough, before xhci->interrupters is allocated but after xhci->max_interrupters has been set, which happens in most (all?) cases, things get uglier, as xhci_mem_cleanup() unconditionally derefences xhci->interrupters. With prejudice.
Gate the interrupt freeing loop with a check on xhci->interrupters being non-NULL.
Found while debugging a DMA allocation issue that led the XHCI driver on this exact path.
--- drivers/usb/host/xhci-mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-mem.c +1 -1
@@ -1872,7 +1872,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)cancel_delayed_work_sync (&xhci->cmd_timer); -for (i =0 ; i < xhci->max_interrupters; i++) { +for (i =0 ; xhci->interrupters && i < xhci->max_interrupters; i++) {if (xhci->interrupters[i]) {xhci_remove_interrupter (xhci, xhci->interrupters[i]);xhci_free_interrupter (xhci, xhci->interrupters[i]);
Signature · 1 line
2.39.2
Quoted 12 lines · Marc Zyngier
If
xhci_mem_init()fails, it calls intoxhci_mem_cleanup()to mop up the damage. If it fails early enough, beforexhci->interruptersis allocated but afterxhci->max_interruptershas been set, which happens in most (all?) cases, things get uglier, asxhci_mem_cleanup()unconditionally derefencesxhci->interrupters. With prejudice.Gate the interrupt freeing loop with a check on
xhci->interruptersbeing non-NULL.Found while debugging a DMA allocation issue that led the XHCI driver on this exact path.
Quoted 6 lines
Fixes c99b38c41234 ("xhci: add support to allocate several interrupters")Cc Mathias Nyman <[email protected]>Cc Wesley Cheng <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Marc Zyngier <[email protected]>---
Thanks, Adding to queue
-Mathias