[PATCH] x86/sev: Leak pages in unknown state in alloc_shared_pages()
From: Yuho Choi
Date: Thu Dec 03 2026 - 11:16:38 EST
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@xxxxxxxxx>
---
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