* [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow [not found] <CGME20261116052855epcas1p403c518b90d70d98752ad0ca2d9ac05e9@epcas1p4.samsung.com> @ 2026-11-16 5:28 ` Gichoon Han 2026-11-16 18:09 ` Alan Stern 0 siblings, 1 reply; 3+ messages in thread From: Gichoon Han @ 2026-11-16 5:28 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 an ARM32 system (vendor 5.4 kernel; this code is unchanged in mainline) with a full-speed UAC1 microphone behind a high-speed hub. snd-usb-audio trusted the value and 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 register state at the fault is only consistent with a wrapped actual_length coming from this path. snd-usb-audio now rejects such packets (commit eed0e9583a29 ("ALSA: usb-audio: Drop capture packets with bogus actual_length")), but as noted when that was applied, the bug really lies in the host controller driver, 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> --- Compile-tested only (ARM32, W=1) on linux-next. I could not capture the siTD contents on the affected hardware; the wrapped value is inferred from the oops above. 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.25.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow 2026-11-16 5:28 ` [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow Gichoon Han @ 2026-11-16 18:09 ` Alan Stern 2026-11-17 0:25 ` gichoon.han 0 siblings, 1 reply; 3+ messages in thread From: Alan Stern @ 2026-11-16 18:09 UTC (permalink / raw) To: Gichoon Han Cc: Greg Kroah-Hartman, Takashi Iwai, linux-usb, linux-kernel, stable On Mon, Nov 16, 2026 at 02:28:51PM +0900, Gichoon Han wrote: > 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 an ARM32 system (vendor 5.4 kernel; this code is The type of CPU doesn't matter as much as the type of EHCI controller, since you're talking about a controller hardware bug. > unchanged in mainline) with a full-speed UAC1 microphone behind a > high-speed hub. snd-usb-audio trusted the value and 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 register state at the fault is only consistent with a wrapped > actual_length coming from this path. > > snd-usb-audio now rejects such packets (commit eed0e9583a29 ("ALSA: > usb-audio: Drop capture packets with bogus actual_length")), but as > noted when that was applied, the bug really lies in the host > controller driver, Actually the bug lies in the host controller hardware. Not the driver. > 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> > --- > Compile-tested only (ARM32, W=1) on linux-next. I could not capture > the siTD contents on the affected hardware; the wrapped value is > inferred from the oops above. So you have no way of knowing whether this patch really fixes the problem? Alan Stern > 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.25.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow 2026-11-16 18:09 ` Alan Stern @ 2026-11-17 0:25 ` gichoon.han 0 siblings, 0 replies; 3+ messages in thread From: gichoon.han @ 2026-11-17 0:25 UTC (permalink / raw) To: 'Alan Stern' Cc: 'Greg Kroah-Hartman', 'Takashi Iwai', linux-usb, linux-kernel, stable On Mon, Nov 16, 2026 at ..., Alan Stern wrote: > The type of CPU doesn't matter as much as the type of EHCI controller, > since you're talking about a controller hardware bug. Fair point. It is the on-chip EHCI controller of a Novatek TV SoC (DT compatible "nvt,NT72668-ehci"), driven by ehci-hcd through a vendor platform glue that is not in mainline. > Actually the bug lies in the host controller hardware. Not the driver. Agreed, I'll fix the wording. > So you have no way of knowing whether this patch really fixes the > problem? Not directly, no. I don't have the siTD contents from the failing device, so the claim that the controller wrote a remaining count larger than the programmed length is an inference: the faulting memcpy() still had about 122 KB left to copy out of a full-speed packet, which can be at most 1023 bytes, and this subtraction is the only place in the path that can produce a value that large. What the patch does guarantee is narrower: whatever the controller writes into the siTD, ehci-hcd never hands a class driver an actual_length larger than the requested length. The crash itself is already prevented on the ALSA side. If you think that is not enough to justify the change without hardware confirmation, I'm fine with dropping it. Otherwise I'll send a v2 with the controller identified and the wording fixed. Thanks, Gichoon -----Original Message----- From: Alan Stern <stern@rowland.harvard.edu> Sent: Tuesday, November 17, 2026 3:09 AM To: Gichoon Han <gichoon.han@samsung.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Takashi Iwai <tiwai@suse.de>; linux-usb@vger.kernel.org; linux-kernel@vger.kernel.org; stable@vger.kernel.org Subject: Re: [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow On Mon, Nov 16, 2026 at 02:28:51PM +0900, Gichoon Han wrote: > 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 an ARM32 system (vendor 5.4 kernel; this code is The type of CPU doesn't matter as much as the type of EHCI controller, since you're talking about a controller hardware bug. > unchanged in mainline) with a full-speed UAC1 microphone behind a > high-speed hub. snd-usb-audio trusted the value and 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 register state at the fault is only consistent with a wrapped > actual_length coming from this path. > > snd-usb-audio now rejects such packets (commit eed0e9583a29 ("ALSA: > usb-audio: Drop capture packets with bogus actual_length")), but as > noted when that was applied, the bug really lies in the host > controller driver, Actually the bug lies in the host controller hardware. Not the driver. > 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> > --- > Compile-tested only (ARM32, W=1) on linux-next. I could not capture > the siTD contents on the affected hardware; the wrapped value is > inferred from the oops above. So you have no way of knowing whether this patch really fixes the problem? Alan Stern > 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.25.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 0:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20261116052855epcas1p403c518b90d70d98752ad0ca2d9ac05e9@epcas1p4.samsung.com>
2026-11-16 5:28 ` [PATCH] usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow Gichoon Han
2026-11-16 18:09 ` Alan Stern
2026-11-17 0:25 ` gichoon.han
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®