* [PATCH] x86/unwind: Recover the fgraph return address behind a rethook
@ 2026-11-25 21:09 Yifan Feng
0 siblings, 0 replies; only message in thread
From: Yifan Feng @ 2026-11-25 21:09 UTC (permalink / raw)
To: Josh Poimboeuf, Peter Zijlstra
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Steven Rostedt, Masami Hiramatsu,
linux-trace-kernel, linux-kernel, Yifan Feng
unwind_recover_ret_addr() asks ftrace_graph_ret_addr() and then
unwind_recover_rethook() for the original return address. That works
when the function graph tracer hooks the return of a function after a
kretprobe did: the stack has return_to_handler(), the shadow stack of
fgraph has arch_rethook_trampoline() and the rethook node has the
original address.
When the kretprobe hooks the return last, the stack has
arch_rethook_trampoline() and the rethook node has return_to_handler().
Nothing translates that address, so the stack trace ends there:
=> rw_verify_area
=> vfs_read
=> return_to_handler
This happens when the kretprobe is registered before the function_graph
tracer or an fprobe exit handler is enabled for the same function. It
also happens in the other order when the function is reached by a tail
call from a traced function, like ksys_read(): the rethook node then
has the return_to_handler() of the caller.
Translate the address found in the rethook node with
ftrace_graph_ret_addr(), and repeat while that gives the rethook
trampoline again. Do it in unwind_recover_rethook(), so that the
unwinding from pt_regs gets it, too.
Fixes: 19138af1bd88 ("x86/unwind: Recover kretprobe trampoline entry")
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
---
QEMU: function_graph, fprobe exit and kretprobes on vfs_read()/ksys_read() in 6 orders, stacktrace trigger in rw_verify_area(): complete in 0 of 6 before, 6 of 6 after. kprobes kunit and ftrace selftests (kprobe, dynevent, ftrace) give the same results.
Found and written with the help of an AI coding assistant.
arch/x86/include/asm/unwind.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/unwind.h b/arch/x86/include/asm/unwind.h
index 7cede4dc21f0..7ded718a8d6b 100644
--- a/arch/x86/include/asm/unwind.h
+++ b/arch/x86/include/asm/unwind.h
@@ -108,9 +108,16 @@ unsigned long unwind_recover_rethook(struct unwind_state *state,
unsigned long addr, unsigned long *addr_p)
{
#ifdef CONFIG_RETHOOK
- if (is_rethook_trampoline(addr))
- return rethook_find_ret_addr(state->task, (unsigned long)addr_p,
+ /*
+ * The rethook and the hook of ftrace_graph can sit on top of each
+ * other in any order, and more than once after a tail call.
+ */
+ while (is_rethook_trampoline(addr)) {
+ addr = rethook_find_ret_addr(state->task, (unsigned long)addr_p,
&state->kr_cur);
+ addr = ftrace_graph_ret_addr(state->task, &state->graph_idx,
+ addr, addr_p);
+ }
#endif
return addr;
}
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.39.3 (Apple Git-146)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 21:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 21:09 [PATCH] x86/unwind: Recover the fgraph return address behind a rethook Yifan Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®