All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ackerley Tng <ackerleytng@google.com>
Cc: sashiko-reviews@lists.linux.dev, Oliver Upton <oupton@kernel.org>,
	kvm@vger.kernel.org,  kvmarm@lists.linux.dev,
	Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH v2 3/4] KVM: SEV: Drop page refcount early in VMSA reload
Date: Fri, 21 Aug 2026 06:36:45 -0700	[thread overview]
Message-ID: <aohUbUKcvUaoVFEc@google.com> (raw)
In-Reply-To: <CAEvNRgHX-NebA7z3twusis35E_grJNTrbse7aUZ6+D=qpQn14A@mail.gmail.com>

On Fri, Aug 21, 2026, Ackerley Tng wrote:
> Ackerley Tng <ackerleytng@google.com> writes:
> >> This is a pre-existing issue, but can this allow a malicious guest to
> >> cause a host kernel panic?
> >>
> >> Looking at sev_gmem_make_shared() in arch/x86/kvm/svm/sev.c:
> >>
> >> arch/x86/kvm/svm/sev.c:sev_gmem_make_shared() {
> >>     ...
> >> 		rc = rmp_make_shared(pfn, use_2m_update ? PG_LEVEL_2M : PG_LEVEL_4K);
> >> 		if (WARN_ONCE(rc, "SEV: Failed to update RMP entry for PFN 0x%llx error %d\n",
> >> 			      pfn, rc))
> >> 			goto next_pfn;
> >>     ...
> >> }
> >>
> >> If an untrusted SEV-SNP guest modifies a guest_memfd page state to VMSA
> >> using RMPADJUST, and the page is subsequently freed, rmp_make_shared()
> >> will architecturally fail on the VMSA page.
> >
> > I need some help with this one.
> >
> > For the initial VMSA page, IIUC snp_safe_alloc_page() gets a
> > non-guest_memfd page. This won't ever go through sev_gmem_make_shared(),
> > so we're good. snp_leak_pages() doesn't actually leak pages, it just
> > tracks leaked pages, but __free_page() is skipped so the page is really
> > leaked.
> >
> >> Because the error is bypassed without calling snp_leak_pages(), the
> >> firmware-owned page is returned to the host page allocator.
> >
> > For guest-provided VMSA pages, those can be guest_memfd pages. The
> > refcount taken is the one guest_memfd holds. Without considering
> > conversions, just considering truncation, sev_gmem_make_shared() is
> > called from kvm_gmem_free_folio(). Sashiko is saying that
> > rmp_make_shared() will fail, and the folio is freed.
> >
> > Sounds like this would be a problem if the folio is used elsewhere...?
> 
> I looked closer, "15.36.12 Running SNP-Active Virtual Machines" in APM
> Vol2 says "After a successful VMRUN, the VMCB page, as well as any AVIC
> Backing Page and VMSA Page are marked as in-use by hardware, and any
> attempt to modify the RMP entries for these pages via instructions like
> RMPUPDATE will result in a FAIL_INUSE response. The in-use marking is
> automatically cleared by hardware after a #VMEXIT event".
> 
> So it's not true that rmp_make_shared() will always fail on a VMSA page,
> it's only true if the guest vCPU is running.

Correct.

> RMPADJUST sets up the VMSA page, and telling the host using
> SVM_VMGEXIT_AP_CREATE is how the VMSA is set up to be usable. Then, the
> other vCPU needs to be started and running, and then:
> 
> If the host truncates the VMSA page or host closes the guest_memfd file
> containing some other vCPU's VMSA page, sev_gmem_make_shared() on the
> VMSA page should fail, but the page is released anyway and we have a
> problem.
> 
> An unsolicited shared->private conversion is fine since the VMSA page is
> already private.
> 
> sev_gmem_make_shared() would fail on an unsolicited private->shared
> conversion. The RMP entry would still indicate private, and guest_memfd
> would track it as shared...? Bad.
> 
> I've been trying to write a mini reproducer like a selftest but I've
> still not gotten it to work yet. If someone knows there's no issue here
> please let me know!

I have a reproducer I created to prove and validate 74bdfb2f6d18 ("KVM: SEV:
Forcefully invalidate SNP VMSA if its backing gmem page is zapped"), I'll make
sure to run it when applying (the final version of) this series.

  reply	other threads:[~2026-08-21 13:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  9:15 [PATCH v2 0/4] Stop returning struct page from guest_memfd PFN lookup Ackerley Tng
2026-08-18  9:15 ` [PATCH v2 1/4] KVM: SEV: Treat unassigned RMP entry as benign race on PSMASH failure Ackerley Tng
2026-08-19  0:11   ` Michael Roth
2026-08-18  9:15 ` [PATCH v2 2/4] KVM: SEV: Drop page refcount early during RMP fault handling Ackerley Tng
2026-08-18  9:29   ` sashiko-bot
2026-08-20  7:53     ` Ackerley Tng
2026-08-19  0:23   ` Michael Roth
2026-08-20 14:58     ` Ackerley Tng
2026-08-20 21:56       ` Michael Roth
2026-08-20 22:35         ` Ackerley Tng
2026-08-20 23:08           ` Michael Roth
2026-08-20 23:34             ` Ackerley Tng
2026-08-20 23:36             ` Sean Christopherson
2026-08-18  9:15 ` [PATCH v2 3/4] KVM: SEV: Drop page refcount early in VMSA reload Ackerley Tng
2026-08-18  9:27   ` sashiko-bot
2026-08-20  9:20     ` Ackerley Tng
2026-08-21  8:43       ` Ackerley Tng
2026-08-21 13:36         ` Sean Christopherson [this message]
2026-08-19  0:31   ` Michael Roth
2026-08-18  9:15 ` [PATCH v2 4/4] KVM: guest_memfd: Stop returning struct page from PFN lookup Ackerley Tng
2026-08-18  9:31   ` sashiko-bot
2026-08-20  9:11     ` Ackerley Tng
2026-08-18 13:58   ` Suzuki K Poulose
2026-08-19  0:49   ` Michael Roth
2026-08-19  8:52   ` Yan Zhao
2026-08-20 14:47     ` Ackerley Tng
2026-08-21  3:19       ` Yan Zhao
2026-08-18 17:12 ` [PATCH v2 0/4] Stop returning struct page from guest_memfd " David Hildenbrand (Arm)
2026-08-18 19:55   ` Sean Christopherson
2026-08-19  7:44     ` David Hildenbrand (Arm)
2026-08-19 14:27       ` Sean Christopherson

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=aohUbUKcvUaoVFEc@google.com \
    --to=seanjc@google.com \
    --cc=ackerleytng@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.