tracing/kprobes: Check whether get_kretprobe() returns NULL in kretprobe_dispatcher()
Subsystems (3)
Masami Hiramatsu (Google)
maintainerPATCH 1/1 tracing/kprobes: Check whether get_kretprobe() returns NULL in kretprobe_dispatcher()
From: Masami Hiramatsu (Google) <[email protected]>
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 d741bf41d7c7 ("kprobes: Remove kretprobe hash"). Before that commit, the struct kretprob_instance::rp directly points the kretprobe and it is never be NULL.
--- kernel/trace/trace_kprobe.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/trace/trace_kprobe.c +10 -1
@@ -1718,8 +1718,17 @@ static int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) { struct kretprobe *rp = get_kretprobe(ri); - struct trace_kprobe *tk = container_of(rp, struct trace_kprobe, rp); +struct trace_kprobe *tk; + +/* +* There is a small chance that get_kretprobe(ri) returns NULL when +* the kretprobe is unregister on another CPU between kretprobe's +* trampoline_handler and this function. +*/ +if (unlikely (!rp)) +return 0 ; + tk = container_of(rp, struct trace_kprobe, rp);raw_cpu_inc (*tk->nhit);if (trace_probe_test_flag (&tk->tp,TP_FLAG_TRACE ))
Quoted 20 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
There is a small chance that
get_kretprobe(ri)returns NULL inkretprobe_dispatcher()when another CPU unregisters the kretprobe right after__kretprobe_trampoline_handler().To avoid this issue,
kretprobe_dispatcher()checks theget_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_instanceby commitd741bf41d7c7("kprobes: Remove kretprobe hash"). Before that commit, the structkretprob_instance::rpdirectly points the kretprobe and it is never be NULL.
Quoted 4 lines
Reported-by Yonghong Song <[email protected]>Fixes d741bf41d7c7 ("kprobes: Remove kretprobe hash")Signed-off-by Masami Hiramatsu (Google) <[email protected]>
[...]
Daniel Borkmann
maintainerQuoted 16 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
There is a small chance that
get_kretprobe(ri)returns NULL inkretprobe_dispatcher()when another CPU unregisters the kretprobe right after__kretprobe_trampoline_handler().To avoid this issue,
kretprobe_dispatcher()checks theget_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_instanceby commitd741bf41d7c7("kprobes: Remove kretprobe hash"). Before that commit, the structkretprob_instance::rpdirectly points the kretprobe and it is never be NULL.
Quoted 4 lines
Reported-by Yonghong Song <[email protected]>Fixes d741bf41d7c7 ("kprobes: Remove kretprobe hash")Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Steven, I presume you'll pick this fix up?
Thanks,
Daniel
Steven Rostedt
maintainerQuoted 17 lines · Daniel Borkmann
Quoted 16 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
There is a small chance that
get_kretprobe(ri)returns NULL inkretprobe_dispatcher()when another CPU unregisters the kretprobe right after__kretprobe_trampoline_handler().To avoid this issue,
kretprobe_dispatcher()checks theget_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_instanceby commitd741bf41d7c7("kprobes: Remove kretprobe hash"). Before that commit, the structkretprob_instance::rpdirectly points the kretprobe and it is never be NULL.
Quoted 6 lines
Quoted 4 lines
Reported-by Yonghong Song <[email protected]>Fixes d741bf41d7c7 ("kprobes: Remove kretprobe hash")Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
-- Steve
Quoted 3 lines
Thanks,
Daniel
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity and top posting.
Daniel Borkmann
maintainerQuoted 18 lines · Steven Rostedt
Quoted 17 lines · Daniel Borkmann
Quoted 16 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
There is a small chance that
get_kretprobe(ri)returns NULL inkretprobe_dispatcher()when another CPU unregisters the kretprobe right after__kretprobe_trampoline_handler().To avoid this issue,
kretprobe_dispatcher()checks theget_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_instanceby commitd741bf41d7c7("kprobes: Remove kretprobe hash"). Before that commit, the structkretprob_instance::rpdirectly points the kretprobe and it is never be NULL.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Reported-by Yonghong Song <[email protected]>Fixes d741bf41d7c7 ("kprobes: Remove kretprobe hash")Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
Ok, thanks. If I don't hear back I presume you'll pick it up then.
Steven Rostedt
maintainerQuoted 7 lines · On Wed, 8 Jun 2022 14:38:39 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
Ok, thanks. If I don't hear back I presume you'll pick it up then.
Yeah, I'm way behind due to the conference. And I'll be on PTO from tomorrow and back on Tuesday. And registration for Linux Plumbers is supposed to open today (but of course there's issues with that!), thus, I'm really have too much on my plate today :-p
-- Steve
Quoted 8 lines · Steven Rostedt
Quoted 4 lines · On Wed, 8 Jun 2022 14:38:39 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
Ok, thanks. If I don't hear back I presume you'll pick it up then.
Yeah, I'm way behind due to the conference. And I'll be on PTO from tomorrow and back on Tuesday. And registration for Linux Plumbers is supposed to open today (but of course there's issues with that!), thus, I'm really have too much on my plate today :-p
Steven,
you missed Davem's presentation at KR about importance of delegation. You need watch it:
https://youtu.be/ELPENQrtUas?t=9085
Steven Rostedt
maintainerQuoted 3 lines · On Wed, 8 Jun 2022 06:57:00 -0700 Alexei Starovoitov…
you missed Davem's presentation at KR about importance of delegation. You need watch it:
https://youtu.be/ELPENQrtUas?t=9085
It's on my TODO list.
-- Steve
Daniel Borkmann
maintainerQuoted 7 lines · Steven Rostedt
Quoted 4 lines · On Wed, 8 Jun 2022 14:38:39 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
Ok, thanks. If I don't hear back I presume you'll pick it up then.
Yeah, I'm way behind due to the conference. And I'll be on PTO from tomorrow and back on Tuesday. And registration for Linux Plumbers is supposed to open today (but of course there's issues with that!), thus, I'm really have too much on my plate today :-p
Steven, we still have this in our patchwork for tracking so it doesn't fall off the radar. The patch is 3 weeks old by now. Has this been picked up yet, or do you want to Ack and we ship the fix via bpf tree? Just asking as I didn't see any further updates ever since.
Thanks,
Daniel
Daniel Borkmann
maintainerQuoted 17 lines · Daniel Borkmann
Quoted 7 lines · Steven Rostedt
Quoted 4 lines · On Wed, 8 Jun 2022 14:38:39 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Masami Hiramatsu (Google) <[email protected]>Steven, I presume you'll pick this fix up?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'm currently at Embedded/Kernel Recipes, but yeah, I'll take a look at it. (Just need to finish my slides first ;-)
Ok, thanks. If I don't hear back I presume you'll pick it up then.
Yeah, I'm way behind due to the conference. And I'll be on PTO from tomorrow and back on Tuesday. And registration for Linux Plumbers is supposed to open today (but of course there's issues with that!), thus, I'm really have too much on my plate today :-p
Quoted 4 lines
Steven, we still have this in our patchwork for tracking so it doesn't fall off the radar. The patch is 3 weeks old by now. Has this been picked up yet, or do you want to Ack and we ship the fix via bpf tree? Just asking as I didn't see any further updates ever since.
Same goes for these two fixes waiting for Ack:
https://lore.kernel.org/bpf/165461825202.280167.12903689442217921817.stgit@devnote2/
Thanks,
Daniel
Steven Rostedt
maintainerQuoted 4 lines · On Fri, 17 Jun 2022 10:26:40 +0200 Daniel Borkmann <[email protected]> wrote:
Steven, we still have this in our patchwork for tracking so it doesn't fall off the radar. The patch is 3 weeks old by now. Has this been picked up yet, or do you want to Ack and we ship the fix via bpf tree? Just asking as I didn't see any further updates ever since.
Sorry, between traveling for conferences and PTO I fell behind. I'll pull this into my urgent queue and start running my tests on it.
-- Steve
Daniel Borkmann
maintainerQuoted 10 lines · Steven Rostedt
Quoted 4 lines · On Fri, 17 Jun 2022 10:26:40 +0200 Daniel Borkmann <[email protected]> wrote:
Steven, we still have this in our patchwork for tracking so it doesn't fall off the radar. The patch is 3 weeks old by now. Has this been picked up yet, or do you want to Ack and we ship the fix via bpf tree? Just asking as I didn't see any further updates ever since.
Sorry, between traveling for conferences and PTO I fell behind. I'll pull this into my urgent queue and start running my tests on it.
Okay, if you pick these fixes up today then I'll toss them from our bpf patchwork.
Steven Rostedt
maintainerQuoted 4 lines · On Fri, 17 Jun 2022 18:09:44 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 2 lines
Sorry, between traveling for conferences and PTO I fell behind. I'll pull this into my urgent queue and start running my tests on it.
Okay, if you pick these fixes up today then I'll toss them from our bpf patchwork.
This patch I'll take, but please keep the fprobe/rethook one, as that's specific to your tree.
-- Steve
Daniel Borkmann
maintainerQuoted 10 lines · Steven Rostedt
Quoted 4 lines · On Fri, 17 Jun 2022 18:09:44 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 2 lines
Sorry, between traveling for conferences and PTO I fell behind. I'll pull this into my urgent queue and start running my tests on it.
Okay, if you pick these fixes up today then I'll toss them from our bpf patchwork.
This patch I'll take, but please keep the fprobe/rethook one, as that's specific to your tree.
Ok, sounds good to me. I just applied them with the comment suggestion added.
Quoted 16 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
There is a small chance that
get_kretprobe(ri)returns NULL inkretprobe_dispatcher()when another CPU unregisters the kretprobe right after__kretprobe_trampoline_handler().To avoid this issue,
kretprobe_dispatcher()checks theget_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_instanceby commitd741bf41d7c7("kprobes: Remove kretprobe hash"). Before that commit, the structkretprob_instance::rpdirectly points the kretprobe and it is never be NULL.
Quoted 4 lines
Reported-by Yonghong Song <[email protected]>Fixes d741bf41d7c7 ("kprobes: Remove kretprobe hash")Signed-off-by Masami Hiramatsu (Google) <[email protected]>
jirka
Quoted 28 lines
--- kernel/trace/trace_kprobe.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)kernel/trace/trace_kprobe.c +10
-1@@ -1718,8 +1718,17 @@ static int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) { struct kretprobe *rp = get_kretprobe(ri); - struct trace_kprobe *tk = container_of(rp, struct trace_kprobe, rp); +struct trace_kprobe *tk; + +/* +* There is a small chance that get_kretprobe(ri) returns NULL when +* the kretprobe is unregister on another CPU between kretprobe's +* trampoline_handler and this function. +*/ +if (unlikely (!rp)) +return 0 ; + tk = container_of(rp, struct trace_kprobe, rp);raw_cpu_inc (*tk->nhit);if (trace_probe_test_flag (&tk->tp,TP_FLAG_TRACE ))