usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): CGME20261118080357epcas1p1d496c3dcbc37d76fd71365cbab494352@epcas1p1.samsung.com
PATCH v2 1/1 usb: host: ehci-sched: Don't let a bogus siTD remaining length underflow
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.
---
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/[email protected]
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(+)
drivers/usb/host/ehci-sched.c +4 -0
@@ -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
Signature · 1 line
2.50.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
sitd_complete()computes the received length of a split isochronous packet asdesc->length-SITD_LENGTH(t), whereSITD_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 anactual_lengthof 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.cmatches 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:
Quoted 6 lines
[ ... ]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Gichoon Han <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1