Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Sashiko <sashiko-bot@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 09/10] xhci: fix use-after-free for errors mid TD on empty halted rings
Date: Fri, 27 Nov 2026 14:17:54 +0200	[thread overview]
Message-ID: <20261127121755.281420-10-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20261127121755.281420-1-mathias.nyman@linux.intel.com>

If a TD with an error mid TD is followed by an event that doesn't point
to that TD, handle_tx_event() gives back the TD with xhci_dequeue_td().
If this was the last TD of the URB, the URB is given back and the TD,
part of the freed urb_priv, is freed with it.

If the TD list is then empty and the endpoint is halted, handle_tx_event()
jumps to check_endpoint_halted and passes the now dangling td pointer to
xhci_handle_halted_endpoint(), which adds it to the endpoint's cancelled
TD list. This causes a use-after-free and corrupts the cancelled TD list.

Set td to NULL after giving it back. xhci_handle_halted_endpoint()
handles a NULL td, and td is reassigned if there are more TDs on the
ring.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-2b321b4d-f99f-4acd-9590-8dd98a82ebb5
Fixes: f42a36bae064 ("usb: xhci: Fix handling errors mid TD followed by other errors")
Cc: stable@vger.kernel.org # 6.12+
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index fca23daf6add..7ccd89a4b995 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2891,6 +2891,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 	if (td && td->error_mid_td && !trb_in_td(td, ep_trb_dma)) {
 		xhci_dbg(xhci, "Missing TD completion event after mid TD error\n");
 		xhci_dequeue_td(xhci, td, ep_ring, td->status);
+		td = NULL;
 	}
 
 	if (list_empty(&ep_ring->td_list)) {
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 12:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261127121755.281420-1-mathias.nyman@linux.intel.com>
2026-11-27 12:17 ` [PATCH 01/10] usb: xhci: Fix ep0 maxpacket update on enabled slots Mathias Nyman
2026-11-27 12:17 ` [PATCH 03/10] xhci: Give back URB under lock in xhci_urb_dequeue() Mathias Nyman
2026-11-27 12:17 ` [PATCH 05/10] xhci: sideband: avoid use-after-free of stale virt device pointer Mathias Nyman
2026-11-27 12:17 ` [PATCH 06/10] xhci: sideband: check virt device under xhci lock when stopping endpoints Mathias Nyman
2026-11-27 12:17 ` [PATCH 08/10] usb: xhci: Demote isoch buffer overrun message to debug level Mathias Nyman
2026-11-27 12:17 ` Mathias Nyman [this message]
2026-11-27 12:17 ` [PATCH 10/10] xhci: fix NULL pointer dereference of rhub_port in xhci_urb_enqueue() Mathias Nyman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127121755.281420-10-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox