riscv: blacklist assembly symbols for kprobe
PATCH 1/1 riscv: blacklist assembly symbols for kprobe
Adding kprobes on some assembly functions (mainly exception handling) will result in crashes (either recursive trap or panic). To avoid such errors, add ASM_NOKPROBE() macro which allow adding specific symbols into the __kprobe_blacklist section and use to blacklist the following symbols that showed to be problematic:
- handle_exception()
- ret_from_exception()
- handle_kernel_stack_overflow()
--- arch/riscv/include/asm/asm.h | 10 ++++++++++ arch/riscv/kernel/entry.S | 3 +++ 2 files changed, 13 insertions(+)
arch/riscv/include/asm/asm.h +10 -0
@@ -142,6 +142,16 @@ REG_L x31, PT_T6(sp) .endm +/* Annotate a function as being unsuitable for kprobes. */ +#ifdef CONFIG_KPROBES +#define ASM_NOKPROBE (name) \ + .pushsection "_kprobe_blacklist", "aw"; \ + RISCV_PTR name; \ + .popsection +#else +#define ASM_NOKPROBE (name) +#endif +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_ASM_H */
arch/riscv/kernel/entry.S +3 -0
@@ -101,6 +101,7 @@ _save_context: 1: tail do_trap_unknown SYM_CODE_END(handle_exception) +ASM_NOKPROBE(handle_exception) /* * The ret_from_exception must be called with interrupt disabled. Here is the
@@ -167,6 +168,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception) sret #endif SYM_CODE_END(ret_from_exception) +ASM_NOKPROBE(ret_from_exception) #ifdef CONFIG_VMAP_STACK SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
@@ -254,6 +256,7 @@ restore_caller_reg: move a0, sp tail handle_bad_stack SYM_CODE_END(handle_kernel_stack_overflow) +ASM_NOKPROBE(handle_kernel_stack_overflow) #endif SYM_CODE_START(ret_from_fork)
Signature · 1 line
2.42.0
Quoted 72 lines · Clément Léger
Adding kprobes on some assembly functions (mainly exception handling) will result in crashes (either recursive trap or panic). To avoid such errors, add
ASM_NOKPROBE()macro which allow adding specific symbols into the__kprobe_blacklistsection and use to blacklist the following symbols that showed to be problematic:
-handle_exception()
-ret_from_exception()
-handle_kernel_stack_overflow()Signed-off-by Clément Léger <[email protected]>--- arch/riscv/include/asm/asm.h | 10 ++++++++++ arch/riscv/kernel/entry.S | 3 +++ 2 files changed, 13 insertions(+)arch/riscv/include/asm/asm.h +10
-0@@ -142,6 +142,16 @@ REG_L x31, PT_T6(sp) .endm +/* Annotate a function as being unsuitable for kprobes. */ +#ifdef CONFIG_KPROBES +#define ASM_NOKPROBE (name) \ + .pushsection "_kprobe_blacklist", "aw"; \ + RISCV_PTR name; \ + .popsection +#else +#define ASM_NOKPROBE (name) +#endif +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_ASM_H */ arch/riscv/kernel/entry.S +3
-0@@ -101,6 +101,7 @@ _save_context: 1: tail do_trap_unknown SYM_CODE_END(handle_exception) +ASM_NOKPROBE(handle_exception) /* * The ret_from_exception must be called with interrupt disabled. Here is the@@ -167,6 +168,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception) sret #endif SYM_CODE_END(ret_from_exception) +ASM_NOKPROBE(ret_from_exception) #ifdef CONFIG_VMAP_STACK SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)@@ -254,6 +256,7 @@ restore_caller_reg: move a0, sp tail handle_bad_stack SYM_CODE_END(handle_kernel_stack_overflow) +ASM_NOKPROBE(handle_kernel_stack_overflow) #endif SYM_CODE_START(ret_from_fork)Signature · 7 lines
2.42.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
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 10 lines · On Wed, 4 Oct 2023 15:10:09 +0200 you wrote:
Adding kprobes on some assembly functions (mainly exception handling) will result in crashes (either recursive trap or panic). To avoid such errors, add
ASM_NOKPROBE()macro which allow adding specific symbols into the__kprobe_blacklistsection and use to blacklist the following symbols that showed to be problematic:
-handle_exception()
-ret_from_exception()
-handle_kernel_stack_overflow()[...]
Here is the summary with links:
- riscv: blacklist assembly symbols for kprobe
https://git.kernel.org/riscv/c/5014396af9bb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html