Skip to contentSkip to conversation

riscv, mm: Perform BPF exhandler fixup on page fault

PATCH Applied Björn Töpel 2 participants 2 messages Feb 14, 2023 – Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv, mm: Perform BPF exhandler fixup on page fault

From: Björn Töpel <[email protected]>

Commit 21855cac82d3 ("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 21855cac82d3 ("riscv/mm: Prevent kernel module to access user memory without uaccess routines")

---
Palmer,

This is a fix for BPF on riscv, but I'd still like to take it via the RISC-V tree, given the mm changes.

BPF/BTF is a special snowflake, and needs special care. ;-)

If BPF_PROBE_MEM is ever to be used for usermode pointers in the future, then the fixup call can be removed, in favor of setting sstatus.SUM from the BPF jitted code.

Björn

---
 arch/riscv/mm/fault.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/riscv/mm/fault.c +6 -4
index d86f7cebd4a7..eb0774d9c03b 100644
@@ -267,10 +267,12 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
 	if (user_mode(regs))
 		flags |= FAULT_FLAG_USER;
 
-	if (!user_mode(regs) && addr < TASK_SIZE &&
-			unlikely(!(regs->status & SR_SUM)))
-		die_kernel_fault("access to user memory without uaccess routines",
-				addr, regs);
+	if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM))) {
+		if (fixup_exception(regs))
+			return;
+
+		die_kernel_fault("access to user memory without uaccess routines", addr, regs);
+	}
 
 	perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
 

base-commit: 950b879b7f0251317d26bae0687e72592d607532

Signature · 7 lines
2.37.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 8 lines · On Tue, 14 Feb 2023 17:25:15 +0100 you wrote:

From: Björn Töpel <[email protected]>

Commit 21855cac82d3 ("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).

[...]

Here is the summary with links:
- riscv, mm: Perform BPF exhandler fixup on page fault

    https://git.kernel.org/riscv/c/416721ff05fd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html