Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow
       [not found] <CGME20261118080357epcas1p1d496c3dcbc37d76fd71365cbab494352@epcas1p1.samsung.com>
@ 2026-11-18  8:03 ` Gichoon Han
  2026-11-18  8:07   ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Gichoon Han @ 2026-11-18  8:03 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman
  Cc: Takashi Iwai, linux-usb, linux-kernel, Gichoon Han, stable

sitd_complete() computes the received length of a split isochronous
packet as desc->length - SITD_LENGTH(t), where SITD_LENGTH() is the
"Total Bytes to Transfer" count the controller leaves in the siTD.
Nothing checks that this remaining count is not larger than what was
programmed.  If the controller reports a larger value, the unsigned
subtraction wraps and the class driver gets an actual_length of
nearly 4 GiB for a packet that can hold at most 1023 bytes.

This was seen on a Novatek TV SoC with its on-chip EHCI controller
(DT compatible "nvt,NT72668-ehci", handled by ehci-hcd through a
vendor platform glue that is not in mainline), running a vendor 5.4
kernel whose ehci-sched.c matches mainline in this area.  A
full-speed UAC1 microphone behind a high-speed hub was streaming when
snd-usb-audio read far past the URB transfer buffer:

  Unable to handle kernel paging request at virtual address e8756000
  Internal error: Oops: 7 [#1] PREEMPT SMP ARM

The faulting memcpy() still had about 122 KB left to copy from a
full-speed packet, which can hold at most 1023 bytes; this
subtraction is the only place on that path that can produce such a
value.

snd-usb-audio now rejects such packets (commit eed0e9583a29 ("ALSA:
usb-audio: Drop capture packets with bogus actual_length")), but the
root cause is the controller hardware reporting an impossible
remaining count, and other class drivers trust actual_length too.

Treat a remaining count larger than the programmed length as a
protocol error instead of reporting a wrapped length.

Link: https://lore.kernel.org/r/87se19ufoi.wl-tiwai@suse.de
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Gichoon Han <gichoon.han@samsung.com>
---
v2:
 - Identify the EHCI controller rather than the CPU (Alan)
 - Attribute the bug to the controller hardware, not the driver (Alan)
 - Explain why a wrapped length is the only explanation for the fault

v1: https://lore.kernel.org/r/20261116052851.2272125-1-gichoon.han@samsung.com

Compile-tested only (ARM32, W=1) on linux-next.  The oops comes from a
field report that included only the kernel log, so the siTD contents
were never captured.  I'm trying to reproduce it with an instrumented
build and will report the raw siTD values if I catch it.

 drivers/usb/host/ehci-sched.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 57d07d1c2dfa..12a10248a4b6 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -2241,6 +2241,10 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
 	} else if (unlikely(t & SITD_STS_ACTIVE)) {
 		/* URB was too late */
 		urb->error_count++;
+	} else if (unlikely(SITD_LENGTH(t) > desc->length)) {
+		/* controller claims more left than was programmed */
+		urb->error_count++;
+		desc->status = -EPROTO;
 	} else {
 		desc->status = 0;
 		desc->actual_length = desc->length - SITD_LENGTH(t);

base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
-- 
2.50.1


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

* Re: [PATCH v2] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow
  2026-11-18  8:03 ` [PATCH v2] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow Gichoon Han
@ 2026-11-18  8:07   ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18  8:07 UTC (permalink / raw)
  To: Gichoon Han; +Cc: linux-usb

> sitd_complete() computes the received length of a split isochronous
> packet as desc->length - SITD_LENGTH(t), where SITD_LENGTH() is the
> "Total Bytes to Transfer" count the controller leaves in the siTD.
> Nothing checks that this remaining count is not larger than what was
> programmed.  If the controller reports a larger value, the unsigned
> subtraction wraps and the class driver gets an actual_length of
> nearly 4 GiB for a packet that can hold at most 1023 bytes.
> 
> This was seen on a Novatek TV SoC with its on-chip EHCI controller
> (DT compatible "nvt,NT72668-ehci", handled by ehci-hcd through a
> vendor platform glue that is not in mainline), running a vendor 5.4
> kernel whose ehci-sched.c matches mainline in this area.  A
> full-speed UAC1 microphone behind a high-speed hub was streaming when
> snd-usb-audio read far past the URB transfer buffer:
> 
> [ ... ]
> 
> Link: https://lore.kernel.org/r/87se19ufoi.wl-tiwai@suse.de
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gichoon Han <gichoon.han@samsung.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118080348.172772-1-gichoon.han@samsung.com?part=1


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

end of thread, other threads:[~2026-11-18  8:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20261118080357epcas1p1d496c3dcbc37d76fd71365cbab494352@epcas1p1.samsung.com>
2026-11-18  8:03 ` [PATCH v2] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow Gichoon Han
2026-11-18  8:07   ` sashiko-bot

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