All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fred Griffoul" <griffoul@gmail.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [RFC PATCH v2 01/11] KVM: guest_memfd: Introduce guest memory ops and route native gmem through them
Date: Wed, 14 Oct 2026 09:51:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-171095@kernel.org> (raw)
In-Reply-To: <20261014093733.90312-2-griffoul@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: ignored xa_store_range failure in kvm_gmem_native_bind allows memory access to freed host pages
--

commit ab5f37736d076d164ccad403ab4a50bd2032eb9b
Author: David Woodhouse <dwmw@amazon.co.uk>

KVM: guest_memfd: Introduce guest memory ops and route native gmem through them

This commit introduces a vtable (struct kvm_gmem_ops) to allow alternate
subsystems to supply guest memory backing. The built-in guest_memfd
implementation is refactored to route its memory-side and file-level
callbacks through this new shared dispatch mechanism.

> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index db57c5766ab60..057f90eb835a1 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c

[ ... ]

> +static int kvm_gmem_native_bind(struct file *file, struct kvm *kvm,
> +				struct kvm_memory_slot *slot, loff_t offset)
> +{

[ ... ]

> +	/*
> +	 * memslots of flag KVM_MEM_GUEST_MEMFD are immutable, so bind must
> +	 * occur on a new memslot.  Because the memslot is not visible yet,
> +	 * kvm_gmem_get_pfn() is guaranteed to see the file.
> +	 */
> +	WRITE_ONCE(slot->gmem.file, file);
> +	slot->gmem.pgoff = start;
> +	if (kvm_gmem_supports_mmap(inode))
> +		slot->flags |= KVM_MEMSLOT_GMEM_ONLY;
> +
> +	xa_store_range(&f->bindings, start, end - 1, slot, GFP_KERNEL);
> +	r = 0;

[Severity: High]
Does this code handle potential memory allocation failures from 
xa_store_range()?

xa_store_range() can fail with -ENOMEM when allocating internal nodes for the
XArray. Because the return value is ignored and the path unconditionally
returns 0, the memslot is successfully bound from KVM's perspective, but is
missing from the f->bindings tracking structure.

During operations like fallocate (hole punch) or file release, KVM iterates
over f->bindings to find and zap the guest mappings. If the slot is missing
from the XArray, the guest mappings will not be zapped, which could allow the
guest to retain read/write access to physical memory that has been returned
to the host allocator.

> +out:
> +	filemap_invalidate_unlock(inode->i_mapping);
> +	return r;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014093733.90312-1-griffoul@gmail.com?part=1

  reply	other threads:[~2026-10-14  9:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  9:37 [RFC PATCH v2 00/11] mm: Memory providers for guest_memfd and iommufd Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 01/11] KVM: guest_memfd: Introduce guest memory ops and route native gmem through them Fred Griffoul
2026-10-14  9:51   ` sashiko-bot [this message]
2026-10-14  9:37 ` [RFC PATCH v2 02/11] KVM: guest_memfd: Let get_pfn() report read-only pages Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 03/11] mm: Add memory providers Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 04/11] KVM: guest_memfd: Add a memory provider backing Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 05/11] iommufd: Track the domains of pages that are not pinned Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 06/11] iommufd: Map memory provider files Fred Griffoul
2026-10-14  9:51   ` sashiko-bot
2026-10-14  9:37 ` [RFC PATCH v2 07/11] iommufd: Use large IOMMU pages for provider mappings Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 08/11] iommufd/selftest: Add mock-domain IOVA queries Fred Griffoul
2026-10-14  9:54   ` sashiko-bot
2026-10-14  9:37 ` [RFC PATCH v2 09/11] iommufd/selftest: Add a mock memory provider Fred Griffoul
2026-10-14  9:37 ` [RFC PATCH v2 10/11] samples/kvm: Add a memory provider sample Fred Griffoul
2026-10-14  9:50   ` sashiko-bot
2026-10-14  9:37 ` [RFC PATCH v2 11/11] KVM: selftests: Test a memory provider shared by KVM and iommufd Fred Griffoul

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=sashiko-outbox-171095@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=griffoul@gmail.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.