From: sashiko-bot@kernel.org
To: "Ackerley Tng" <ackerleytng@google.com>
Cc: kvm@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v4 13/44] KVM: guest_memfd: Apply content modes while setting memory attributes
Date: Thu, 13 Aug 2026 22:51:34 +0000 [thread overview]
Message-ID: <20260813225134.DFF471F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260326-gmem-inplace-conversion-v4-13-e202fe950ffd@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] WARN_ON() discards the error code from kvm_gmem_apply_content_mode(), leading to silent failures and a user-triggerable kernel warning (DoS vector).
- [Medium] Applying content mode without invalidating MMU mappings when memory attributes do not change causes data races and potential hardware machine checks.
--
--- Patch [13]: [PATCH RFC v4 13/44] KVM: guest_memfd: Apply content modes while setting memory attributes ---
commit 47c20f7dd20767b04a5efc7e5951d56b44e5a590
Author: Ackerley Tng <ackerleytng@google.com>
KVM: guest_memfd: Apply content modes while setting memory attributes
Provide defined memory content modes so that KVM can make guarantees about
memory content after setting memory attributes, according to userspace
requests.
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index e270e54e030f0..eeac7678fcf4e 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
[ ... ]
> @@ -752,9 +783,23 @@ static int __kvm_gmem_set_attributes(struct inode *inode, pgoff_t start,
>
> filemap_invalidate_lock(mapping);
>
> + if (!kvm_gmem_content_mode_is_supported(kvm, content_mode,
> + to_private)) {
> + r = -EOPNOTSUPP;
> + *err_index = start;
> + goto out;
> + }
> +
> mas_init(&mas, mt, start);
>
> if (kvm_gmem_range_has_attributes(mt, start, nr_pages, attrs)) {
> + /*
> + * Even if no update is required to attributes, the
> + * requested content mode is applied.
> + */
> + WARN_ON(kvm_gmem_apply_content_mode(kvm, content_mode,
> + inode, start, end));
> +
> r = 0;
> goto out;
> }
[Severity: Medium]
Does this path allow the host to modify memory (e.g., zeroing it) while the
guest still has active PTEs?
Since this early exit path skips kvm_gmem_invalidate_begin() or
unmap_mapping_pages(), the KVM MMU is not zapped. Could this introduce guest
data races, or hardware state machine violations if the architecture-specific
preserve operation acts on actively mapped private pages?
[Severity: High]
Is the error code from kvm_gmem_apply_content_mode() being discarded here?
WARN_ON() evaluates to a boolean and its return value isn't captured. If a
folio is hardware-poisoned and kvm_gmem_apply_content_mode_zero() returns
-EHWPOISON, it appears this will silently return 0 (success) to userspace
meaning memory was not zeroed as requested.
Additionally, since this is reachable by untrusted userspace via the
KVM_SET_MEMORY_ATTRIBUTES2 ioctl, could this trigger a host denial of
service if panic_on_warn is enabled?
[ ... ]
> @@ -786,6 +831,9 @@ static int __kvm_gmem_set_attributes(struct inode *inode, pgoff_t start,
> if (!to_private)
> kvm_gmem_invalidate(inode, start, end);
>
> + WARN_ON(kvm_gmem_apply_content_mode(kvm, content_mode, inode,
> + start, end));
> +
> mas_store_prealloc(&mas, xa_mk_value(attrs));
>
> kvm_gmem_invalidate_end(inode, start, end);
[Severity: High]
Similar to the early exit path above, does this discard the error code from
kvm_gmem_apply_content_mode()?
If this is modified to capture and return the error code, would we also
need to call mas_destroy(&mas) on the error path to avoid leaking the
preallocated maple tree nodes?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260326-gmem-inplace-conversion-v4-0-e202fe950ffd@google.com?part=13
next prev parent reply other threads:[~2026-08-13 22:51 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 22:24 [PATCH RFC v4 00/44] guest_memfd: In-place conversion support Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 01/44] KVM: guest_memfd: Introduce per-gmem attributes, use to guard user mappings Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 02/44] KVM: Rename KVM_GENERIC_MEMORY_ATTRIBUTES to KVM_VM_MEMORY_ATTRIBUTES Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 03/44] KVM: Enumerate support for PRIVATE memory iff kvm_arch_has_private_mem is defined Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 04/44] KVM: Stub in ability to disable per-VM memory attribute tracking Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 05/44] KVM: guest_memfd: Wire up kvm_get_memory_attributes() to per-gmem attributes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 06/44] KVM: guest_memfd: Update kvm_gmem_populate() to use gmem attributes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 07/44] KVM: guest_memfd: Only prepare folios for private pages Ackerley Tng
2026-04-01 14:05 ` Ackerley Tng
2026-04-01 15:16 ` Michael Roth
2026-04-01 21:43 ` Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 08/44] KVM: Introduce KVM_SET_MEMORY_ATTRIBUTES2 Ackerley Tng
2026-03-31 22:53 ` Michael Roth
2026-04-01 21:04 ` Sean Christopherson
2026-03-26 22:24 ` [PATCH RFC v4 09/44] KVM: guest_memfd: Enable INIT_SHARED on guest_memfd for x86 Coco VMs Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 10/44] KVM: guest_memfd: Add support for KVM_SET_MEMORY_ATTRIBUTES2 Ackerley Tng
2026-03-31 23:31 ` Michael Roth
2026-04-01 22:46 ` Ackerley Tng
2026-04-01 15:35 ` Michael Roth
2026-04-01 21:12 ` Sean Christopherson
2026-04-01 22:38 ` Ackerley Tng
2026-04-02 16:20 ` Ackerley Tng
2026-04-03 14:50 ` Ackerley Tng
2026-04-07 21:09 ` Michael Roth
2026-04-07 21:50 ` Vishal Annapurve
2026-04-07 22:09 ` Michael Roth
2026-04-08 0:33 ` Sean Christopherson
2026-04-08 16:54 ` Ackerley Tng
2026-04-08 19:48 ` Sean Christopherson
2026-04-08 11:01 ` Steven Price
2026-04-08 0:30 ` Sean Christopherson
2026-04-14 23:37 ` Michael Roth
2026-04-15 18:20 ` Michael Roth
2026-04-16 3:05 ` Michael Roth
2026-04-24 19:08 ` Ackerley Tng
2026-04-29 23:21 ` Michael Roth
2026-05-08 17:40 ` Sean Christopherson
2026-05-08 21:21 ` Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 11/44] KVM: guest_memfd: Handle lru_add fbatch refcounts during conversion safety check Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 12/44] KVM: guest_memfd: Introduce default handlers for content modes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 13/44] KVM: guest_memfd: Apply content modes while setting memory attributes Ackerley Tng
2026-08-13 22:51 ` sashiko-bot [this message]
2026-03-26 22:24 ` [PATCH RFC v4 14/44] KVM: x86: Add support for applying content modes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 15/44] KVM: Add CAP to enumerate supported SET_MEMORY_ATTRIBUTES2 flags Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 16/44] KVM: Move KVM_VM_MEMORY_ATTRIBUTES config definition to x86 Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 17/44] KVM: Let userspace disable per-VM mem attributes, enable per-gmem attributes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 18/44] KVM: selftests: Create gmem fd before "regular" fd when adding memslot Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 19/44] KVM: selftests: Rename guest_memfd{,_offset} to gmem_{fd,offset} Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 20/44] KVM: selftests: Add support for mmap() on guest_memfd in core library Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 21/44] KVM: selftests: Add selftests global for guest memory attributes capability Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 22/44] KVM: selftests: Update framework to use KVM_SET_MEMORY_ATTRIBUTES2 Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 23/44] KVM: selftests: Add helpers for calling ioctls on guest_memfd Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 24/44] KVM: selftests: Test using guest_memfd for guest private memory Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 25/44] KVM: selftests: Test basic single-page conversion flow Ackerley Tng
2026-03-31 22:33 ` Ackerley Tng
2026-04-01 21:08 ` Sean Christopherson
2026-03-26 22:24 ` [PATCH RFC v4 26/44] KVM: selftests: Test conversion flow when INIT_SHARED Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 27/44] KVM: selftests: Test conversion precision in guest_memfd Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 28/44] KVM: selftests: Test conversion before allocation Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 29/44] KVM: selftests: Convert with allocated folios in different layouts Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 30/44] KVM: selftests: Test that truncation does not change shared/private status Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 31/44] KVM: selftests: Test that shared/private status is consistent across processes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 32/44] KVM: selftests: Test conversion with elevated page refcount Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 33/44] KVM: selftests: Test that conversion to private does not support ZERO Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 34/44] KVM: selftests: Support checking that data not equal expected Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 35/44] KVM: selftests: Test that not specifying a conversion flag scrambles memory contents Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 36/44] KVM: selftests: Reset shared memory after hole-punching Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 37/44] KVM: selftests: Provide function to look up guest_memfd details from gpa Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 38/44] KVM: selftests: Provide common function to set memory attributes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 39/44] KVM: selftests: Check fd/flags provided to mmap() when setting up memslot Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 40/44] KVM: selftests: Make TEST_EXPECT_SIGBUS thread-safe Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 41/44] KVM: selftests: Update private_mem_conversions_test to mmap() guest_memfd Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 42/44] KVM: selftests: Add script to exercise private_mem_conversions_test Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 43/44] KVM: selftests: Update pre-fault test to work with per-guest_memfd attributes Ackerley Tng
2026-03-26 22:24 ` [PATCH RFC v4 44/44] KVM: selftests: Update private memory exits test to work with per-gmem attributes Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 0/6] guest_memfd in-place conversion selftests for SNP Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 1/6] KVM: selftests: Initialize guest_memfd with INIT_SHARED Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 2/6] KVM: selftests: Call snp_launch_update_data() providing copy of memory Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 3/6] KVM: selftests: Make guest_code_xsave more friendly Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 4/6] KVM: selftests: Allow specifying CoCo-privateness while mapping a page Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 5/6] KVM: selftests: Test conversions for SNP Ackerley Tng
2026-03-26 23:36 ` [POC PATCH 6/6] KVM: selftests: Test content modes ZERO and PRESERVE " Ackerley Tng
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=20260813225134.DFF471F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ackerleytng@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-trace-kernel@vger.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