From: Masami Hiramatsu mhiramat@kernel.org
mainline inclusion from mainline-v5.16-rc1 commit cd9bc2c9258816dc934b300705076519d7375b81 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9R2TB
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
------------------------------------------------------
Since the kretprobe replaces the function return address with the kretprobe_trampoline on the stack, stack unwinder shows it instead of the correct return address.
This checks whether the next return address is the __kretprobe_trampoline(), and if so, try to find the correct return address from the kretprobe instance list. For this purpose this adds 'kr_cur' loop cursor to memorize the current kretprobe instance.
With this fix, now arm64 can enable CONFIG_ARCH_CORRECT_STACKTRACE_ON_KRETPROBE, and pass the kprobe self tests.
Signed-off-by: Masami Hiramatsu mhiramat@kernel.org Acked-by: Will Deacon will@kernel.org Signed-off-by: Steven Rostedt (VMware) rostedt@goodmis.org Conflicts: arch/arm64/Kconfig arch/arm64/include/asm/stacktrace.h arch/arm64/kernel/stacktrace.c [Adapt for calling kretprobe_find_ret_addr()] Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- arch/arm64/kernel/stacktrace.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index c445828ecc3a..2073a3a7fe75 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -101,6 +101,10 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) frame->pc = ret_stack->ret; } #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ +#ifdef CONFIG_KRETPROBES + if (is_kretprobe_trampoline(frame->pc)) + frame->pc = kretprobe_find_ret_addr(tsk, (void *)frame->fp); +#endif
frame->pc = ptrauth_strip_insn_pac(frame->pc);