[PATCH] riscv: kprobes: Prevent probes in breakpoint handlers

Rui Qi posted 1 patch 1 month, 4 weeks ago
There is a newer version of this series
arch/riscv/kernel/traps.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] riscv: kprobes: Prevent probes in breakpoint handlers
Posted by Rui Qi 1 month, 4 weeks ago
The ftrace selftest multiple_kprobes.tc registers kprobe events on
the first 256 text symbols from /proc/kallsyms. If handle_break() is
selected as a probe target on RISC-V, the breakpoint exception path
can trap again before it reaches the kprobe breakpoint handler. That
recursively enters do_trap_break() and can make the system
unresponsive.

Mark handle_break() and its local probe dispatch helpers as nokprobe
symbols so they are added to the kprobe blacklist, matching other
low-level breakpoint exception paths.

Signed-off-by: Rui Qi <qirui.001@bytedance.com>
---
 arch/riscv/kernel/traps.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index 2f57fd48ec28..5eb5785874dd 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -270,6 +270,8 @@ static bool probe_single_step_handler(struct pt_regs *regs)
 	return user ? uprobe_single_step_handler(regs) : kprobe_single_step_handler(regs);
 }
 
+NOKPROBE_SYMBOL(probe_single_step_handler);
+
 static bool probe_breakpoint_handler(struct pt_regs *regs)
 {
 	bool user = user_mode(regs);
@@ -277,6 +279,8 @@ static bool probe_breakpoint_handler(struct pt_regs *regs)
 	return user ? uprobe_breakpoint_handler(regs) : kprobe_breakpoint_handler(regs);
 }
 
+NOKPROBE_SYMBOL(probe_breakpoint_handler);
+
 void handle_break(struct pt_regs *regs)
 {
 	if (probe_single_step_handler(regs))
@@ -301,6 +305,8 @@ void handle_break(struct pt_regs *regs)
 		die(regs, "Kernel BUG");
 }
 
+NOKPROBE_SYMBOL(handle_break);
+
 asmlinkage __visible __trap_section void do_trap_break(struct pt_regs *regs)
 {
 	if (user_mode(regs)) {
-- 
2.20.1
Re: [PATCH] riscv: kprobes: Prevent probes in breakpoint handlers
Posted by Nam Cao 1 month, 4 weeks ago
"Rui Qi" <qirui.001@bytedance.com> writes:
> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> index 2f57fd48ec28..5eb5785874dd 100644
> --- a/arch/riscv/kernel/traps.c
> +++ b/arch/riscv/kernel/traps.c
> @@ -270,6 +270,8 @@ static bool probe_single_step_handler(struct pt_regs *regs)
>  	return user ? uprobe_single_step_handler(regs) : kprobe_single_step_handler(regs);
>  }
>  
> +NOKPROBE_SYMBOL(probe_single_step_handler);
> +

The usual style is NOKPROBE_SYMBOL() following the function with no
blank line.

Other than that:
Reviewed-by: Nam Cao <namcao@linutronix.de>