* [PATCH][v3] virt: tdx-guest: Don't free decrypted memory
@ 2024-06-19 8:47 Li RongQing
2024-06-19 10:37 ` Kirill A. Shutemov
0 siblings, 1 reply; 2+ messages in thread
From: Li RongQing @ 2024-06-19 8:47 UTC (permalink / raw)
To: kirill.shutemov, dave.hansen, x86, linux-coco, linux-kernel,
rick.p.edgecombe
Cc: Li RongQing
In CoCo VMs it is possible for the untrusted host to cause
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. So leak the decrypted memory when
set_memory_decrypted fails, and don't need to print an error
since set_memory_decrypted will call WARN_ONCE.
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
diff with v2: remove print error
diff with v1: leak the page, and print error
drivers/virt/coco/tdx-guest/tdx-guest.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
index 1253bf7..8575d98 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -124,10 +124,8 @@ static void *alloc_quote_buf(void)
if (!addr)
return NULL;
- if (set_memory_decrypted((unsigned long)addr, count)) {
- free_pages_exact(addr, len);
+ if (set_memory_decrypted((unsigned long)addr, count))
return NULL;
- }
return addr;
}
--
2.9.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][v3] virt: tdx-guest: Don't free decrypted memory
2024-06-19 8:47 [PATCH][v3] virt: tdx-guest: Don't free decrypted memory Li RongQing
@ 2024-06-19 10:37 ` Kirill A. Shutemov
0 siblings, 0 replies; 2+ messages in thread
From: Kirill A. Shutemov @ 2024-06-19 10:37 UTC (permalink / raw)
To: Li RongQing; +Cc: dave.hansen, x86, linux-coco, linux-kernel, rick.p.edgecombe
On Wed, Jun 19, 2024 at 04:47:50PM +0800, Li RongQing wrote:
> In CoCo VMs it is possible for the untrusted host to cause
> 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. So leak the decrypted memory when
> set_memory_decrypted fails, and don't need to print an error
> since set_memory_decrypted will call WARN_ONCE.
Add "()" for set_memory_decrypted() and WARN_ONCE().
And put the solution into a separate paragraph:
s/ So leak/\n\nLeak/
> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
Otherwise, looks good:
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kiryl Shutsemau / Kirill A. Shutemov
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-19 10:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-19 8:47 [PATCH][v3] virt: tdx-guest: Don't free decrypted memory Li RongQing
2024-06-19 10:37 ` Kirill A. Shutemov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®