Skip to contentSkip to conversation

ARM: kretprobes: fix out-of-range literal issue in naked asm routine

PATCH In review Ard Biesheuvel 2 participants 2 messages Mar 25, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: kretprobes: fix out-of-range literal issue in naked asm routine

__kretprobe_trampoline is a naked C function implemented in asm, and the first thing it does is take its own address and record it in the frame record, so that a backtrace will properly traverse its stackframe.

As it turns out, using 'LDR <reg>, =<symbol>' notation is problematic here, as it relies on a literal pool to be emitted sufficiently close to the LDR instruction, and since the compiler is not aware of this need, this results in assembler errors in some cases.

Since the address taken is guaranteed to be the address of the instruction itself, just use ADR instead.

Cc Masami Hiramatsu <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Nick Desaulniers <[email protected]>
Fixes 7e9bf33b8124 ("ARM: kprobes: Make a frame pointer on __kretprobe_trampoline")
---
 arch/arm/probes/kprobes/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/probes/kprobes/core.c +1 -1
index 9090c3a74dcc..068639a777c8 100644
@@ -377,7 +377,7 @@ void __naked __kprobes __kretprobe_trampoline(void)
 {
 	__asm__ __volatile__ (
 #ifdef CONFIG_FRAME_POINTER
-		"ldr	lr, =__kretprobe_trampoline	\n\t"
+		"adr	lr, .			\n\t"
 	/* __kretprobe_trampoline makes a framepointer on pt_regs. */
 #ifdef CONFIG_CC_IS_CLANG
 		"stmdb	sp, {sp, lr, pc}	\n\t"
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Fri, 25 Mar 2022 09:03:02 +0100 Ard Biesheuvel <[email protected]> wrote:

__kretprobe_trampoline is a naked C function implemented in asm, and the first thing it does is take its own address and record it in the frame record, so that a backtrace will properly traverse its stackframe.

As it turns out, using 'LDR <reg>, =<symbol>' notation is problematic here, as it relies on a literal pool to be emitted sufficiently close to the LDR instruction, and since the compiler is not aware of this need, this results in assembler errors in some cases.

Since the address taken is guaranteed to be the address of the instruction itself, just use ADR instead.

Ah, indeed :)

This looks good to me.

Thank you very much!

Quoted 27 lines
Cc Masami Hiramatsu <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Nick Desaulniers <[email protected]>
Fixes 7e9bf33b8124 ("ARM: kprobes: Make a frame pointer on __kretprobe_trampoline")
---
 arch/arm/probes/kprobes/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/probes/kprobes/core.c +1 -1
index 9090c3a74dcc..068639a777c8 100644
@@ -377,7 +377,7 @@ void __naked __kprobes __kretprobe_trampoline(void)
 {
 	__asm__ __volatile__ (
 #ifdef CONFIG_FRAME_POINTER
-		"ldr	lr, =__kretprobe_trampoline	\n\t"
+		"adr	lr, .			\n\t"
 	/* __kretprobe_trampoline makes a framepointer on pt_regs. */
 #ifdef CONFIG_CC_IS_CLANG
 		"stmdb	sp, {sp, lr, pc}	\n\t"
Signature · 1 line
2.30.2
Signature · 6 lines
Masami Hiramatsu <[email protected]>

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel