Skip to content

Fix VirtIO descriptor length validation bugs#799

Open
olivia-wu-epsf wants to merge 4 commits intointel:mainfrom
olivia-wu-epsf:fix/virtio-descriptor-len-validation
Open

Fix VirtIO descriptor length validation bugs#799
olivia-wu-epsf wants to merge 4 commits intointel:mainfrom
olivia-wu-epsf:fix/virtio-descriptor-len-validation

Conversation

@olivia-wu-epsf
Copy link
Copy Markdown

Summary

Clamp VMM-controlled descriptor len values to the known DMA allocation size before passing them to slice_from_raw_parts/from_raw_parts. This prevents out-of-bounds reads when a malicious VMM overwrites the shared DMA descriptor table with inflated length values.

Changes

Bug 1: Vsock driver (src/devices/vsock/src/transport/virtio_pci.rs)

  • pkt[1].len is now clamped to dma_record.dma_size in the receive path
  • Changed contains_key to get to retrieve the DMA record for size validation

Bug 2: VirtIO serial driver (src/devices/virtio_serial/src/lib.rs)

  • Control path: Added DMA address validation via dma_allocation.get() (previously missing) and clamped vq_buf.len to record.dma_size
  • Data path: Changed contains_key to get, clamped buffer.len to record.dma_size, and clamped the downstream used_len to safe_len to prevent a secondary OOB on the slice index

Classification

These are reliability bugs (Rust UB, potential crash). Not security vulnerabilities under the Confidential Computing threat model, since OOB reads only reach VMM-controlled shared memory (no confidentiality loss) or cause a crash (DoS, which is out of scope per the TDX threat model).

Testing

  • cargo check -p vsock -p virtio_serial compiles cleanly
  • cargo test -p vsock -p virtio_serial -p virtio all existing tests pass

Clamp VMM-controlled descriptor len values to the known DMA allocation
size before passing them to slice_from_raw_parts/from_raw_parts. This
prevents out-of-bounds reads when a malicious VMM overwrites the shared
DMA descriptor table with inflated length values.

Bug 1 (vsock): pkt[1].len is now clamped to dma_record.dma_size in
virtio_pci.rs receive path.

Bug 2 (virtio_serial): vq_buf.len and buffer.len are now clamped to
dma_allocation.dma_size in both the control message receive path and the
data receive path. The control path also now validates the DMA address
via dma_allocation.get() before creating the slice.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@olivia-wu-epsf olivia-wu-epsf requested a review from jyao1 as a code owner April 17, 2026 18:14
@jyao1 jyao1 closed this Apr 22, 2026
@jyao1 jyao1 reopened this Apr 22, 2026
@jyao1 jyao1 requested a review from sgrams as a code owner April 22, 2026 02:20
@jyao1
Copy link
Copy Markdown
Contributor

jyao1 commented Apr 22, 2026

@olivia-wu-epsf, could you please fix cargo fmt / clippy issue?

@jyao1 jyao1 closed this Apr 23, 2026
@jyao1 jyao1 reopened this Apr 23, 2026
olivia-wu-epsf and others added 3 commits April 24, 2026 11:26
Fix rustfmt formatting in virtio_serial and vsock drivers to pass
the CI cargo fmt --check step.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address cargo-deny advisory RUSTSEC-2026-0104 (reachable panic in
certificate revocation list parsing) by updating rustls-webpki
from 0.103.10 to 0.103.13.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Main already contains rustls-webpki 0.103.13 (RUSTSEC-2026-0104 fix),
so take main's Cargo.lock as the resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants