Skip to contentSkip to conversation

s390/mm: Add missing vm_start <= addr check to do_secure_storage_access()

PATCH In review Heiko Carstens 4 participants 5 messages Jul 17 – Jul 24

Subsystems (3)
lore
Share & tools
lore

Heiko Carstens

author maintainer
#0 lore raw

PATCH 1/1 s390/mm: Add missing vm_start <= addr check to do_secure_storage_access()

do_secure_storage_access() uses find_vma() without verifying that the faulting address is within the returned vma. Add this missing check by converting to lock_mm_and_find_vma().

This is not a critical fix, since the worst that could happen is WARN_ON_ONCE() in folio_walk_start().

---
 arch/s390/mm/fault.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/s390/mm/fault.c +2 -3
index 028aeb9c48d6..d6c58d78edc5 100644
@@ -456,10 +456,9 @@ void do_secure_storage_access(struct pt_regs *regs)
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);
 		mm = current->mm;
-		mmap_read_lock(mm);
-		vma = find_vma(mm, addr);
+		vma = lock_mm_and_find_vma(mm, addr, regs);
 		if (!vma)
-			return handle_fault_error(regs, SEGV_MAPERR);
+			return handle_fault_error_nolock(regs, SEGV_MAPERR);
 		folio = folio_walk_start(&fw, vma, addr, 0);
 		if (!folio) {
 			mmap_read_unlock(mm);
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

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

Pre-existing issues:
- [High] Missing !mm check in do_secure_storage_access allows kernel threads faulting on user-space accesses to trigger a NULL pointer dereference. --

--- Patch [1]: [PATCH] s390/mm: Add missing vm_start <= addr check to do_secure_storage_access() --- commit 925b56344e2c328b11b68034f7f630693a6c6b31
Author: Heiko Carstens <[email protected]>

s390/mm: Add missing vm_start <= addr check to do_secure_storage_access()

This patch converts do_secure_storage_access() to use lock_mm_and_find_vma() to ensure the faulting address is properly checked against the VMA boundaries.

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 459

Quoted 11 lines
arch/s390/mm/fault.c +1 -2
index 028aeb9c48d6f..d6c58d78edc5a 100644
@@ -456,10 +456,9 @@ void do_secure_storage_access(struct pt_regs *regs)
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);
 		mm = current->mm;
-		mmap_read_lock(mm);
-		vma = find_vma(mm, addr);
+		vma = lock_mm_and_find_vma(mm, addr, regs);

[Severity: High]
This is a pre-existing issue, but does this lack of a NULL check on mm lead to a crash if a kernel thread faults on a user-space access?

When a kernel thread (which has current->mm == NULL) triggers a secure storage access exception (for instance, via a copy_from_user() mapped to a secure page), it enters this branch. The mm pointer is set to NULL and then passed to lock_mm_and_find_vma():

vma = lock_mm_and_find_vma(mm, addr, regs);

Inside lock_mm_and_find_vma(), it unconditionally calls mmap_read_lock(mm):

mm/mmap_lock.c:lock_mm_and_find_vma() {
        ...
        mmap_read_lock(mm);
        ...
}

Could this result in a NULL pointer dereference? The do_page_fault() path handles this gracefully with an explicit !mm check and exception fixups, but do_secure_storage_access() appears to be missing this check.

Quoted 3 lines
arch/s390/mm/fault.c +1 -1
 		if (!vma)
-			return handle_fault_error(regs, SEGV_MAPERR);
+			return handle_fault_error_nolock(regs, SEGV_MAPERR);

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Heiko Carstens
Quoted 21 lines · Heiko Carstens

do_secure_storage_access() uses find_vma() without verifying that the faulting address is within the returned vma. Add this missing check by converting to lock_mm_and_find_vma().

This is not a critical fix, since the worst that could happen is WARN_ON_ONCE() in folio_walk_start().

---
 arch/s390/mm/fault.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/s390/mm/fault.c +0 -0
index 028aeb9c48d6..d6c58d78edc5 100644
@@ -456,10 +456,9 @@ void do_secure_storage_access(struct pt_regs *regs)
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 464

Quoted 10 lines
arch/s390/mm/fault.c +2 -3
 		mm = current->mm;
-		mmap_read_lock(mm);
-		vma = find_vma(mm, addr);
+		vma = lock_mm_and_find_vma(mm, addr, regs);
 		if (!vma)
-			return handle_fault_error(regs, SEGV_MAPERR);
+			return handle_fault_error_nolock(regs, SEGV_MAPERR);
 		folio = folio_walk_start(&fw, vma, addr, 0);
 		if (!folio) {
 			mmap_read_unlock(mm);

The Sashiko feedback looks like a false positive to me.

author maintainer
#3 lore raw
Quoted 21 lines · Alexander Gordeev
Quoted 7 lines · Heiko Carstens
arch/s390/mm/fault.c +0 -0
index 028aeb9c48d6..d6c58d78edc5 100644
@@ -456,10 +456,9 @@ void do_secure_storage_access(struct pt_regs *regs)
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 464

Quoted 10 lines
arch/s390/mm/fault.c +2 -3
 		mm = current->mm;
-		mmap_read_lock(mm);
-		vma = find_vma(mm, addr);
+		vma = lock_mm_and_find_vma(mm, addr, regs);
 		if (!vma)
-			return handle_fault_error(regs, SEGV_MAPERR);
+			return handle_fault_error_nolock(regs, SEGV_MAPERR);
 		folio = folio_walk_start(&fw, vma, addr, 0);
 		if (!folio) {
 			mmap_read_unlock(mm);

The Sashiko feedback looks like a false positive to me.

Quoted 1 line

This has been integrated into the "[PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS" series. First I thought of keeping things separate, but decided then to address all of Sashiko reports and make the code look quite similar to do_exception().

So v4 is the only series that matters, everything else can be ignored.

What is still missing is kmemleak handling for which Christian posted a patch, but that appears to be incomplete. Or least my thinking is that there will be a subsequent patch.

Christian?

#4 lore raw

Am 24.07.26 um 14:48 schrieb Heiko Carstens:

Quoted 29 lines · Alexander Gordeev
Quoted 21 lines · Heiko Carstens
Quoted 7 lines
arch/s390/mm/fault.c +0 -0
index 028aeb9c48d6..d6c58d78edc5 100644
@@ -456,10 +456,9 @@ void do_secure_storage_access(struct pt_regs *regs)
  		if (faulthandler_disabled())
  			return handle_fault_error_nolock(regs, 0);

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 464

Quoted 10 lines
arch/s390/mm/fault.c +2 -3
  		mm = current->mm;
-		mmap_read_lock(mm);
-		vma = find_vma(mm, addr);
+		vma = lock_mm_and_find_vma(mm, addr, regs);
  		if (!vma)
-			return handle_fault_error(regs, SEGV_MAPERR);
+			return handle_fault_error_nolock(regs, SEGV_MAPERR);
  		folio = folio_walk_start(&fw, vma, addr, 0);
  		if (!folio) {
  			mmap_read_unlock(mm);

The Sashiko feedback looks like a false positive to me.

Quoted 1 line

This has been integrated into the "[PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS" series. First I thought of keeping things separate, but decided then to address all of Sashiko reports and make the code look quite similar to do_exception().

Quoted 7 lines

So v4 is the only series that matters, everything else can be ignored.

What is still missing is kmemleak handling for which Christian posted a patch, but that appears to be incomplete. Or least my thinking is that there will be a subsequent patch.

Christian?

Yes, its on my todo list to extend the initial patch to also take care of the other storage areas. Still doing other things first.....