public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup()
@ 2024-07-31 20:59 Marc Zyngier
  2024-08-05  8:23 ` Mathias Nyman
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Zyngier @ 2024-07-31 20:59 UTC (permalink / raw)
  To: linux-usb, linux-kernel; +Cc: Mathias Nyman, Wesley Cheng, Greg Kroah-Hartman

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.

Fixes: c99b38c41234 ("xhci: add support to allocate several interrupters")
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Wesley Cheng <quic_wcheng@quicinc.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/usb/host/xhci-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d7654f475daf..937ce5fd5809 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -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]);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup()
  2024-07-31 20:59 [PATCH] usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup() Marc Zyngier
@ 2024-08-05  8:23 ` Mathias Nyman
  0 siblings, 0 replies; 2+ messages in thread
From: Mathias Nyman @ 2024-08-05  8:23 UTC (permalink / raw)
  To: Marc Zyngier, linux-usb, linux-kernel; +Cc: Wesley Cheng, Greg Kroah-Hartman

On 31.7.2024 23.59, Marc Zyngier wrote:
> 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.
> 
> Fixes: c99b38c41234 ("xhci: add support to allocate several interrupters")
> Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> Cc: Wesley Cheng <quic_wcheng@quicinc.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---

Thanks, Adding to queue

-Mathias


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-05  8:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-31 20:59 [PATCH] usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup() Marc Zyngier
2024-08-05  8:23 ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox