Re: [PATCH] swiotlb: clear read bounce buffers on confidential guests

From: Edgecombe, Rick P

Date: Mon Nov 23 2026 - 17:19:13 EST


On Mon, 2026-11-23 at 21:53 +0100, Shukai Ni wrote:
> On confidential guests (AMD SEV, Intel TDX) all device DMA is bounced
> through swiotlb, whose pool is shared with and readable by the untrusted
> host. swiotlb_tbl_map_single() copies the destination buffer's current
> contents into the bounce buffer at map time even for DMA_FROM_DEVICE. For
> a reused read buffer that still holds private data, the host can read
> that data from the bounce buffer before the device overwrites it.
>
> For DMA_FROM_DEVICE into a host-shared pool, zero the bounce buffer
> instead. Zeroing rather than skipping the copy keeps a short read from
> returning a previous transfer's data.
>
> Fixes: ddbd89deb7d3 ("swiotlb: fix info leak with DMA_FROM_DEVICE")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Jo Van Bulck <jo.vanbulck@xxxxxxxxxxxxxx>
> Signed-off-by: Jo Van Bulck <jo.vanbulck@xxxxxxxxxxxxxx>
> Signed-off-by: Shukai Ni <shukai.ni@xxxxxxxxxxx>
> ---
>
> Notes:
>     We are open to discussing a different approach: e.g. clearing the
>     residual when read back, scrubbing slots on free, or extending zeroing
>     for bidirectional DMA.

There is an existing usptream position around coco driver hardening, that the
drivers should be fixed. In some ways this another thing that could be fixed in
a driver? The driver could zero memory before sharing it for DMA_FROM_DEVICE.

But the swiotlb was supposed to be sort of a generic solution to the problem of
not inadvertently sharing private memory. Instead of marking an entire page as
shared (which might have private contents elsewhere on the page), the bounce
buffer allows for only sharing the minimum specified.

So you could maybe look at this issue as fitting into the general problem of not
inadvertently sharing the private data inside the buffer. But also that is
covering for driver gaps.

It seems like the fixes commit was arguing that copying the contents to the
swiotlb buffer was more transparent. So this patch kind of goes back against
that argument. That seems to be another point that the drivers should be fixed.
If this is essentially more of a potentially behavior altering kernel hardening,
then I wonder about putting it behind some kind of hardening config like
CONFIG_INIT_ON_ALLOC_DEFAULT_ON.

Ohh, but I guess the problem is the buffer getting copied could have come from
userspace? So then you would have to fix userspace... But then this patch could
also potentially break userspace if there is any partial write assumptions. Oh
boy.