Skip to content

Commit 0dbb3f7

Browse files
Zhe Qiaosmb49
authored andcommitted
riscv/mm: Add handling for VM_FAULT_SIGSEGV in mm_fault_error()
BugLink: https://bugs.launchpad.net/bugs/2078428 [ Upstream commit 0c710050c47d45eb77b28c271cddefc5c785cb40 ] Handle VM_FAULT_SIGSEGV in the page fault path so that we correctly kill the process and we don't BUG() the kernel. Fixes: 07037db ("RISC-V: Paging and MMU") Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20240731084547.85380-1-qiaozhe@iscas.ac.cn Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 147877c commit 0dbb3f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

arch/riscv/mm/fault.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,27 @@ static inline void no_context(struct pt_regs *regs, unsigned long addr)
6060

6161
static inline void mm_fault_error(struct pt_regs *regs, unsigned long addr, vm_fault_t fault)
6262
{
63+
if (!user_mode(regs)) {
64+
no_context(regs, addr);
65+
return;
66+
}
67+
6368
if (fault & VM_FAULT_OOM) {
6469
/*
6570
* We ran out of memory, call the OOM killer, and return the userspace
6671
* (which will retry the fault, or kill us if we got oom-killed).
6772
*/
68-
if (!user_mode(regs)) {
69-
no_context(regs, addr);
70-
return;
71-
}
7273
pagefault_out_of_memory();
7374
return;
7475
} else if (fault & VM_FAULT_SIGBUS) {
7576
/* Kernel mode? Handle exceptions or die */
76-
if (!user_mode(regs)) {
77-
no_context(regs, addr);
78-
return;
79-
}
8077
do_trap(regs, SIGBUS, BUS_ADRERR, addr);
8178
return;
79+
} else if (fault & VM_FAULT_SIGSEGV) {
80+
do_trap(regs, SIGSEGV, SEGV_MAPERR, addr);
81+
return;
8282
}
83+
8384
BUG();
8485
}
8586

0 commit comments

Comments
 (0)