Thread View: muc.lists.freebsd.bugs
4 messages
4 total messages
Started by bugzilla-noreply
Mon, 23 Nov 2026 01:26
[Bug 301029] usb(4)/xhci(4): UAF race between usbd_transfer_unsetup_sub() and xhci_interrupt_poll() on struct usb_page_cache
Author: bugzilla-noreply
Date: Mon, 23 Nov 2026 01:26
Date: Mon, 23 Nov 2026 01:26
123 lines
7414 bytes
7414 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301029
Bug ID: 301029
Summary: usb(4)/xhci(4): UAF race between
usbd_transfer_unsetup_sub() and xhci_interrupt_poll()
on struct usb_page_cache
Product: Base System
Version: 15.1-RELEASE
Hardware: amd64
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: viktor.dolgopiatov@icloud.com
Environment:
FreeBSD 15.1-RELEASE-p3, releng/15.1-n283611-88e7371d9dc2 GENERIC amd64.
Intel N100 (Alder Lake-N), 2x Intel xHCI controllers (one in active use,
one unused/empty on this board). Panic reproduced once in the field on
an embedded appliance; race window independently confirmed live via
DTrace on a test unit (see below). Stock kernel, no local patches.
Summary:
A single, field-observed kernel panic (page fault in usb_pc_cpu_invalidate(),
called from xhci_activate_transfer()) pointed to a stale/UAF
bus_dma_tag_t inside a struct usb_page_cache. Deep analysis (lldb on the
vmcore, source review, and later a live DTrace capture) identified a
structural lock-discipline gap in usbd_transfer_unsetup_sub()
(sys/dev/usb/usb_transfer.c) that races with xhci_interrupt_poll()
(sys/dev/usb/controller/xhci.c) under real-world traffic on a busy
xHCI controller.
Root cause:
usbd_transfer_unsetup_sub() releases USB_BUS_LOCK before tearing down
the xfer's own page caches:
USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
...
usb_proc_mwait(info->done_p, &info->done_m[0], &info->done_m[1]);
USB_BUS_UNLOCK(info->bus); /* <-- lock released here */
#if USB_HAVE_BUSDMA
pc = info->dma_page_cache_start;
while (pc != info->dma_page_cache_end) { usb_pc_free_mem(pc); pc++; }
pc = info->xfer_page_cache_start;
while (pc != info->xfer_page_cache_end) { usb_pc_dmamap_destroy(pc); pc++;
}
usb_dma_tag_unsetup(&info->dma_parent_tag);
#endif
usb_pc_dmamap_destroy() is the only place that zeroes pc->tag; it runs
with no lock held. Meanwhile xhci_interrupt_poll() always runs under
USB_BUS_LOCK and, via xhci_activate_transfer()/xhci_generic_done_sub(),
calls usb_pc_cpu_invalidate(td->page_cache)/usb_pc_cpu_flush(td->page_cache)
on the exact same usb_page_cache array.
The only safety net usb_pc_cpu_invalidate()/usb_pc_cpu_flush() have is:
if (pc->page_offset_end == pc->page_offset_buf) return; /* "not loaded" */
usb_pc_free_mem() does NOT reset page_offset_buf/page_offset_end when it
frees pc->buffer, so this guard never fires for a pc that has just been
(or is concurrently being) freed by usbd_transfer_unsetup_sub() on
another CPU, and the racing call proceeds to dereference pc->tag/pc->map,
which may by then be stale.
Why this is not just theoretical:
Live DTrace on a test unit (2 USB RNDIS network/video interfaces + 2
USB-serial consoles on the same xHCI controller) showed
usbd_transfer_unsetup_sub() invoked roughly every 15-20 seconds after
boot. A clean DTrace capture measured the controller's true steady-state
interrupt rate at ~7400-7900/s (confirmed independently via vmstat -i),
with usb_pc_cpu_invalidate()+usb_pc_cpu_flush() combined firing at
~59000/s.
Update (2026-11-23): a 2-hour live DTrace capture (same probes, normal
production load) recorded 119 usbd_transfer_unsetup_sub() teardown
windows and 437,314,015 usb_pc_cpu_invalidate()+usb_pc_cpu_flush() calls
total; 15,823 of those reads from another CPU landed inside an open
teardown window (confirming the race window is routinely entered), but
none of those 15,823 happened to hit a pc pointer inside the 119
concurrently-freed ranges in this particular run. Two earlier shorter
captures (30s, 3min) on the same unit caught 0 teardowns at all, so hit
rate is highly workload-dependent.
Suggested fix:
Rather than extending USB_BUS_LOCK's hold time over the bus_dmamem_free()/
bus_dmamap_destroy()/bus_dma_tag_destroy() calls, set the existing
"not loaded" sentinel while STILL holding the lock, before USB_BUS_UNLOCK():
for each pc about to be destroyed (both loops):
pc->page_offset_buf = pc->page_offset_end;
USB_BUS_UNLOCK(info->bus);
/* existing unlocked free/destroy loops unchanged */
We checked (by grepping all of sys/dev/usb/) that no other code path
dereferences pc->tag/pc->map without going through this same guard, and
that usb_pc_free_mem()/usb_pc_dmamap_destroy()/usb_dma_tag_unsetup() do
not themselves depend on page_offset_buf/page_offset_end, so this
sentinel write should not have other side effects. We have not
submitted a formal patch/diff yet; happy to if useful.
How to reproduce:
No reliable minimal repro (the original panic happened once, in the
field, under real load). The lock-discipline gap is visible by code
inspection; the race WINDOW (not the exact same-pointer collision) is
directly observable with a DTrace script probing
usbd_transfer_unsetup_sub:entry/return, usb_pc_cpu_invalidate:entry,
usb_pc_cpu_flush:entry on any amd64 box with an actively-used xHCI
controller carrying more than one USB device generating steady traffic.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301029] usb(4)/xhci(4): UAF race between usbd_transfer_unsetup_sub() and xhci_interrupt_poll() on struct usb_page_cache
Author: bugzilla-noreply
Date: Mon, 23 Nov 2026 01:28
Date: Mon, 23 Nov 2026 01:28
16 lines
2579 bytes
2579 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301029
Viktor Dolgopiatov <viktor.dolgopiatov@icloud.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags| |maintainer-feedback+
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301029] usb(4)/xhci(4): UAF race between usbd_transfer_unsetup_sub() and xhci_interrupt_poll() on struct usb_page_cache
Author: bugzilla-noreply
Date: Mon, 23 Nov 2026 01:29
Date: Mon, 23 Nov 2026 01:29
16 lines
2562 bytes
2562 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301029
Viktor Dolgopiatov <viktor.dolgopiatov@icloud.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags|maintainer-feedback+ |
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301029] usb(4)/xhci(4): UAF race between usbd_transfer_unsetup_sub() and xhci_interrupt_poll() on struct usb_page_cache
Author: bugzilla-noreply
Date: Mon, 23 Nov 2026 17:10
Date: Mon, 23 Nov 2026 17:10
17 lines
2615 bytes
2615 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301029
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|kern |usb
Assignee|bugs@FreeBSD.org |usb@FreeBSD.org
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads