summaryrefslogtreecommitdiffstats
path: root/drivers/hv
diff options
context:
space:
mode:
authorMichael Kelley <mhklinux@outlook.com>2024-03-11 17:15:58 +0100
committerWei Liu <wei.liu@kernel.org>2024-04-10 23:33:33 +0200
commit30d18df6567be09c1433e81993e35e3da573ac48 (patch)
tree0538db590f101ab8fcc58784b958199f2597a47f /drivers/hv
parentuio_hv_generic: Don't free decrypted memory (diff)
downloadlinux-30d18df6567be09c1433e81993e35e3da573ac48.tar.xz
linux-30d18df6567be09c1433e81993e35e3da573ac48.zip
Drivers: hv: vmbus: Don't free ring buffers that couldn't be re-encrypted
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. The VMBus ring buffer code could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the struct vmbus_gpadl for the ring buffers to decide whether to free the memory. Signed-off-by: Michael Kelley <mhklinux@outlook.com> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/r/20240311161558.1310-6-mhklinux@outlook.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <20240311161558.1310-6-mhklinux@outlook.com>
Diffstat (limited to 'drivers/hv')
-rw-r--r--drivers/hv/channel.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 98259b492502..fb8cd8469328 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -153,7 +153,9 @@ void vmbus_free_ring(struct vmbus_channel *channel)
hv_ringbuffer_cleanup(&channel->inbound);
if (channel->ringbuffer_page) {
- __free_pages(channel->ringbuffer_page,
+ /* In a CoCo VM leak the memory if it didn't get re-encrypted */
+ if (!channel->ringbuffer_gpadlhandle.decrypted)
+ __free_pages(channel->ringbuffer_page,
get_order(channel->ringbuffer_pagecount
<< PAGE_SHIFT));
channel->ringbuffer_page = NULL;