Skip to content

Commit 21855ca

Browse files
Eric Linpalmer-dabbelt
authored andcommitted
riscv/mm: Prevent kernel module to access user memory without uaccess routines
We found this issue in an legacy out-of-tree kernel module which didn't properly access user space pointer by get/put_user(). Such an illegal access loops in the page fault handler. To resolve this, let it die here. Signed-off-by: Eric Lin <[email protected]> Reviewed-by: Pekka Enberg <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 21733cb commit 21855ca

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

arch/riscv/mm/fault.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
243243
if (user_mode(regs))
244244
flags |= FAULT_FLAG_USER;
245245

246+
if (!user_mode(regs) && addr < TASK_SIZE &&
247+
unlikely(!(regs->status & SR_SUM)))
248+
die_kernel_fault("access to user memory without uaccess routines",
249+
addr, regs);
250+
246251
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
247252

248253
if (cause == EXC_STORE_PAGE_FAULT)

0 commit comments

Comments
 (0)