ASAravind Sivakumaran
Theme

Theme and appearance

Appearance
Palette

Pick any colour. The displayed accent adjusts for readable contrast in light or dark mode.

← IOMMU star map

SECURITY / BUFFER WORKBOOK

Follow 16 bytes through a bounce buffer

An ordinary NIC may not write a confidential VM's private pages (secure DMA), so Linux gives it a bounce buffer in shared memory and copies. The Linux DMA lab shows those copies; this workbook asks the security questions about the same bytes: when does each buffer change, what can the host read, and when may the application trust what arrived? The copies below follow Linux 7.3's code, as dmakit models it.

What claims does this page make? 2 points
The application's buffer App, the driver's private buffer O, the CPU copy, the shared bounce buffer B, and the NIC. Appapplication Odriver, private CPU copySWIOTLB Bbounce, shared NICDMA the host can read B

Address or copy? Four routes to the same buffer

A 32-bit device receives 16 bytes into O, which sits above 4 GiB. A translation (IOMMU) changes the address the device uses; only a CPU copy (SWIOTLB) moves bytes. Pick a route, map the buffer, and submit only if the map succeeded.

Route

Sharing a message shares its page

Experiments

Words used in the experiments
O, B, App
The driver's buffer at 0x100002040, private (the Linux DMA lab's Original A; 64 bytes into secure DMA's private page O; the model uses one address as both GPA and SPA), the bounce slot the kernel copies through (0x2000040, in a shared pool), and the application's buffer.
Map, sync, unmap
dma_map_single() gives the device an address; dma_sync_single_for_cpu() or _for_device() hands the buffer over; dma_unmap_single() ends it. With a bounce buffer, each can copy.
Receive, send
DMA_FROM_DEVICE (the device writes) and DMA_TO_DEVICE (the device reads).
RX16
The packet: de ad be ef, four times.

Experiment

Timeline: which buffer holds the bytes, and what the CPU copied

    Intel and Arm:

    The bytes after that step

    Buffers

      Copy ledger · every CPU copy so far, never erased by a later failure

        Counters

          What the host read

            Driver and application

              A copy of 16 bytes counts 16, not 32. Counts are bytes, not time. Descriptors and the application's checks are this page's own small model; the copies and the IOMMU are dmakit's.

              Three kinds of "ownership", all true at once

              QuestionAnswered byAfter a receive's sync
              May the CPU use O now?The DMA API (map, sync, unmap)Yes
              Whose page is O?The RMP (SNP)Still the VM's private page
              Can the application trust the bytes?The application's own checksNot until it checks them

              Pressing "sync" does not change who owns the page, and a private page can hold untrusted input.

              Rules that fall out

              Sources