mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yan Zhao <yan.y.zhao@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	David Hildenbrand <david@kernel.org>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Vishal Annapurve <vannapurve@google.com>
Subject: Re: [PATCH v2] KVM: guest_memfd: Elaborate on how release() vs. get_pfn() is safe against UAF
Date: Wed, 23 Sep 2026 13:01:35 +0800	[thread overview]
Message-ID: <arNdLw7Us/cRs7Ce@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <arKPLKedX4fs8Zef@google.com>

On Tue, Sep 22, 2026 at 07:22:36AM -0700, Sean Christopherson wrote:
> And the whole thing as a diff:
LGTM.

> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 9a112daa5df9..483998f0df58 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -312,7 +312,7 @@ static int kvm_gmem_release(struct inode *inode, struct file *file)
>  	 * synchronize_srcu_expedited() in kvm_swap_active_memslots() to ensure
>  	 * kvm_gmem_get_pfn() (which runs with kvm->srcu held for read) can't
>  	 * grab a reference to slot->gmem.file even if the struct file object
> -	 * is reallocated.
> +	 * is reallocated (for use as a different file).
>  	 *
>  	 * file_ref_put() provides a full barrier, and __get_file_rcu() the
>  	 * matching acquire barrier, to ensure that kvm_gmem_get_file() (via
> @@ -327,7 +327,7 @@ static int kvm_gmem_release(struct inode *inode, struct file *file)
>  	 *
>  	 *  CPU0				CPU1
>  	 *  kvm_gmem_get_pfn()
> -	 *    f = X (from slot->gmem.file)
> +	 *    slot->gmem.file == A
>  	 *					kvm_gmem_release())
>  	 *					  slot->gmem.file = NULL
>  	 *
> @@ -336,18 +336,19 @@ static int kvm_gmem_release(struct inode *inode, struct file *file)
>  	 *
>  	 *					kvm_set_memory_region()
>  	 *					  slot created
> -	 *					  slot->gmem.file = f (alloc the same object)
> +	 *					  slot->gmem.file = B (alloc the same object)
>  	 *
>  	 *  get_file_active()
> -	 *    file = f
> -	 *    file_reloaded = f
> +	 *    file = B
> +	 *    file_reloaded = B
>  	 *
>  	 * <KVM does weird things with an old memslot+file>
>  	 *
>  	 * Obviously KVM would be broken in many places if the synchronization
>  	 * were omitted, but it's important to note that get_file_active() does
> -	 * NOT guarantee a reference to the correct file was obtained, only
> -	 * that the file doesn't point at a reallocated object.
> +	 * NOT guarantee a reference to the "original" file was obtained, only
> +	 * that it grabbed a reference for the returned file, i.e. didn't grab
> +	 * a reference for file A, but then returned a pointer to file B.
>  	 */
>  	xa_for_each(&f->bindings, index, slot)
>  		WRITE_ONCE(slot->gmem.file, NULL);

      reply	other threads:[~2026-09-23  5:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 16:56 Sean Christopherson
2026-09-20 12:55 ` Yan Zhao
2026-09-21 13:40   ` Sean Christopherson
2026-09-21 13:43     ` Sean Christopherson
2026-09-22  3:47       ` Yan Zhao
2026-09-22  3:45     ` Yan Zhao
2026-09-22 14:22       ` Sean Christopherson
2026-09-23  5:01         ` Yan Zhao [this message]

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=arNdLw7Us/cRs7Ce@yzhao56-desk.sh.intel.com \
    --to=yan.y.zhao@intel.com \
    --cc=david@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vannapurve@google.com \
    /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

all inboxes | Powered by JetHome®