sparc64: Report the fault address when a user window cannot be saved
PATCH 1/1 sparc64: Report the fault address when a user window cannot be saved
When the kernel spills a user register window and the store faults, the window is kept in the thread's window buffer. On the way back to user space fault_in_user_windows() writes it to the stack. If that write fails as well, it sends SIGSEGV with force_sig(). The handler gets SI_KERNEL and si_addr == 0.
When a thread overflows its stack, the first store into the guard page can be a window spill. If the kernel does that spill, for example during a system call, the window goes through this path. Stack overflow handlers compare si_addr with the guard page. With si_addr == 0 they cannot tell that the stack overflowed. The Rust runtime then resets the handler, and the process dies with SIGSEGV instead of reporting the overflow. Rust's tests/ui/runtime/out-of-stack.rs fails this way:
ferris[157185]: bad register window fault: SP fff800010f60bf90 (orig_sp fff800010f60b791) TPC fff800010f3a2db0 O7 00000100016039e4
Pass the address of the window to the signal, as stack_unaligned() does for SIGBUS in the same file. Look up the VMA to choose the si_code, as process_fpemu_return() does on MIPS. A spill into a PROT_NONE guard page then reports SEGV_ACCERR, whether the hardware or the kernel did the spill.
---
Tested on a T4-1 (sun4v) and a V240 (sun4u) with 7.3.6. A thread recurses and writes to a pipe at every level, so the kernel spills its windows. Before, the handler got si_code 128 and si_addr 0. After, it gets the window address and the same si_code as a spill by the
hardware: SEGV_ACCERR for a PROT_NONE guard, SEGV_MAPERR for an unmapped hole. out-of-stack.rs passes 10/10 on the T4. A handler that makes the guard writable and returns also works: the thread continues and every frame unwinds with the right values.
arch/sparc/kernel/process_64.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/sparc/kernel/process_64.c +10 -2
@@ -518,6 +518,8 @@ void fault_in_user_windows(struct pt_regs *regs) {struct thread_info *t =current_thread_info ();unsigned long window; +unsigned long sp; +int si_code;flush_user_windows (); window =get_thread_wsaved ();
@@ -527,7 +529,7 @@ void fault_in_user_windows(struct pt_regs *regs) do { struct reg_window *rwin = &t->reg_window[window]; int winsize = sizeof(struct reg_window); - unsigned long sp, orig_sp; + unsigned long orig_sp; orig_sp = sp = t->rwbuf_stkptrs[window];
@@ -557,7 +559,13 @@ void fault_in_user_windows(struct pt_regs *regs) barf:set_thread_wsaved (window +1 ); -force_sig (SIGSEGV ); +mmap_read_lock (current->mm); +if (vma_lookup (current->mm, sp)) + si_code =SEGV_ACCERR ; +else + si_code =SEGV_MAPERR ; +mmap_read_unlock (current->mm); +force_sig_fault (SIGSEGV , si_code, (void __user *) sp); }/* Copy a Sparc thread. The fork() return value conventions
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] sparc64: call to undeclared vma_lookup() in fault_in_user_windows() - [High] sparc64: missing trapno…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] sparc64: call to undeclared vma_lookup() in fault_in_user_windows()
- [High] sparc64: missing trapno argument to force_sig_fault() in process_64.c
- [Low] sparc64: missing Fixes trailer in commit message for fault_in_user_windows()
- [Low] sparc64: fault_in_user_windows() uses base sp on page-straddling fault
--
commit ee3413b56ca2f61248a64fe34c40cdf99b9dde0c
Author: Stian Halseth <[email protected]>
Quoted 19 lines
sparc64: Report the fault address when a user window cannot be saved
When the kernel spills a user register window and the store faults, the window is kept in the thread's window buffer. On the way back to user space
fault_in_user_windows()writes it to the stack. If that write fails as well, it sends SIGSEGV withforce_sig(). The handler getsSI_KERNELandsi_addr== 0.When a thread overflows its stack, the first store into the guard page can be a window spill. If the kernel does that spill, for example during a system call, the window goes through this path. Stack overflow handlers compare
si_addrwith the guard page. Withsi_addr== 0 they cannot tell that the stack overflowed. The Rust runtime then resets the handler, and the process dies with SIGSEGV instead of reporting the overflow. Rust'stests/ui/runtime/out-of-stack.rsfails this way:ferris[157185]: bad register window fault: SP
fff800010f60bf90(orig_spfff800010f60b791) TPCfff800010f3a2db0O700000100016039e4
Quoted 8 lines
Pass the address of the window to the signal, as
stack_unaligned()does for SIGBUS in the same file. Look up the VMA to choose thesi_code, asprocess_fpemu_return()does on MIPS. A spill into aPROT_NONEguard page then reportsSEGV_ACCERR, whether the hardware or the kernel did the spill.Signed-off-by Stian Halseth <[email protected]>
[Severity: Low]
Should this include a Fixes tag for the commit that introduced force_sig(SIGSEGV) in fault_in_user_windows():
Quoted 23 lines
arch/sparc/kernel/process_64.c +3
-1@@ -530,6 +530,8 @@ void fault_in_user_windows(struct pt_regs *regs) {struct thread_info *t =current_thread_info ();unsigned long window; +unsigned long sp; +int si_code;flush_user_windows (); window =get_thread_wsaved ();@@ -539,7 +541,7 @@ void fault_in_user_windows(struct pt_regs *regs) do { struct reg_window *rwin = &t->reg_window[window]; int winsize = sizeof(struct reg_window); - unsigned long sp, orig_sp; + unsigned long orig_sp; orig_sp = sp = t->rwbuf_stkptrs[window];
arch/sparc/kernel/process_64.c void fault_in_user_windows(struct pt_regs *regs) · line 575
Quoted 6 lines
arch/sparc/kernel/process_64.c +2
-1@@ -569,7 +571,13 @@ void fault_in_user_windows(struct pt_regs *regs) barf:set_thread_wsaved (window +1 ); -force_sig (SIGSEGV ); +mmap_read_lock (current->mm); +if (vma_lookup (current->mm, sp))
[Severity: High]
Does this fail to build because vma_lookup() is not declared in this tree? process_fpemu_return() in arch/mips/kernel/traps.c uses find_vma() and checks vma && vma->vm_start <= addr instead.
arch/sparc/kernel/process_64.c void fault_in_user_windows(struct pt_regs *regs) · line 568
Quoted 5 lines
arch/sparc/kernel/process_64.c +5
-0+ si_code =SEGV_ACCERR ; + else + si_code =SEGV_MAPERR ; +mmap_read_unlock (current->mm); +force_sig_fault (SIGSEGV , si_code, (void __user *) sp);
[Severity: High]
Does force_sig_fault() fail to compile on SPARC without the fourth trapno argument? SPARC defines __ARCH_SI_TRAPNO, so force_sig_fault() requires a trapno parameter as in stack_unaligned() just above:
arch/sparc/kernel/process_64.c:stack_unaligned() {
...
force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *) sp, 0);
}[Severity: Low]
Can looking up and reporting sp report the wrong fault address and si_code when the register window straddles a page boundary?
If sp lies near the top of a writable page and [sp, sp + winsize) crosses into an unmapped or non-writable upper page, copy_to_user() faults in the upper page and returns the uncopied byte count rem, but the VMA lookup and force_sig_fault() use sp in the writable lower page. Computing the fault address from the uncopied byte count (sp + winsize - rem) would report the faulting page.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi,
Sashiko tested the patch against Linux 5.12-rc2, davem/sparc.git. vma_lookup() was added later, and force_sig_fault() no longer has the trapno argument.
Agree with the Fixes tag:
Andreas, can you add the tag if you apply the patch, or do you want a v2?
On the final low finding:
The straddling window case needs sp just below an unmapped or read-only page. A stack overflow always faults at sp itself, so I kept it to the window address.
/Stian
Quoted 111 lines · On Wed, 2026-11-25 at 10:07 +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] sparc64: call to undeclaredvma_lookup()infault_in_user_windows()
- [High] sparc64: missing trapno argument toforce_sig_fault()inprocess_64.c
- [Low] sparc64: missing Fixes trailer in commit message forfault_in_user_windows()
- [Low] sparc64:fault_in_user_windows()uses base sp on page-straddling fault
--commit
ee3413b56ca2f61248a64fe34c40cdf99b9dde0c
Author: Stian Halseth <[email protected]>Quoted 19 lines
sparc64: Report the fault address when a user window cannot be saved
When the kernel spills a user register window and the store faults, the window is kept in the thread's window buffer. On the way back to user space
fault_in_user_windows()writes it to the stack. If that write fails as well, it sends SIGSEGV withforce_sig(). The handler getsSI_KERNELandsi_addr== 0.When a thread overflows its stack, the first store into the guard page can be a window spill. If the kernel does that spill, for example during a system call, the window goes through this path. Stack overflow handlers compare
si_addrwith the guard page. Withsi_addr== 0 they cannot tell that the stack overflowed. The Rust runtime then resets the handler, and the process dies with SIGSEGV instead of reporting the overflow. Rust'stests/ui/runtime/out-of-stack.rsfails this way:ferris[157185]: bad register window fault: SP
fff800010f60bf90(orig_spfff800010f60b791) TPCfff800010f3a2db0O700000100016039e4Quoted 8 lines
Pass the address of the window to the signal, as
stack_unaligned()does for SIGBUS in the same file. Look up the VMA to choose thesi_code, asprocess_fpemu_return()does on MIPS. A spill into aPROT_NONEguard page then reportsSEGV_ACCERR, whether the hardware or the kernel did the spill.Signed-off-by Stian Halseth <[email protected]>[Severity: Low]
Should this include a Fixes tag for the commit that introducedforce_sig(SIGSEGV)infault_in_user_windows():Fixes 5b4fc3882a64 ("sparc64: Make corrupted user stacks more debuggable.")Quoted 23 lines
arch/sparc/kernel/process_64.c +3
-1@@ -530,6 +530,8 @@ void fault_in_user_windows(struct pt_regs *regs) {struct thread_info *t =current_thread_info ();unsigned long window; +unsigned long sp; +int si_code;flush_user_windows (); window =get_thread_wsaved ();@@ -539,7 +541,7 @@ void fault_in_user_windows(struct pt_regs *regs) do { struct reg_window *rwin = &t->reg_window[window]; int winsize = sizeof(struct reg_window); - unsigned long sp, orig_sp; + unsigned long orig_sp; orig_sp = sp = t->rwbuf_stkptrs[window];arch/sparc/kernel/process_64.c void fault_in_user_windows(struct pt_regs *regs) · line 575
Quoted 6 lines
arch/sparc/kernel/process_64.c +2
-1@@ -569,7 +571,13 @@ void fault_in_user_windows(struct pt_regs *regs) barf:set_thread_wsaved (window +1 ); -force_sig (SIGSEGV ); +mmap_read_lock (current->mm); +if (vma_lookup (current->mm, sp))[Severity: High]
Does this fail to build becausevma_lookup()is not declared in this tree?process_fpemu_return()inarch/mips/kernel/traps.cusesfind_vma()and checks vma &&vma->vm_start<= addr instead.arch/sparc/kernel/process_64.c void fault_in_user_windows(struct pt_regs *regs) · line 568
Quoted 5 lines
arch/sparc/kernel/process_64.c +5
-0+ si_code =SEGV_ACCERR ; + else + si_code =SEGV_MAPERR ; +mmap_read_unlock (current->mm); +force_sig_fault (SIGSEGV , si_code, (void __user *) sp);[Severity: High]
Doesforce_sig_fault()fail to compile on SPARC without the fourth trapno argument? SPARC defines__ARCH_SI_TRAPNO, soforce_sig_fault()requires a trapno parameter as instack_unaligned()just above:arch/sparc/kernel/process_64.c:stack_unaligned() { ... force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *) sp, 0); }[Severity: Low]
Can looking up and reporting sp report the wrong fault address andsi_codewhen the register window straddles a page boundary?If sp lies near the top of a writable page and [sp, sp + winsize) crosses into an unmapped or non-writable upper page,
copy_to_user()faults in the upper page and returns the uncopied byte count rem, but the VMA lookup andforce_sig_fault()use sp in the writable lower page. Computing the fault address from the uncopied byte count (sp + winsize - rem) would report the faulting page.