All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v3 2/6] s390/mm: Add missing mm check to do_secure_storage_access()
Date: Sun, 19 Jul 2026 13:13:07 +0000	[thread overview]
Message-ID: <20260719131307.E40B61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260719130006.3882764-3-hca@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing VMA Bounds Check allows Denial of Service via WARN_ON_ONCE.
- [High] Invalid Memory Access / Kernel Crash via virt_to_folio() on non-direct-mapped addresses.
--

--- Patch [2]: [PATCH v3 2/6] s390/mm: Add missing mm check to do_secure_storage_access() ---
commit 55ed80680943e84fffd67209605311fedc0e28ae
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;
>  

[ ... ]

> @@ -453,9 +453,8 @@ void do_secure_storage_access(struct pt_regs *regs)
>  		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);
>  		if (!vma)

[Severity: High]
This isn't a bug introduced by this patch, but can this cause memory
corruption?

Earlier in this same function:

arch/s390/mm/fault.c:do_secure_storage_access() {
    ...
	if (is_kernel_fault(regs)) {
		folio = virt_to_folio((void *)addr);
    ...
}

When the kernel accesses a secure guest page through a vmalloc mapping,
is_kernel_fault(regs) evaluates to true. Then virt_to_folio() is
unconditionally applied to the faulting kernel address without validating that
it is a direct-mapped address.

Since virt_to_folio() subtracts the direct map offset, wouldn't it produce a
bogus PFN for vmalloc addresses, leading to dereferencing a garbage struct page
pointer?

[Severity: High]
This is also a pre-existing issue, but could this lead to a denial of service
via WARN_ON_ONCE?

Looking at do_secure_storage_access() in arch/s390/mm/fault.c, find_vma()
returns a VMA that may start after the faulting address, which is not verified
before use.

If a concurrent thread unmaps the VMA between the time the hardware generates
the secure storage exception and the handler acquires the mmap lock, could
find_vma() return the next adjacent VMA?

If so, passing this potentially unrelated VMA to folio_walk_start():

arch/s390/mm/fault.c:do_secure_storage_access() {
    ...
		vma = find_vma(mm, addr);
		if (!vma)
			return handle_fault_error(regs, SEGV_MAPERR);
		folio = folio_walk_start(&fw, vma, addr, 0);
    ...
}

would trigger the WARN_ON_ONCE(addr < vma->vm_start || addr >= vma->vm_end)
safety check. Could a malicious user-space program exploit this race by
repeatedly triggering secure storage accesses while concurrently unmapping
regions to crash the system if panic_on_warn is enabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260719130006.3882764-1-hca@linux.ibm.com?part=2

  reply	other threads:[~2026-07-19 13:13 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
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 [this message]
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=20260719131307.E40B61F000E9@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 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.