Skip to contentSkip to conversation

perf probe: Fix a segfault when removing uprobe events

PATCH Applied Masami Hiramatsu 4 participants 7 messages Sep 16, 2015 – Sep 23, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf probe: Fix a segfault when removing uprobe events

Fix a segfault bug and a small mistake in perf probe -d.

Since the "ulist" in perf_del_probe_events is never initialized, strlist__add(ulist, *) always causes a segfault when removing uprobe events by perf probe -d.

Also, the "str" local variable is never released if fail to allocate the "klist". This fixes it too.

This has been introduced by the commit e607f1426b58 ("perf probe:
Print deleted events in cmd_probe()").

---
 tools/perf/builtin-probe.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +5 -2
index 94385ee..f7882ae 100644
@@ -380,8 +380,11 @@ static int perf_del_probe_events(struct strfilter *filter)
 		goto out;
 
 	klist = strlist__new(NULL, NULL);
-	if (!klist)
-		return -ENOMEM;
+	ulist = strlist__new(NULL, NULL);
+	if (!klist || !ulist) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	ret = probe_file__get_events(kfd, filter, klist);
 	if (ret == 0) {
#1 lore raw

Hi Arnaldo,

Could you pull this bugfix as an urgent patch, since this fixes a critical problem?

Thanks,

From: Masami Hiramatsu [mailto:[email protected]]

Quoted 38 lines

Fix a segfault bug and a small mistake in perf probe -d.

Since the "ulist" in perf_del_probe_events is never initialized, strlist__add(ulist, *) always causes a segfault when removing uprobe events by perf probe -d.

Also, the "str" local variable is never released if fail to allocate the "klist". This fixes it too.

This has been introduced by the commit e607f1426b58 ("perf probe:
Print deleted events in cmd_probe()").

---
tools/perf/builtin-probe.c | 7 +++++--

1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +5 -2
index 94385ee..f7882ae 100644
@@ -380,8 +380,11 @@ static int perf_del_probe_events(struct strfilter *filter)
 		goto out;
 
 	klist = strlist__new(NULL, NULL);
-	if (!klist)
-		return -ENOMEM;
+	ulist = strlist__new(NULL, NULL);
+	if (!klist || !ulist) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	ret = probe_file__get_events(kfd, filter, klist);
 	if (ret == 0) {
#2 lore raw

Em Fri, Sep 18, 2015 at 01:39:13AM +0000, 平松雅巳 / HIRAMATU,MASAMI escreveu:

Quoted 4 lines

Hi Arnaldo,

Could you pull this bugfix as an urgent patch, since this fixes a critical problem?

Sure, thanks for the reminder.

- Arnaldo

Quoted 42 lines

Thanks,

From: Masami Hiramatsu [mailto:[email protected]]

Quoted 38 lines

Fix a segfault bug and a small mistake in perf probe -d.

Since the "ulist" in perf_del_probe_events is never initialized, strlist__add(ulist, *) always causes a segfault when removing uprobe events by perf probe -d.

Also, the "str" local variable is never released if fail to allocate the "klist". This fixes it too.

This has been introduced by the commit e607f1426b58 ("perf probe:
Print deleted events in cmd_probe()").

---
tools/perf/builtin-probe.c | 7 +++++--

1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +5 -2
index 94385ee..f7882ae 100644
@@ -380,8 +380,11 @@ static int perf_del_probe_events(struct strfilter *filter)
 		goto out;
 
 	klist = strlist__new(NULL, NULL);
-	if (!klist)
-		return -ENOMEM;
+	ulist = strlist__new(NULL, NULL);
+	if (!klist || !ulist) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	ret = probe_file__get_events(kfd, filter, klist);
 	if (ret == 0) {
#3 lore raw

Em Fri, Sep 18, 2015 at 11:26:22AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 7 lines

Em Fri, Sep 18, 2015 at 01:39:13AM +0000, 平松雅巳 / HIRAMATU,MASAMI escreveu:

Quoted 4 lines

Hi Arnaldo,

Could you pull this bugfix as an urgent patch, since this fixes a critical problem?

Sure, thanks for the reminder.

But it is not applying, checking:

[acme@zoo linux]$ patch -p1 < /wb/1.patch
patching file tools/perf/builtin-probe.c
Hunk #1 FAILED at 380.
1 out of 1 hunk FAILED -- saving rejects to file tools/perf/builtin-probe.c.rej [acme@zoo linux]$

- Arnaldo

maintainer Applied
#4 lore raw

Em Fri, Sep 18, 2015 at 11:28:30AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 7 lines

Em Fri, Sep 18, 2015 at 11:26:22AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 5 lines

Em Fri, Sep 18, 2015 at 01:39:13AM +0000, 平松雅巳 / HIRAMATU,MASAMI escreveu:

Quoted 2 lines

Could you pull this bugfix as an urgent patch, since this fixes a critical problem?

Sure, thanks for the reminder.

Quoted 7 lines

But it is not applying, checking:

[acme@zoo linux]$ patch -p1 < /wb/1.patch
patching file tools/perf/builtin-probe.c
Hunk #1 FAILED at 380.
1 out of 1 hunk FAILED -- saving rejects to file tools/perf/builtin-probe.c.rej [acme@zoo linux]$

The way you reported made me somehow think this was for perf/urgent, but the function it patches is not even there, ok, applying to perf/core.

Applied.

- Arnaldo

#5 lore raw
In reply to Masami Hiramatsu
Quoted 23 lines · Masami Hiramatsu

Fix a segfault bug and a small mistake in perf probe -d.

Since the "ulist" in perf_del_probe_events is never initialized, strlist__add(ulist, *) always causes a segfault when removing uprobe events by perf probe -d.

Also, the "str" local variable is never released if fail to allocate the "klist". This fixes it too.

This has been introduced by the commit e607f1426b58 ("perf probe:
Print deleted events in cmd_probe()").

---
  tools/perf/builtin-probe.c |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +0 -0
index 94385ee..f7882ae 100644

tools/perf/builtin-probe.c static int perf_del_probe_events(struct strfilter *filter) · line 387

Quoted 10 lines
tools/perf/builtin-probe.c +5 -2
@@ -380,8 +380,11 @@ static int perf_del_probe_events(struct strfilter *filter)
  		goto out;
 
  	klist = strlist__new(NULL, NULL);
-	if (!klist)
-		return -ENOMEM;
+	ulist = strlist__new(NULL, NULL);
+	if (!klist || !ulist) {
+		ret = -ENOMEM;
+		goto out;
+	}

Newbie here, but if one of "strlist__new()" calls succeeds, don't you need a corresponding strlist__delete() ?

PC

#6 lore raw
In reply to Masami Hiramatsu
perf probe: Fix a segfault when removing uprobe events
Commit-ID:  0fb18553478dee5b3d8dc0af4f99a5288e81142f
Gitweb:     http://git.kernel.org/tip/0fb18553478dee5b3d8dc0af4f99a5288e81142f
Author:     Masami Hiramatsu <[email protected]>
AuthorDate: Wed, 16 Sep 2015 21:52:42 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Sep 2015 18:01:17 -0300

perf probe: Fix a segfault when removing uprobe events

Fix a segfault bug and a small mistake in perf probe -d.

Since the "ulist" in perf_del_probe_events is never initialized, strlist__add(ulist, *) always causes a segfault when removing uprobe events by perf probe -d.

Also, the "str" local variable is never released if fail to allocate the "klist". This fixes it too.

This has been introduced by the commit e607f1426b58 ("perf probe:
Print deleted events in cmd_probe()").

---
 tools/perf/builtin-probe.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-probe.c +5 -2
index 94385ee..f7882ae 100644
@@ -380,8 +380,11 @@ static int perf_del_probe_events(struct strfilter *filter)
 		goto out;
 
 	klist = strlist__new(NULL, NULL);
-	if (!klist)
-		return -ENOMEM;
+	ulist = strlist__new(NULL, NULL);
+	if (!klist || !ulist) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	ret = probe_file__get_events(kfd, filter, klist);
 	if (ret == 0) {