kprobes: fix trace_probe flags in enable_trace_kprobe
PATCH 1/1 kprobes: fix trace_probe flags in enable_trace_kprobe
If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe it returns an error, but does not unset the tp flags it set previosly. This results in a probe being considered enabled and failures like being unable to remove the probe through kprobe_events file since probes_open() expects every probe to be disabled.
--- kernel/trace/trace_kprobe.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/trace/trace_kprobe.c +11 -2
@@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { +struct event_file_link *link;int ret =0 ;if (file) { -struct event_file_link *link; - link =kmalloc (sizeof (*link),GFP_KERNEL );if (!link) { ret = -ENOMEM ;
@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)else ret =enable_kprobe (&tk->rp.kp); } + +if (ret) { +if (file) { +list_del (&link->list); +kfree (link); + tk->tp.flags &= ~TP_FLAG_TRACE ; + }else { + tk->tp.flags &= ~TP_FLAG_PROFILE ; + } + } out:return ret; }
Signature · 1 line
2.13.6
Steven Rostedt
maintainer[ Adding Masami to Cc ]
Quoted 6 lines · On Wed, 25 Jul 2018 12:28:26 +0200 Artem Savkov <[email protected]> wrote:
If
enable_trace_kprobefails to enable the probe in enable_k(ret)probe it returns an error, but does not unset the tp flags it set previosly. This results in a probe being considered enabled and failures like being unable to remove the probe throughkprobe_eventsfile sinceprobes_open()expects every probe to be disabled.
Looks good to me. Masami, want to ack it?
-- Steve
Quoted 39 lines
Signed-off-by Artem Savkov <[email protected]>--- kernel/trace/trace_kprobe.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)kernel/trace/trace_kprobe.c +11
-2@@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { +struct event_file_link *link;int ret =0 ;if (file) { -struct event_file_link *link; - link =kmalloc (sizeof (*link),GFP_KERNEL );if (!link) { ret = -ENOMEM ;@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)else ret =enable_kprobe (&tk->rp.kp); } + +if (ret) { +if (file) { +list_del (&link->list); +kfree (link); + tk->tp.flags &= ~TP_FLAG_TRACE ; + }else { + tk->tp.flags &= ~TP_FLAG_PROFILE ; + } + } out:return ret; }
Quoted 6 lines · On Wed, 25 Jul 2018 09:21:51 -0400 Steven Rostedt <[email protected]> wrote:
[ Adding Masami to Cc ]
On Wed, 25 Jul 2018 12:28:26 +0200
Artem Savkov <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
If
enable_trace_kprobefails to enable the probe in enable_k(ret)probe it returns an error, but does not unset the tp flags it set previosly. This results in a probe being considered enabled and failures like being unable to remove the probe throughkprobe_eventsfile sinceprobes_open()expects every probe to be disabled.Looks good to me. Masami, want to ack it?
Yes, looks good to me too.
Thanks Artem!
Quoted 43 lines
-- Steve
Quoted 39 lines
Signed-off-by Artem Savkov <[email protected]>--- kernel/trace/trace_kprobe.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)kernel/trace/trace_kprobe.c +11
-2@@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { +struct event_file_link *link;int ret =0 ;if (file) { -struct event_file_link *link; - link =kmalloc (sizeof (*link),GFP_KERNEL );if (!link) { ret = -ENOMEM ;@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)else ret =enable_kprobe (&tk->rp.kp); } + +if (ret) { +if (file) { +list_del (&link->list); +kfree (link); + tk->tp.flags &= ~TP_FLAG_TRACE ; + }else { + tk->tp.flags &= ~TP_FLAG_PROFILE ; + } + } out:return ret; }
Signature · 1 line
Masami Hiramatsu <[email protected]>
Quoted 2 lines · Artem Savkov
If
enable_trace_kprobefails to enable the probe in enable_k(ret)probe it returns an error, but does not unset the tp flags it set previosly.
"previously"
kernel/trace/trace_kprobe.c enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) · line 429
Quoted 8 lines
kernel/trace/trace_kprobe.c +4
-0@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)else ret =enable_kprobe (&tk->rp.kp); } + +if (ret) { +if (file) { +list_del (&link->list);
Should this be list_del_rcu(), since it was added to the list with list_add_tail_rcu()?
Signature · 1 line
Josh
Steven Rostedt
maintainerQuoted 5 lines · On Wed, 25 Jul 2018 08:56:32 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 2 lines · Artem Savkov
If
enable_trace_kprobefails to enable the probe in enable_k(ret)probe it returns an error, but does not unset the tp flags it set previosly."previously"
I tentatively added this to my queue. I updated the subject as:
tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure
But yeah, that needs to be fixed.
Quoted 13 lines
kernel/trace/trace_kprobe.c enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) · line 429
Quoted 9 lines
kernel/trace/trace_kprobe.c +4
-0@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)else ret =enable_kprobe (&tk->rp.kp); } + +if (ret) { +if (file) { +list_del (&link->list);Should this be
list_del_rcu(), since it was added to the list withlist_add_tail_rcu()?
Good catch. Yes, that should be list_del_rcu().
Artem,
Can you send a v2 with the changes.
Thanks,
-- Steve