Skip to content

Commit 5014396

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
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() Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 7f43d57 commit 5014396

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/riscv/include/asm/asm.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@
183183
REG_L x31, PT_T6(sp)
184184
.endm
185185

186+
/* Annotate a function as being unsuitable for kprobes. */
187+
#ifdef CONFIG_KPROBES
188+
#define ASM_NOKPROBE(name) \
189+
.pushsection "_kprobe_blacklist", "aw"; \
190+
RISCV_PTR name; \
191+
.popsection
192+
#else
193+
#define ASM_NOKPROBE(name)
194+
#endif
195+
186196
#endif /* __ASSEMBLY__ */
187197

188198
#endif /* _ASM_RISCV_ASM_H */

arch/riscv/kernel/entry.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ SYM_CODE_START(handle_exception)
111111
1:
112112
tail do_trap_unknown
113113
SYM_CODE_END(handle_exception)
114+
ASM_NOKPROBE(handle_exception)
114115

115116
/*
116117
* The ret_from_exception must be called with interrupt disabled. Here is the
@@ -184,6 +185,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
184185
sret
185186
#endif
186187
SYM_CODE_END(ret_from_exception)
188+
ASM_NOKPROBE(ret_from_exception)
187189

188190
#ifdef CONFIG_VMAP_STACK
189191
SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
@@ -219,6 +221,7 @@ SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
219221
move a0, sp
220222
tail handle_bad_stack
221223
SYM_CODE_END(handle_kernel_stack_overflow)
224+
ASM_NOKPROBE(handle_kernel_stack_overflow)
222225
#endif
223226

224227
SYM_CODE_START(ret_from_fork)

0 commit comments

Comments
 (0)