perf bench: Fix NULL pointer dereference in "perf bench all"
PATCH 1/1 perf bench: Fix NULL pointer dereference in "perf bench all"
for_each_bench() must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over).
This fixes a NULL pointer dereference when running "perf bench all".
--- tools/perf/builtin-bench.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-bench.c +1 -1
@@ -76,7 +76,7 @@ static struct collection collections[] = {/* Iterate over all benchmarks within a collection: */ #define for_each_bench (coll, bench) \ - for (bench = coll->benchmarks; bench->name; bench++) + for (bench = coll->benchmarks; bench && bench->name; bench++)static void dump_benchmarks (struct collection *coll) {
Signature · 1 line
1.9.0
Em Wed, Mar 12, 2014 at 06:40:51PM -0400, Patrick Palka escreveu:
Quoted 6 lines
for_each_bench()must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over).This fixes a NULL pointer dereference when running "perf bench all".
Can you please mention against which tree you're fixing things? I just tried to reproduce it here on perf/urgent and this problem is not reproducible by simply running:
perf bench all
So now I'm going to try on perf/core, tip/master, etc :-\
- Arnaldo
Quoted 20 lines
Signed-off-by Patrick Palka <[email protected]>--- tools/perf/builtin-bench.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-bench.c +1
-1@@ -76,7 +76,7 @@ static struct collection collections[] = {/* Iterate over all benchmarks within a collection: */ #define for_each_bench (coll, bench) \ - for (bench = coll->benchmarks; bench->name; bench++) + for (bench = coll->benchmarks; bench && bench->name; bench++)static void dump_benchmarks (struct collection *coll) {Signature · 1 line
1.9.0
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 12, 2014 at 06:40:51PM -0400, Patrick Palka escreveu:
Quoted 6 lines
for_each_bench()must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over).This fixes a NULL pointer dereference when running "perf bench all".
Quoted 7 lines
Can you please mention against which tree you're fixing things? I just tried to reproduce it here on perf/urgent and this problem is not reproducible by simply running:
perf bench all
So now I'm going to try on perf/core, tip/master, etc :-\
I'm fixing this on top on Linus' tree, which is currently on ac9dc67b7.
Without the patch, the output of "./perf bench all" looks like:
# Running sched/messaging benchmark...
# 20 sender and receiver processes per group
# 10 groups == 400 processes run
Total time: 0.623 [sec]
# Running sched/pipe benchmark...
# Executed 1000000 pipe operations between two processes
Total time: 32.199 [sec]
32.199419 usecs/op
31056 ops/sec# Running mem/memcpy benchmark...
# Copying 1MB Bytes ...
1.247206 GB/Sec
1.268263 GB/Sec (with prefault)# Running mem/memset benchmark...
# Copying 1MB Bytes ...
1.429813 GB/Sec
8.418642 GB/Sec (with prefault)zsh: segmentation fault ./perf bench all
Patrick
Em Thu, Mar 13, 2014 at 10:47:58AM -0400, Patrick Palka escreveu:
Quoted 14 lines
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 12, 2014 at 06:40:51PM -0400, Patrick Palka escreveu:
Quoted 6 lines
for_each_bench()must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over).This fixes a NULL pointer dereference when running "perf bench all".
Can you please mention against which tree you're fixing things? I just tried to reproduce it here on perf/urgent and this problem is not reproducible by simply running:
Quoted 7 lines
Quoted 3 lines
perf bench all
So now I'm going to try on perf/core, tip/master, etc :-\
I'm fixing this on top on Linus' tree, which is currently on
ac9dc67b7.Without the patch, the output of "./perf bench all" looks like:
That helps, I didn't manage to reproduce it here, I think, because I have the numa libs installed and then a numa bench is included, and it seems broken, which stops 'perf bench all' before it hits this problem.
I'm fixing that problem and then will process your patch.
Please add the output, possibly trimmed if long, in your next changelog messages, that helps in more quickly seeing what is happening and comparing with results obtained elsewhere.
Thanks,
- Arnaldo
Quoted 30 lines
# Running sched/messaging benchmark...
# 20 sender and receiver processes per group
# 10 groups == 400 processes runTotal time: 0.623 [sec]# Running sched/pipe benchmark...
# Executed 1000000 pipe operations between two processesTotal time: 32.199 [sec] 32.199419 usecs/op 31056 ops/sec# Running mem/memcpy benchmark...
# Copying 1MB Bytes ...1.247206 GB/Sec 1.268263 GB/Sec (with prefault)# Running mem/memset benchmark...
# Copying 1MB Bytes ...1.429813 GB/Sec 8.418642 GB/Sec (with prefault)zsh: segmentation fault ./perf bench all
Patrick
tip-bot for Patrick Palka
merge bot[tip:perf/urgent] perf bench: Fix NULL pointer dereference in " perf bench all"
In reply to Patrick Palkaperf bench: Fix NULL pointer dereference in "perf bench all"
Commit-ID: 6eeefccdcfc2cc9697562e740bfe6c35fddd4e1c Gitweb: http://git.kernel.org/tip/6eeefccdcfc2cc9697562e740bfe6c35fddd4e1c Author: Patrick Palka <[email protected]> AuthorDate: Wed, 12 Mar 2014 18:40:51 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 14 Mar 2014 13:45:54 -0300
perf bench: Fix NULL pointer dereference in "perf bench all"
The for_each_bench() macro must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over).
This fixes this NULL pointer dereference when running "perf bench all":
[root@ssdandy ~]# perf bench all
<SNIP>
# Running mem/memset benchmark...
# Copying 1MB Bytes ...
2.453675 GB/Sec
12.056327 GB/Sec (with prefault) Segmentation fault (core dumped)
[root@ssdandy ~]#
--- tools/perf/builtin-bench.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-bench.c +1 -1
@@ -76,7 +76,7 @@ static struct collection collections[] = {/* Iterate over all benchmarks within a collection: */ #define for_each_bench (coll, bench) \ - for (bench = coll->benchmarks; bench->name; bench++) + for (bench = coll->benchmarks; bench && bench->name; bench++)static void dump_benchmarks (struct collection *coll) {