Re: [PATCH v1 5/8] dma: Use size for swiotlb boundary checks

Andi Kleen
2021-06-03T02:10:55Z

On 6/2/2021 6:48 PM, Konrad Rzeszutek Wilk wrote:
> On Wed, Jun 02, 2021 at 05:41:30PM -0700, Andi Kleen wrote:
>> swiotlb currently only uses the start address of a DMA to check if something
>> is in the swiotlb or not. But with virtio and untrusted hosts the host
>> could give some DMA mapping that crosses the swiotlb boundaries,
>> potentially leaking or corrupting data. Add size checks to all the swiotlb
>> checks and reject any DMAs that cross the swiotlb buffer boundaries.
> I seem to be only CC-ed on this and #7, so please bear with me.
You weren't cc'ed originally so if you get partial emails it must be
through some list.
>
> But could you explain to me why please:
>
> commit daf9514fd5eb098d7d6f3a1247cb8cc48fc94155 (swiotlb/stable/for-linus-5.12)
> Author: Martin Radev <martin.b.radev@gmail.com>
> Date: Tue Jan 12 16:07:29 2021 +0100
>
> swiotlb: Validate bounce size in the sync/unmap path
>
> does not solve the problem as well?

Thanks. I missed that patch, race condition.

One major difference of my patch is that it supports an error return,
which allows virtio to error out. This is important in virtio because
otherwise you'll end up with uninitialized memory on the target without
any indication. This uninitialized memory could be an potential attack
vector on the guest memory, e.g. if the attacker finds some way to echo
it out again.

But the error return could be added to your infrastructure too and what
would make this patch much shorter. I'll take a look at that.

-Andi