Skip to content

Commit cc72b72

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobes: Check whether get_kretprobe() returns NULL in kretprobe_dispatcher()
There is a small chance that get_kretprobe(ri) returns NULL in kretprobe_dispatcher() when another CPU unregisters the kretprobe right after __kretprobe_trampoline_handler(). To avoid this issue, kretprobe_dispatcher() checks the get_kretprobe() return value again. And if it is NULL, it returns soon because that kretprobe is under unregistering process. This issue has been introduced when the kretprobe is decoupled from the struct kretprobe_instance by commit d741bf4 ("kprobes: Remove kretprobe hash"). Before that commit, the struct kretprob_instance::rp directly points the kretprobe and it is never be NULL. Link: https://lkml.kernel.org/r/165366693881.797669.16926184644089588731.stgit@devnote2 Reported-by: Yonghong Song <[email protected]> Fixes: d741bf4 ("kprobes: Remove kretprobe hash") Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: bpf <[email protected]> Cc: Kernel Team <[email protected]> Cc: [email protected] Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Acked-by: Jiri Olsa <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b13bacc commit cc72b72

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,17 @@ static int
17181718
kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
17191719
{
17201720
struct kretprobe *rp = get_kretprobe(ri);
1721-
struct trace_kprobe *tk = container_of(rp, struct trace_kprobe, rp);
1721+
struct trace_kprobe *tk;
1722+
1723+
/*
1724+
* There is a small chance that get_kretprobe(ri) returns NULL when
1725+
* the kretprobe is unregister on another CPU between kretprobe's
1726+
* trampoline_handler and this function.
1727+
*/
1728+
if (unlikely(!rp))
1729+
return 0;
17221730

1731+
tk = container_of(rp, struct trace_kprobe, rp);
17231732
raw_cpu_inc(*tk->nhit);
17241733

17251734
if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))

0 commit comments

Comments
 (0)