From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v3 1/6] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area
Date: Sun, 19 Jul 2026 13:27:28 +0000 [thread overview]
Message-ID: <20260719132728.81D5C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260719130006.3882764-2-hca@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Physical pages are freed to the buddy allocator before their page table entries (PTEs) are cleared, creating a Use-After-Free and memory corruption window.
- [Medium] A sleeping memory allocation is performed inside a pte_fn_t callback under lazy_mmu_mode_enable(), violating core MM API contracts.
--
--- Patch [1]: [PATCH v3 1/6] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area ---
commit 2a65969cbdc861d6caeb95bb64f45d4facecff0e
Author: Heiko Carstens <hca@linux.ibm.com>
KVM: s390: pv: Use VM_SPARSE area for guest variable storage area
The guest variable storage area is allocated with vmalloc and then
donated to the ultravisor. Any kernel access to that area will result
in a secure storage access exception (aka fault).
This is a problem if such a memory area is read via /proc/kcore. This
causes an exception via vread_iter() and results in an unexpected short
read. Avoid this by allocating a custom VM_SPARSE area.
> diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
> index a284f98d97168..d1cdc5ae5e270 100644
> --- a/arch/s390/kernel/uv.c
> +++ b/arch/s390/kernel/uv.c
[ ... ]
> @@ -209,6 +210,70 @@ int uv_convert_from_secure_pte(pte_t pte)
> return uv_convert_from_secure_folio(pfn_folio(pte_pfn(pte)));
> }
>
> +static int uv_free_range_cb(pte_t *ptep, unsigned long addr, void *data)
> +{
> + pte_t pte = ptep_get(ptep);
> +
> + if (!pte_present(pte))
> + return 0;
> + /*
> + * Note: do not update the pte here, since there is no code which
> + * accesses the memory range, besides bugs. The invalidation of ptes
> + * and TLB flushing is deferred like for regular vfree() calls.
> + */
> + __free_page(pte_page(pte));
[Severity: High]
Is it safe to free the physical page back to the buddy allocator while the
PTE remains fully present in the init_mm page tables?
The commit message notes that vfree() defers PTE updates, but vfree() actually
clears the PTEs via remove_vm_area() before freeing the underlying pages.
Here, the pages are freed first, and the PTEs are cleared later when
free_vm_area() is called in uv_free_stor_var().
Could this create a window where the physical page is reallocated to another
process, but the current CPU still has a valid, writable PTE pointing to it?
Any stray kernel access or speculative execution through the old vmalloc
address could then silently corrupt the new owner's memory without faulting.
> + return 0;
> +}
> +
> +void uv_free_stor_var(void *stor_var)
> +{
[ ... ]
> +}
> +EXPORT_SYMBOL_FOR_MODULES(uv_free_stor_var, "kvm");
> +
> +static int uv_alloc_range_cb(pte_t *ptep, unsigned long addr, void *data)
> +{
> + struct page *page;
> + pte_t pte;
> +
> + page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
[Severity: Medium]
Does this violate the cross-architecture pte_fn_t API contract by performing
a sleeping memory allocation?
This callback is executed by apply_to_page_range(), which wraps the pte_fn_t
callbacks in a lazy MMU mode section. The MM subsystem guidelines dictate
that lazy MMU mode implies a possible atomic context (as it disables
preemption on some architectures), forbidding these callbacks from sleeping.
While lazy_mmu_mode_enable() is currently a no-op on s390, the commit message
states s390 expects to gain full support for lazy MMU mode in the future.
Will this GFP_KERNEL allocation then introduce a preemption-disabled deadlock?
> + if (!page)
> + return -ENOMEM;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260719130006.3882764-1-hca@linux.ibm.com?part=1
next prev parent reply other threads:[~2026-07-19 13:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 13:00 [PATCH v3 0/6] s390: Reintroduce support for DCACHE_WORD_ACCESS Heiko Carstens
2026-07-19 13:00 ` [PATCH v3 1/6] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area Heiko Carstens
2026-07-19 13:27 ` sashiko-bot [this message]
2026-07-19 13:00 ` [PATCH v3 2/6] s390/mm: Add missing mm check to do_secure_storage_access() Heiko Carstens
2026-07-19 13:13 ` sashiko-bot
2026-07-19 13:00 ` [PATCH v3 3/6] s390/mm: Use lock_mm_and_find_vma() in do_secure_storage_access() Heiko Carstens
2026-07-19 13:06 ` sashiko-bot
2026-07-19 13:00 ` [PATCH v3 4/6] s390/mm: Fix handling of vmalloc area " Heiko Carstens
2026-07-19 13:10 ` sashiko-bot
2026-07-19 13:00 ` [PATCH v3 5/6] s390/mm: Remove folio handling for kernel faults " Heiko Carstens
2026-07-19 13:14 ` sashiko-bot
2026-07-19 13:00 ` [PATCH v3 6/6] s390: Add support for DCACHE_WORD_ACCESS (again) Heiko Carstens
2026-07-19 13:08 ` sashiko-bot
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=20260719132728.81D5C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@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