]> git.baikalelectronics.ru Git - kernel.git/commit
dma-direct: don't over-decrypt memory
authorRobin Murphy <robin.murphy@arm.com>
Fri, 20 May 2022 17:10:13 +0000 (18:10 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 23 May 2022 13:25:40 +0000 (15:25 +0200)
commitcdf0fd7a837657c3e8c3d1148e698d89ac9b682d
treeba5dc0010beb736ab375eecc72890bb71a4cb131
parent231a5fbab5c328ac11a59889a7adfa894b3d7d43
dma-direct: don't over-decrypt memory

The original x86 sev_alloc() only called set_memory_decrypted() on
memory returned by alloc_pages_node(), so the page order calculation
fell out of that logic. However, the common dma-direct code has several
potential allocators, not all of which are guaranteed to round up the
underlying allocation to a power-of-two size, so carrying over that
calculation for the encryption/decryption size was a mistake. Fix it by
rounding to a *number* of pages, rather than an order.

Until recently there was an even worse interaction with DMA_DIRECT_REMAP
where we could have ended up decrypting part of the next adjacent
vmalloc area, only averted by no architecture actually supporting both
configs at once. Don't ask how I found that one out...

Fixes: 8a8ee1a861ad ("dma/direct: Handle force decryption for DMA coherent buffers in common code")
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David Rientjes <rientjes@google.com>
kernel/dma/direct.c