public inbox for patches@lists.linux.dev
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Michal Pecio <michal.pecio@gmail.com>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 6.13 17/23] usb: xhci: Dont skip on Stopped - Length Invalid
Date: Thu,  3 Apr 2025 16:20:34 +0100	[thread overview]
Message-ID: <20250403151622.770891959@linuxfoundation.org> (raw)
In-Reply-To: <20250403151622.273788569@linuxfoundation.org>

6.13-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Michal Pecio <michal.pecio@gmail.com>

commit 58d0a3fab5f4fdc112c16a4c6d382f62097afd1c upstream.

Up until commit d56b0b2ab142 ("usb: xhci: ensure skipped isoc TDs are
returned when isoc ring is stopped") in v6.11, the driver didn't skip
missed isochronous TDs when handling Stoppend and Stopped - Length
Invalid events. Instead, it erroneously cleared the skip flag, which
would cause the ring to get stuck, as future events won't match the
missed TD which is never removed from the queue until it's cancelled.

This buggy logic seems to have been in place substantially unchanged
since the 3.x series over 10 years ago, which probably speaks first
and foremost about relative rarity of this case in normal usage, but
by the spec I see no reason why it shouldn't be possible.

After d56b0b2ab142, TDs are immediately skipped when handling those
Stopped events. This poses a potential problem in case of Stopped -
Length Invalid, which occurs either on completed TDs (likely already
given back) or Link and No-Op TRBs. Such event won't be recognized
as matching any TD (unless it's the rare Link TRB inside a TD) and
will result in skipping all pending TDs, giving them back possibly
before they are done, risking isoc data loss and maybe UAF by HW.

As a compromise, don't skip and don't clear the skip flag on this
kind of event. Then the next event will skip missed TDs. A downside
of not handling Stopped - Length Invalid on a Link inside a TD is
that if the TD is cancelled, its actual length will not be updated
to account for TRBs (silently) completed before the TD was stopped.

I had no luck producing this sequence of completion events so there
is no compelling demonstration of any resulting disaster. It may be
a very rare, obscure condition. The sole motivation for this patch
is that if such unlikely event does occur, I'd rather risk reporting
a cancelled partially done isoc frame as empty than gamble with UAF.

This will be fixed more properly by looking at Stopped event's TRB
pointer when making skipping decisions, but such rework is unlikely
to be backported to v6.12, which will stay around for a few years.

Fixes: d56b0b2ab142 ("usb: xhci: ensure skipped isoc TDs are returned when isoc ring is stopped")
Cc: stable@vger.kernel.org
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250306144954.3507700-4-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/host/xhci-ring.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2862,6 +2862,10 @@ static int handle_tx_event(struct xhci_h
 		if (!ep_seg) {
 
 			if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) {
+				/* this event is unlikely to match any TD, don't skip them all */
+				if (trb_comp_code == COMP_STOPPED_LENGTH_INVALID)
+					return 0;
+
 				skip_isoc_td(xhci, td, ep, status);
 				if (!list_empty(&ep_ring->td_list))
 					continue;



  parent reply	other threads:[~2025-04-03 15:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 15:20 [PATCH 6.13 00/23] 6.13.10-rc1 review Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 01/23] ALSA: usb-audio: Add quirk for Plantronics headsets to fix control names Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 02/23] HID: hid-plantronics: Add mic mute mapping and generalize quirks Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 03/23] atm: Fix NULL pointer dereference Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 04/23] nfsd: fix legacy client tracking initialization Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 05/23] cgroup/rstat: Fix forceidle time in cpu.stat Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 06/23] netfilter: socket: Lookup orig tuple for IPv6 SNAT Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 07/23] ALSA: hda/realtek: Support mute LED on HP Laptop 15s-du3xxx Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 08/23] ALSA: hda/realtek: Bass speaker fixup for ASUS UM5606KA Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 09/23] counter: stm32-lptimer-cnt: fix error handling when enabling Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 10/23] counter: microchip-tcb-capture: Fix undefined counter channel state on probe Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 11/23] tty: serial: 8250: Add some more device IDs Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 12/23] tty: serial: 8250: Add Brainboxes XC devices Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 13/23] tty: serial: fsl_lpuart: disable transmitter before changing RS485 related registers Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 14/23] net: usb: qmi_wwan: add Telit Cinterion FN990B composition Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 15/23] net: usb: qmi_wwan: add Telit Cinterion FE990B composition Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 16/23] net: usb: usbnet: restore usb%d name exception for local mac addresses Greg Kroah-Hartman
2025-04-03 15:20 ` Greg Kroah-Hartman [this message]
2025-04-03 15:20 ` [PATCH 6.13 18/23] usb: xhci: Apply the link chain quirk on NEC isoc endpoints Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 19/23] memstick: rtsx_usb_ms: Fix slab-use-after-free in rtsx_usb_ms_drv_remove Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 20/23] perf tools: Fix up some comments and code to properly use the event_source bus Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 21/23] serial: stm32: do not deassert RS485 RTS GPIO prematurely Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 22/23] serial: 8250_dma: terminate correct DMA in tx_dma_flush() Greg Kroah-Hartman
2025-04-03 15:20 ` [PATCH 6.13 23/23] bcachefs: bch2_ioctl_subvolume_destroy() fixes Greg Kroah-Hartman
2025-04-03 20:22 ` [PATCH 6.13 00/23] 6.13.10-rc1 review Pavel Machek
2025-04-03 20:52 ` Peter Schneider
2025-04-04 12:02 ` Mark Brown
2025-04-04 14:46 ` Shuah Khan
2025-04-04 16:47 ` Florian Fainelli
2025-04-04 19:30 ` Jon Hunter
2025-04-04 21:39 ` Justin Forbes
2025-04-05  2:11 ` Ron Economos
2025-04-05  6:20 ` Naresh Kamboju
2025-04-05 10:24   ` Greg Kroah-Hartman

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=20250403151622.770891959@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=michal.pecio@gmail.com \
    --cc=patches@lists.linux.dev \
    --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