From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: Alexandru Elisei <alexandru.elisei@arm.com>,
Marc Zyngier <maz@kernel.org>,
kvm@vger.kernel.org, kvmarm@lists.linux.dev,
Oliver Upton <oupton@kernel.org>
Subject: Re: [RFC PATCH] KVM: Ignore MMU notifiers for guest_memfd-only memslots
Date: Mon, 15 Jun 2026 10:47:14 -0700 [thread overview]
Message-ID: <ajA6ogaNiI3KDv5i@google.com> (raw)
In-Reply-To: <20260615160901.9A1A61F000E9@smtp.kernel.org>
On Mon, Jun 15, 2026, sashiko-bot@kernel.org wrote:
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> [ ... ]
> > @@ -592,6 +592,10 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
> > unsigned long hva_start, hva_end;
> >
> > slot = container_of(node, struct kvm_memory_slot, hva_node[slots->node_idx]);
> > +
> > + if (kvm_slot_has_gmem(slot) && kvm_memslot_is_gmem_only(slot))
> > + continue;
> > +
>
> [Severity: Critical]
> Does this change inadvertently introduce a regression in the pfncache retry
> protocol?
>
> Looking at the pfncache framework, it maps guest memory into kernel space and
> explicitly drops the page reference after mapping it:
>
> virt/kvm/pfncache.c:hva_to_pfn_retry() {
> ...
> kvm_release_page_clean(page);
> ...
> }
>
> It appears to rely entirely on KVM's MMU notifiers (kvm->mmu_invalidate_seq)
> to invalidate the cache when the page is unmapped by the host.
>
> If a VMM defines a guest_memfd-backed memslot with KVM_MEMSLOT_GMEM_ONLY
> but still provides a valid anonymous user mapping as its userspace_addr,
> could this regression lead to a use-after-free?
Sadly, yes. To land this, we would need to first teach the gfn_to_pfn_cache code
to be able to pull directly from guest_memfd. I forget if anyone is working on
that.
> By unmapping the anonymous memory, the host would trigger MMU notifiers, but
> this new check skips the memslot. As a result, kvm->mmu_invalidate_seq
> wouldn't increment, and KVM might retain a kernel mapping to a freed physical
> page.
>
> Could this allow the guest to read or write arbitrary host physical memory?
>
> > hva_start = max_t(unsigned long, range->start, slot->userspace_addr);
> > hva_end = min_t(unsigned long, range->end,
> > slot->userspace_addr + (slot->npages << PAGE_SHIFT));
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260615155244.183044-1-alexandru.elisei@arm.com?part=1
next prev parent reply other threads:[~2026-06-15 17:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 15:52 [RFC PATCH] KVM: Ignore MMU notifiers for guest_memfd-only memslots Alexandru Elisei
2026-06-15 16:09 ` sashiko-bot
2026-06-15 17:47 ` Sean Christopherson [this message]
2026-06-15 18:09 ` Sean Christopherson
2026-06-15 19:07 ` David Hildenbrand
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=ajA6ogaNiI3KDv5i@google.com \
--to=seanjc@google.com \
--cc=alexandru.elisei@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox