0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/usb_util
HuJK c43077eabc usb: a transfer too big for the DMA window goes through a plain buffer
reserve_dma_buffer() handed out a DmaBuffer carrying the size the caller
asked for, never comparing it against the mapping it points into. That
mapping is a fixed MMAP_SIZE (1 MB) window over the usbfs fd, while the
size comes from the guest's transfer descriptor -- so a longer request
produced a DmaBuffer whose size does not describe its mapping. Every
caller trusts that size: as_mut_slice() built a slice running off the end
of the window, and that slice's length is the only bound
ScatterGatherBuffer::read() has, so the copy walked straight past it.

A DisplayLink adapter, whose driver pushes a frame as one bulk transfer,
killed crosvm the moment the guest enabled display output. From the
crash: memcpy(dst=0x6d5b015000, src=0x6f69310000, 0x10000) with the
destination base at 0x6d5af15000 -- the fault address is base + 0x100000,
exactly MMAP_SIZE, on the 17th of the TD's 64 kB TRBs. The IN direction
had the mirror of it: as_slice() read past the window and wrote what it
found there into guest memory.

So ask the mapping for its size. A request that does not fit is refused,
and request_transfer_buffer() falls back to TransferBuffer::Vector, whose
length does describe its allocation; that costs a copy into the kernel's
own DMA buffer and is bounded. The check reads managed.buf.size() rather
than MMAP_SIZE so it still holds if the window ever stops being that
constant.

The refusal is reported once per new maximum rather than per transfer: a
device whose transfers never fit asks again for every frame, and the
useful thing to have in the log is the size it settles on, not thousands
of identical lines. Nothing is logged for the pre-existing fallback of a
busy slot.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NrTFaLfTucJb9LBtxtU6Ab
History 2026-09-12 13:27:31 +08:00
..
src usb: a transfer too big for the DMA window goes through a plain buffer 2026-09-12 13:27:31 +08:00
Android.bp Merge remote-tracking branch 'aosp/upstream-main' into merge 2025-02-25 18:10:03 +00:00
Cargo.toml crosvm: upgrade zerocopy to 0.8 2025-02-24 11:35:51 -08:00
OWNERS devices: usb: Add the OWNERS file 2023-10-13 01:34:19 +00:00