The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] x86/sev: Leak pages in unknown state in alloc_shared_pages()
@ 2026-12-03 16:16 Yuho Choi
  0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-12-03 16:16 UTC (permalink / raw)
  To: Borislav Petkov, Tom Lendacky
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Nikunj A Dadhania, Carlos López, linux-kernel, Yuho Choi

When set_memory_decrypted() fails, alloc_shared_pages() frees the page.
On SEV-SNP the page may already be shared in the RMP when the page table
update fails, so the allocator could hand out a page that is no longer
private. Leak it instead, as free_shared_pages() does on failure and as
commit fd948c3f96b1 ("virt: sev-guest: Explicitly leak pages in unknown
state") did for the certificate buffer.

Fixes: fce96cf04430 ("virt: Add SEV-SNP guest driver")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
An LLM helped me write this patch; I have no reproduction test for it.

Compile-tested only (W=1, x86_64 defconfig plus AMD_MEM_ENCRYPT and
SEV_GUEST) on tip x86/urgent a7505e93b280. The path needs an SEV-SNP
guest and a failure inside set_memory_decrypted(), such as -ENOMEM
while splitting the direct map, and I have no SNP host to run one.

 arch/x86/coco/sev/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index eb2e853e950a..be73b8c4cb55 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1519,8 +1519,7 @@ static void *alloc_shared_pages(size_t sz)
 
 	ret = set_memory_decrypted((unsigned long)page_address(page), npages);
 	if (ret) {
-		pr_err("failed to mark page shared, ret=%d\n", ret);
-		__free_pages(page, get_order(sz));
+		pr_err("failed to mark page shared, ret=%d (leak it)\n", ret);
 		return NULL;
 	}
 

base-commit: a7505e93b280feef120376e17e0c7fd2839c2f42
-- 
2.56.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 16:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:16 [PATCH] x86/sev: Leak pages in unknown state in alloc_shared_pages() Yuho Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox