From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH v4 2/8] s390/mm: Add missing mm check to do_secure_storage_access()
Date: Mon, 20 Jul 2026 09:12:43 +0000 [thread overview]
Message-ID: <20260720091243.B79281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720085834.898025-3-hca@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing VMA boundary check in user space fault path can trigger a kernel WARN_ON_ONCE due to a race condition with concurrent munmap.
- [High] Using virt_to_folio() on arbitrary kernel fault addresses can cause a kernel panic if the address is in vmalloc space.
- [High] Failing to run exception fixups for kernel-mode faults in `do_secure_storage_access()` causes an infinite loop.
--
--- Patch [2]: [PATCH v4 2/8] s390/mm: Add missing mm check to do_secure_storage_access() ---
commit 61b1851bdfb6749b6398a064bf9e76283ed6b1e3
Author: Heiko Carstens <hca@linux.ibm.com>
s390/mm: Add missing mm check to do_secure_storage_access()
Similar like the normal exception handler the secure storage access
exception handler needs to verify if mm is not NULL, which may happen
with kernel threads.
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260717132345.539A11F00A3A@smtp.kernel.org/
> diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
> index 028aeb9c48d6f..2839d7a64401c 100644
> --- a/arch/s390/mm/fault.c
> +++ b/arch/s390/mm/fault.c
> @@ -409,9 +409,9 @@ void do_secure_storage_access(struct pt_regs *regs)
> {
> union teid teid = { .val = regs->int_parm_long };
> unsigned long addr = get_fault_address(regs);
> + struct mm_struct *mm = current->mm;
> struct vm_area_struct *vma;
> struct folio_walk fw;
> - struct mm_struct *mm;
> struct folio *folio;
> int rc;
>
[ ... ]
> panic("Unexpected PGM 0x3d with TEID bit 61=0");
> }
> if (is_kernel_fault(regs)) {
> folio = virt_to_folio((void *)addr);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
This isn't a bug introduced by this patch, but does using virt_to_folio()
unconditionally here cause a kernel panic if the fault address is in vmalloc
space?
If the kernel accesses donated secure memory that was allocated via vmalloc,
virt_to_folio() on s390 uses __pa(), which only works for direct-mapped
addresses. This would produce a garbage physical address, leading to an
out-of-bounds pointer dereference in the subsequent folio_try_get() check.
> if (unlikely(!folio_try_get(folio)))
> return;
> rc = uv_convert_from_secure(folio_to_phys(folio));
[ ... ]
> if (rc)
> return handle_fault_error_nolock(regs, 0);
> } else {
> - if (faulthandler_disabled())
> + if (faulthandler_disabled() || !mm)
> return handle_fault_error_nolock(regs, 0);
> - mm = current->mm;
> mmap_read_lock(mm);
> vma = find_vma(mm, addr);
^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
This is a pre-existing issue, but does find_vma() properly check that the
address is within the VMA's boundaries before we call folio_walk_start()?
find_vma() returns the first VMA with vm_end greater than addr, but its
vm_start could also be greater than addr if the faulting address was just
unmapped by a concurrent munmap(). If this happens, we would pass a VMA
to folio_walk_start() that doesn't actually contain the address, which
triggers its strict WARN_ON_ONCE assertion. Should this be using
vma_lookup() instead?
> if (!vma)
> return handle_fault_error(regs, SEGV_MAPERR);
> folio = folio_walk_start(&fw, vma, addr, 0);
> if (!folio) {
> mmap_read_unlock(mm);
> return;
> }
> /* arch_make_folio_accessible() needs a raised refcount. */
> folio_get(folio);
> rc = arch_make_folio_accessible(folio);
> folio_put(folio);
> folio_walk_end(&fw, vma);
> if (rc)
> send_sig(SIGSEGV, current, 0);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
This isn't a bug introduced by this patch, but does this error path cause an
infinite loop if the fault was triggered by a kernel-mode access like
copy_to_user()?
For kernel faults that happen in the user address space, is_kernel_fault()
is false. If arch_make_folio_accessible() fails here, we send a SIGSEGV
and return without calling fixup_exception(). Because fixup_exception() is
not run, the kernel will return to the faulting instruction rather than an
error path, causing the instruction to endlessly re-execute and lock up
the CPU.
> mmap_read_unlock(mm);
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720085834.898025-1-hca@linux.ibm.com?part=2
next prev parent reply other threads:[~2026-07-20 9:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 8:58 [PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS Heiko Carstens
2026-07-20 8:58 ` [PATCH v4 1/8] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area Heiko Carstens
2026-07-20 9:14 ` sashiko-bot
2026-07-20 9:56 ` Christian Borntraeger
2026-07-20 10:15 ` Heiko Carstens
2026-07-20 8:58 ` [PATCH v4 2/8] s390/mm: Add missing mm check to do_secure_storage_access() Heiko Carstens
2026-07-20 9:12 ` sashiko-bot [this message]
2026-07-20 10:44 ` Christian Borntraeger
2026-07-20 8:58 ` [PATCH v4 3/8] s390/mm: Use lock_mm_and_find_vma() in do_secure_storage_access() Heiko Carstens
2026-07-20 9:19 ` sashiko-bot
2026-07-20 10:45 ` Christian Borntraeger
2026-07-20 8:58 ` [PATCH v4 4/8] s390/mm: Fix handling of vmalloc area " Heiko Carstens
2026-07-20 9:23 ` sashiko-bot
2026-07-20 10:22 ` Christian Borntraeger
2026-07-20 8:58 ` [PATCH v4 5/8] s390/mm: Remove folio handling for kernel faults " Heiko Carstens
2026-07-20 9:30 ` sashiko-bot
2026-07-20 10:53 ` Christian Borntraeger
2026-07-20 8:58 ` [PATCH v4 6/8] s390/mm: Use handle_fault_error() " Heiko Carstens
2026-07-20 9:26 ` sashiko-bot
2026-07-20 8:58 ` [PATCH v4 7/8] s390/mm: Use goto statement " Heiko Carstens
2026-07-20 9:36 ` sashiko-bot
2026-07-20 10:36 ` Christian Borntraeger
2026-07-20 8:58 ` [PATCH v4 8/8] s390: Add support for DCACHE_WORD_ACCESS (again) Heiko Carstens
2026-07-20 9:48 ` sashiko-bot
2026-07-21 9:59 ` Sven Schnelle
2026-07-20 9:03 ` [PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS Christian Borntraeger
2026-07-20 9:40 ` Heiko Carstens
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=20260720091243.B79281F000E9@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