Skip to contentSkip to conversation

tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure

PATCH In review Artem Savkov 4 participants 6 messages Jul 25, 2018 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure

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 previously. 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
index 21f718472942..27ace4513c43 100644
@@ -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_rcu(&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
maintainer
#1 lore raw
Quoted 7 lines · On Wed, 25 Jul 2018 16:20:38 +0200 Artem Savkov <[email protected]> wrote:

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 previously. 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.

Masami,

Can you ack this?

Thanks!

-- Steve

Quoted 38 lines
---
 kernel/trace/trace_kprobe.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/trace/trace_kprobe.c +11 -2
index 21f718472942..27ace4513c43 100644
@@ -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_rcu(&link->list);
+			kfree(link);
+			tk->tp.flags &= ~TP_FLAG_TRACE;
+		} else {
+			tk->tp.flags &= ~TP_FLAG_PROFILE;
+		}
+	}
  out:
 	return ret;
 }
Reviewed-by on v2 1/1
#2 lore raw
In reply to Artem Savkov
Quoted 7 lines · Artem Savkov

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 previously. 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.

Signature · 1 line
Josh
maintainer
#3 lore raw
Quoted 11 lines · On Wed, 25 Jul 2018 10:35:57 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 7 lines · Artem Savkov

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 previously. 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.

Thanks Josh!

Queued up and currently being tested.

-- Steve

maintainer Acked-by on v2 1/1
#4 lore raw
In reply to Artem Savkov
Quoted 6 lines · On Wed, 25 Jul 2018 16:20:38 +0200 Artem Savkov <[email protected]> wrote:

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 previously. 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.

Looks good to me.

Thanks!

Quoted 42 lines
---
 kernel/trace/trace_kprobe.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/trace/trace_kprobe.c +11 -2
index 21f718472942..27ace4513c43 100644
@@ -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_rcu(&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
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#5 lore raw
Quoted 10 lines · On Thu, 26 Jul 2018 00:41:13 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 6 lines · On Wed, 25 Jul 2018 16:20:38 +0200 Artem Savkov <[email protected]> wrote:

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 previously. 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.

Quoted 3 lines

Looks good to me.

Thanks Masami,

-- Steve