Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/kprobes: Add UNWIND_HINT_FUNC on kretprobe_trampoline()

Add UNWIND_HINT_FUNC on __kretprobe_trampoline() code so that ORC
information is generated on the __kretprobe_trampoline() correctly.
Also, this uses STACK_FRAME_NON_STANDARD_FP(), CONFIG_FRAME_POINTER-
-specific version of STACK_FRAME_NON_STANDARD().

Link: https://lkml.kernel.org/r/163163049242.489837.11970969750993364293.stgit@devnote2

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Josh Poimboeuf and committed by
Steven Rostedt (VMware)
eb4a3f7d 5b284b19

+16 -2
+5
arch/x86/include/asm/unwind_hints.h
··· 52 52 UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=8 type=UNWIND_HINT_TYPE_FUNC 53 53 .endm 54 54 55 + #else 56 + 57 + #define UNWIND_HINT_FUNC \ 58 + UNWIND_HINT(ORC_REG_SP, 8, UNWIND_HINT_TYPE_FUNC, 0) 59 + 55 60 #endif /* __ASSEMBLY__ */ 56 61 57 62 #endif /* _ASM_X86_UNWIND_HINTS_H */
+11 -2
arch/x86/kernel/kprobes/core.c
··· 1025 1025 /* We don't bother saving the ss register */ 1026 1026 #ifdef CONFIG_X86_64 1027 1027 " pushq %rsp\n" 1028 + UNWIND_HINT_FUNC 1028 1029 " pushfq\n" 1029 1030 SAVE_REGS_STRING 1030 1031 " movq %rsp, %rdi\n" ··· 1036 1035 " popfq\n" 1037 1036 #else 1038 1037 " pushl %esp\n" 1038 + UNWIND_HINT_FUNC 1039 1039 " pushfl\n" 1040 1040 SAVE_REGS_STRING 1041 1041 " movl %esp, %eax\n" ··· 1050 1048 ".size __kretprobe_trampoline, .-__kretprobe_trampoline\n" 1051 1049 ); 1052 1050 NOKPROBE_SYMBOL(__kretprobe_trampoline); 1053 - STACK_FRAME_NON_STANDARD(__kretprobe_trampoline); 1054 - 1051 + /* 1052 + * __kretprobe_trampoline() skips updating frame pointer. The frame pointer 1053 + * saved in trampoline_handler() points to the real caller function's 1054 + * frame pointer. Thus the __kretprobe_trampoline() doesn't have a 1055 + * standard stack frame with CONFIG_FRAME_POINTER=y. 1056 + * Let's mark it non-standard function. Anyway, FP unwinder can correctly 1057 + * unwind without the hint. 1058 + */ 1059 + STACK_FRAME_NON_STANDARD_FP(__kretprobe_trampoline); 1055 1060 1056 1061 /* 1057 1062 * Called from __kretprobe_trampoline