Skip to content

Commit 0c71005

Browse files
Zhe Qiaopalmer-dabbelt
Zhe Qiao
authored andcommitted
riscv/mm: Add handling for VM_FAULT_SIGSEGV in mm_fault_error()
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 <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 941a8e9 commit 0c71005

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
@@ -61,26 +61,27 @@ static inline void no_context(struct pt_regs *regs, unsigned long addr)
6161

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

0 commit comments

Comments
 (0)