Re: [PATCH v3 8/9] ARM: kprobes: Make a frame pointer on __kretprobe_trampoline
From: Ard Biesheuvel <ardb@kernel.org>
Date: 2021-12-04 08:55:50
Also in:
lkml
Subsystem:
arm port, the rest · Maintainers:
Russell King, Linus Torvalds
On Fri, 3 Dec 2021 at 21:38, Arnd Bergmann [off-list ref] wrote:
On Thu, Oct 21, 2021 at 2:55 AM Masami Hiramatsu [off-list ref] wrote:quoted
Currently kretprobe on ARM just fills r0-r11 of pt_regs, but that is not enough for the stacktrace. Moreover, from the user kretprobe handler, stacktrace needs a frame pointer on the __kretprobe_trampoline. This adds a frame pointer on __kretprobe_trampoline for both gcc and clang case. Those have different frame pointer so we need different but similar stack on pt_regs. Gcc makes the frame pointer (fp) to point the 'pc' address of the {fp, ip (=sp), lr, pc}, this means {r11, r13, r14, r15}. Thus if we save the r11 (fp) on pt_regs->r12, we can make this set on the end of pt_regs. On the other hand, Clang makes the frame pointer to point the 'fp' address of {fp, lr} on stack. Since the next to the pt_regs->lr is pt_regs->sp, I reused the pair of pt_regs->fp and pt_regs->ip. So this stores the 'lr' on pt_regs->ip and make the fp to point pt_regs->fp. For both cases, saves __kretprobe_trampoline address to pt_regs->lr, so that the stack tracer can identify this frame pointer has been made by the __kretprobe_trampoline. Note that if the CONFIG_FRAME_POINTER is not set, this keeps fp as is. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>This causes a regression that I see in randconfig builds with gcc-11: /tmp/ccovvQNw.s: Assembler messages: /tmp/ccovvQNw.s:32: Error: invalid literal constant: pool needs to be closer make[5]: *** [/git/arm-soc/scripts/Makefile.build:288: arch/arm/probes/kprobes/core.o] Error 1 I have two randconfigs that reproduce it locally, here is a .config [1] and assembly output[2] for reference. I have not done any further analysis, but maybe you have an idea.
Does this help?
diff --git a/arch/arm/probes/kprobes/core.c b/arch/arm/probes/kprobes/core.c
index 9090c3a74dcc..88999ed2cfc4 100644
--- a/arch/arm/probes/kprobes/core.c
+++ b/arch/arm/probes/kprobes/core.c@@ -408,6 +408,7 @@ void __naked __kprobes __kretprobe_trampoline(void) #else "mov pc, lr \n\t" #endif + ".ltorg \n\t" : : : "memory"); }
_______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel