Skip to contentSkip to conversation

perf: fix for double free in tools/perf stat

PATCH Applied Yasser Shalabi 4 participants 4 messages Oct 4, 2014 – Oct 16, 2014 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: fix for double free in tools/perf stat

Fix for double free bug in tools/perf due to dangling thread_map pointer in perf_evlist struct. Code path excercised when perf stat -C switch is used but not set and is followed by another switch.
Example: perf stat -C -e.

---
 tools/perf/util/evlist.c |    1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +1 -0
index 814e954..09af633 100644
@@ -845,6 +845,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 
 out_delete_threads:
 	thread_map__delete(evlist->threads);
+	evlist->threads = 0;
 	return -1;
 }
 
Signature · 1 line
1.7.10.4
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Yasser,

Quoted 14 lines · Yasser Shalabi

Fix for double free bug in tools/perf due to dangling thread_map pointer in perf_evlist struct. Code path excercised when perf stat -C switch is used but not set and is followed by another switch.
Example: perf stat -C -e.

---
 tools/perf/util/evlist.c |    1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +0 -0
index 814e954..09af633 100644

tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 848

Quoted 4 lines
tools/perf/util/evlist.c +1 -0
@@ -845,6 +845,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 
 out_delete_threads:
 	thread_map__delete(evlist->threads);
+	evlist->threads = 0;

Nitpick - I think NULL is preferred rather than 0.

Other than that,

Thanks,
Namhyung

Quoted 2 lines
tools/perf/util/evlist.c +0 -0
 	return -1;
 }
maintainer Applied
#2 lore raw

Em Tue, Oct 07, 2014 at 05:15:41PM +0900, Namhyung Kim escreveu:

Quoted 18 lines

Hi Yasser,

Quoted 15 lines · Yasser Shalabi

Fix for double free bug in tools/perf due to dangling thread_map pointer in perf_evlist struct. Code path excercised when perf stat -C switch is used but not set and is followed by another switch.
Example: perf stat -C -e.

---
 tools/perf/util/evlist.c |    1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +0 -0
index 814e954..09af633 100644
@@ -845,6 +845,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 
Quoted 5 lines

tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 848

Quoted 3 lines
tools/perf/util/evlist.c +1 -0
 out_delete_threads:
 	thread_map__delete(evlist->threads);
+	evlist->threads = 0;

Nitpick - I think NULL is preferred rather than 0.

yeah, I fixed that.

Quoted 3 lines

Other than that,

Thanks, applied!

Quoted 6 lines

Thanks,
Namhyung

Quoted 2 lines
tools/perf/util/evlist.c +0 -0
 	return -1;
 }
#3 lore raw

[tip:perf/urgent] perf evlist: Fix for double free in tools/ perf stat

In reply to Yasser Shalabi
perf evlist: Fix for double free in tools/perf stat
Commit-ID:  b2e19a934a36b2b4affcde9c170c0f01afabe50a
Gitweb:     http://git.kernel.org/tip/b2e19a934a36b2b4affcde9c170c0f01afabe50a
Author:     Yasser Shalabi <[email protected]>
AuthorDate: Sat, 4 Oct 2014 11:37:57 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 15 Oct 2014 16:16:53 -0300

perf evlist: Fix for double free in tools/perf stat

Fix for double free bug in tools/perf due to dangling thread_map pointer in perf_evlist struct.

Code path excercised when perf stat -C switch is used but not set and is followed by another switch.

Example:

perf stat -C -e.

---
 tools/perf/util/evlist.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +1 -0
index b4b54d8..3c9e77d 100644
@@ -1003,6 +1003,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 
 out_delete_threads:
 	thread_map__delete(evlist->threads);
+	evlist->threads = NULL;
 	return -1;
 }