* [PATCH] perf tools: Fix segfault in cpu_cache_level__read
@ 2019-09-12 10:52 Jiri Olsa
2019-09-20 18:20 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2019-09-12 10:52 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
Peter Zijlstra, Michael Petlan
We release wrong pointer on error path in
cpu_cache_level__read function, leading to
segfault:
(gdb) r record ls
Starting program: /root/perf/tools/perf/perf record ls
...
[ perf record: Woken up 1 times to write data ]
double free or corruption (out)
Thread 1 "perf" received signal SIGABRT, Aborted.
0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
(gdb) bt
#0 0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
#1 0x00007ffff7443bac in abort () from /lib64/power9/libc.so.6
#2 0x00007ffff74af8bc in __libc_message () from /lib64/power9/libc.so.6
#3 0x00007ffff74b92b8 in malloc_printerr () from /lib64/power9/libc.so.6
#4 0x00007ffff74bb874 in _int_free () from /lib64/power9/libc.so.6
#5 0x0000000010271260 in __zfree (ptr=0x7fffffffa0b0) at ../../lib/zalloc..
#6 0x0000000010139340 in cpu_cache_level__read (cache=0x7fffffffa090, cac..
#7 0x0000000010143c90 in build_caches (cntp=0x7fffffffa118, size=<optimiz..
...
Releasing the proper pointer.
Link: http://lkml.kernel.org/n/tip-e7js6xoi4y18kydxqehh0ihx@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
| 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b0c34dda30a0..3527b9897b6f 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1081,7 +1081,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path);
if (sysfs__read_str(file, &cache->map, &len)) {
- zfree(&cache->map);
+ zfree(&cache->size);
zfree(&cache->type);
return -1;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf tools: Fix segfault in cpu_cache_level__read
2019-09-12 10:52 [PATCH] perf tools: Fix segfault in cpu_cache_level__read Jiri Olsa
@ 2019-09-20 18:20 ` Arnaldo Carvalho de Melo
2019-09-20 18:44 ` Jiri Olsa
0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-09-20 18:20 UTC (permalink / raw)
To: Jiri Olsa
Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
Peter Zijlstra, Michael Petlan
Em Thu, Sep 12, 2019 at 12:52:35PM +0200, Jiri Olsa escreveu:
> We release wrong pointer on error path in
> cpu_cache_level__read function, leading to
> segfault:
>
> (gdb) r record ls
> Starting program: /root/perf/tools/perf/perf record ls
> ...
> [ perf record: Woken up 1 times to write data ]
> double free or corruption (out)
>
> Thread 1 "perf" received signal SIGABRT, Aborted.
> 0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
> (gdb) bt
> #0 0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
> #1 0x00007ffff7443bac in abort () from /lib64/power9/libc.so.6
> #2 0x00007ffff74af8bc in __libc_message () from /lib64/power9/libc.so.6
> #3 0x00007ffff74b92b8 in malloc_printerr () from /lib64/power9/libc.so.6
> #4 0x00007ffff74bb874 in _int_free () from /lib64/power9/libc.so.6
> #5 0x0000000010271260 in __zfree (ptr=0x7fffffffa0b0) at ../../lib/zalloc..
> #6 0x0000000010139340 in cpu_cache_level__read (cache=0x7fffffffa090, cac..
> #7 0x0000000010143c90 in build_caches (cntp=0x7fffffffa118, size=<optimiz..
> ...
>
> Releasing the proper pointer.
You forgot to add:
Fixes: 720e98b5faf1 ("perf tools: Add perf data cache feature")
Cc: stable@vger.kernel.org: # v4.6+
I did it, please consider doing it next time,
- Arnaldo
> Link: http://lkml.kernel.org/n/tip-e7js6xoi4y18kydxqehh0ihx@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/util/header.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index b0c34dda30a0..3527b9897b6f 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1081,7 +1081,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
>
> scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path);
> if (sysfs__read_str(file, &cache->map, &len)) {
> - zfree(&cache->map);
> + zfree(&cache->size);
> zfree(&cache->type);
> return -1;
> }
> --
> 2.21.0
--
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf tools: Fix segfault in cpu_cache_level__read
2019-09-20 18:20 ` Arnaldo Carvalho de Melo
@ 2019-09-20 18:44 ` Jiri Olsa
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2019-09-20 18:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
Peter Zijlstra, Michael Petlan
On Fri, Sep 20, 2019 at 03:20:26PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Sep 12, 2019 at 12:52:35PM +0200, Jiri Olsa escreveu:
> > We release wrong pointer on error path in
> > cpu_cache_level__read function, leading to
> > segfault:
> >
> > (gdb) r record ls
> > Starting program: /root/perf/tools/perf/perf record ls
> > ...
> > [ perf record: Woken up 1 times to write data ]
> > double free or corruption (out)
> >
> > Thread 1 "perf" received signal SIGABRT, Aborted.
> > 0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
> > (gdb) bt
> > #0 0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
> > #1 0x00007ffff7443bac in abort () from /lib64/power9/libc.so.6
> > #2 0x00007ffff74af8bc in __libc_message () from /lib64/power9/libc.so.6
> > #3 0x00007ffff74b92b8 in malloc_printerr () from /lib64/power9/libc.so.6
> > #4 0x00007ffff74bb874 in _int_free () from /lib64/power9/libc.so.6
> > #5 0x0000000010271260 in __zfree (ptr=0x7fffffffa0b0) at ../../lib/zalloc..
> > #6 0x0000000010139340 in cpu_cache_level__read (cache=0x7fffffffa090, cac..
> > #7 0x0000000010143c90 in build_caches (cntp=0x7fffffffa118, size=<optimiz..
> > ...
> >
> > Releasing the proper pointer.
>
> You forgot to add:
>
> Fixes: 720e98b5faf1 ("perf tools: Add perf data cache feature")
> Cc: stable@vger.kernel.org: # v4.6+
>
> I did it, please consider doing it next time,
will do, sry
jirka
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-20 18:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-12 10:52 [PATCH] perf tools: Fix segfault in cpu_cache_level__read Jiri Olsa
2019-09-20 18:20 ` Arnaldo Carvalho de Melo
2019-09-20 18:44 ` Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox