Commit 2b4f16eb authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Zheng Yejian
Browse files

arm64: Recover kretprobe modified return address in stacktrace

mainline inclusion
from mainline-v5.16-rc1
commit cd9bc2c9
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9R2TB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cd9bc2c9258816dc934b300705076519d7375b81



------------------------------------------------------

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: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Signed-off-by: default avatarSteven 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: default avatarZheng Yejian <zhengyejian1@huawei.com>
parent fc7d1e03
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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);