Skip to content

Commit 30d18df

Browse files
mhklinuxliuw
authored andcommitted
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 <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent 3d788b2 commit 30d18df

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/hv/channel.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ void vmbus_free_ring(struct vmbus_channel *channel)
153153
hv_ringbuffer_cleanup(&channel->inbound);
154154

155155
if (channel->ringbuffer_page) {
156-
__free_pages(channel->ringbuffer_page,
156+
/* In a CoCo VM leak the memory if it didn't get re-encrypted */
157+
if (!channel->ringbuffer_gpadlhandle.decrypted)
158+
__free_pages(channel->ringbuffer_page,
157159
get_order(channel->ringbuffer_pagecount
158160
<< PAGE_SHIFT));
159161
channel->ringbuffer_page = NULL;

0 commit comments

Comments
 (0)