linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] virt: tdx-guest: Fix the decrypted failure memory free
@ 2024-06-13 11:19 Li RongQing
  2024-06-13 16:07 ` Dave Hansen
  2024-06-13 16:10 ` Edgecombe, Rick P
  0 siblings, 2 replies; 5+ messages in thread
From: Li RongQing @ 2024-06-13 11:19 UTC (permalink / raw)
  To: kirill.shutemov, dave.hansen, x86, linux-coco; +Cc: Li RongQing

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.

When set_memory_decrypted() fails, the memory should be encrypted
via set_memory_encrypted(); if encrypting the memory fails, leak it

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/virt/coco/tdx-guest/tdx-guest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
index 1253bf7..63271fc 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -125,7 +125,8 @@ static void *alloc_quote_buf(void)
 		return NULL;
 
 	if (set_memory_decrypted((unsigned long)addr, count)) {
-		free_pages_exact(addr, len);
+		if (!set_memory_encrypted((unsigned long)addr, count))
+			free_pages_exact(addr, len);
 		return NULL;
 	}
 
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-14  5:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 11:19 [PATCH] virt: tdx-guest: Fix the decrypted failure memory free Li RongQing
2024-06-13 16:07 ` Dave Hansen
2024-06-13 16:13   ` Edgecombe, Rick P
2024-06-13 16:10 ` Edgecombe, Rick P
2024-06-14  4:48   ` [外部邮件] " Li,Rongqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).