Skip to content

Commit 416721f

Browse files
bjorn-rivospalmer-dabbelt
authored andcommitted
riscv, mm: Perform BPF exhandler fixup on page fault
Commit 21855ca ("riscv/mm: Prevent kernel module to access user memory without uaccess routines") added early exits/deaths for page faults stemming from accesses to user-space without using proper uaccess routines (where sstatus.SUM is set). Unfortunatly, this is too strict for some BPF programs, which relies on BPF exhandler fixups. These BPF programs loads "BTF pointers". A BTF pointers could either be a valid kernel pointer or NULL, but not a userspace address. Resolve the problem by calling the fixup handler in the early exit path. Fixes: 21855ca ("riscv/mm: Prevent kernel module to access user memory without uaccess routines") Signed-off-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20230214162515.184827-1-bjorn@kernel.org Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 9493e6f commit 416721f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

arch/riscv/mm/fault.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
267267
if (user_mode(regs))
268268
flags |= FAULT_FLAG_USER;
269269

270-
if (!user_mode(regs) && addr < TASK_SIZE &&
271-
unlikely(!(regs->status & SR_SUM)))
272-
die_kernel_fault("access to user memory without uaccess routines",
273-
addr, regs);
270+
if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM))) {
271+
if (fixup_exception(regs))
272+
return;
273+
274+
die_kernel_fault("access to user memory without uaccess routines", addr, regs);
275+
}
274276

275277
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
276278

0 commit comments

Comments
 (0)