The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Yuho Choi <oss.patchbox@gmail.com>
To: Borislav Petkov <bp@alien8.de>, Tom Lendacky <thomas.lendacky@amd.com>
Cc: "Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Nikunj A Dadhania" <nikunj@amd.com>,
	"Carlos López" <clopez@suse.de>,
	linux-kernel@vger.kernel.org,
	"Yuho Choi" <oss.patchbox@gmail.com>
Subject: [PATCH] x86/sev: Leak pages in unknown state in alloc_shared_pages()
Date: Thu,  3 Dec 2026 16:16:09 +0000	[thread overview]
Message-ID: <20261203161611.1974881-2-oss.patchbox@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-03 16:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203161611.1974881-2-oss.patchbox@gmail.com \
    --to=oss.patchbox@gmail.com \
    --cc=bp@alien8.de \
    --cc=clopez@suse.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=tglx@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox