* [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address.
@ 2023-07-19 20:29 Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim, Ian Rogers
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Adrian Hunter,
Clark Williams, Kate Carcia, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo, John Garry
Hi,
Please review/ack, I put it as well on the tmp.perf-tools-next
in the perf-tools-next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=tmp.perf-tools-next
Best regards,
- Arnaldo
Arnaldo Carvalho de Melo (6):
perf evsel: Free evsel->filter on the destructor
perf thread: Allow tools to register a thread->priv destructor
perf trace: Register a thread priv destructor
perf trace: Really free the evsel->priv area
perf trace: Free thread_trace->files table
MAINTAINERS: Add git information for perf-tools and perf-tools-next
trees/branches
MAINTAINERS | 2 ++
tools/perf/builtin-trace.c | 38 +++++++++++++++++++++++++++++++-------
tools/perf/util/evsel.c | 1 +
tools/perf/util/thread.c | 11 +++++++++++
tools/perf/util/thread.h | 2 ++
5 files changed, 47 insertions(+), 7 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/6] perf evsel: Free evsel->filter on the destructor
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Noticed with:
make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin
Direct leak of 45 byte(s) in 1 object(s) allocated from:
#0 0x7f213f87243b in strdup (/lib64/libasan.so.8+0x7243b)
#1 0x63d15f in evsel__set_filter util/evsel.c:1371
#2 0x63d15f in evsel__append_filter util/evsel.c:1387
#3 0x63d15f in evsel__append_tp_filter util/evsel.c:1400
#4 0x62cd52 in evlist__append_tp_filter util/evlist.c:1145
#5 0x62cd52 in evlist__append_tp_filter_pids util/evlist.c:1196
#6 0x541e49 in trace__set_filter_loop_pids /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3646
#7 0x541e49 in trace__set_filter_pids /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3670
#8 0x541e49 in trace__run /home/acme/git/perf-tools/tools/perf/builtin-trace.c:3970
#9 0x541e49 in cmd_trace /home/acme/git/perf-tools/tools/perf/builtin-trace.c:5141
#10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools/tools/perf/perf.c:323
#11 0x4196da in handle_internal_command /home/acme/git/perf-tools/tools/perf/perf.c:377
#12 0x4196da in run_argv /home/acme/git/perf-tools/tools/perf/perf.c:421
#13 0x4196da in main /home/acme/git/perf-tools/tools/perf/perf.c:537
#14 0x7f213e84a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Free it on evsel__exit().
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/evsel.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 762e2b2634a5532a..e41bc4d9925f69a4 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1474,6 +1474,7 @@ void evsel__exit(struct evsel *evsel)
perf_thread_map__put(evsel->core.threads);
zfree(&evsel->group_name);
zfree(&evsel->name);
+ zfree(&evsel->filter);
zfree(&evsel->pmu_name);
zfree(&evsel->group_pmu_name);
zfree(&evsel->unit);
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 22:31 ` Ian Rogers
2023-07-19 20:29 ` [PATCH 3/6] perf trace: Register a thread priv destructor Arnaldo Carvalho de Melo
` (4 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
So that when thread__delete() runs it can be called and free stuff tools
stashed into thread->priv, like 'perf trace' does and will use this
new facility to plug some leaks.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/thread.c | 11 +++++++++++
tools/perf/util/thread.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0b166404c5c365cf..35dd4e716e411da9 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid)
return NULL;
}
+static void (*thread__priv_destructor)(void *priv);
+
+void thread__set_priv_destructor(void (*destructor)(void *priv))
+{
+ thread__priv_destructor = destructor;
+}
+
void thread__delete(struct thread *thread)
{
struct namespaces *namespaces, *tmp_namespaces;
@@ -112,6 +119,10 @@ void thread__delete(struct thread *thread)
exit_rwsem(thread__namespaces_lock(thread));
exit_rwsem(thread__comm_lock(thread));
thread__free_stitch_list(thread);
+
+ if (thread__priv_destructor)
+ thread__priv_destructor(thread__priv(thread));
+
RC_CHK_FREE(thread);
}
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 9068a21ce0fa1b0f..e79225a0ea46b789 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid);
int thread__init_maps(struct thread *thread, struct machine *machine);
void thread__delete(struct thread *thread);
+void thread__set_priv_destructor(void (*destructor)(void *priv));
+
struct thread *thread__get(struct thread *thread);
void thread__put(struct thread *thread);
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/6] perf trace: Register a thread priv destructor
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 4/6] perf trace: Really free the evsel->priv area Arnaldo Carvalho de Melo
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
To plug these leaks detected with:
$ make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin
=================================================================
==473890==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 112 byte(s) in 1 object(s) allocated from:
#0 0x7fdf19aba097 in calloc (/lib64/libasan.so.8+0xba097)
#1 0x987836 in zalloc (/home/acme/bin/perf+0x987836)
#2 0x5367ae in thread_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1289
#3 0x5367ae in thread__trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1307
#4 0x5367ae in trace__sys_exit /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2468
#5 0x52bf34 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3177
#6 0x52bf34 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3685
#7 0x542927 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3712
#8 0x542927 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4055
#9 0x542927 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5141
#10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
#11 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
#12 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
#13 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
#14 0x7fdf18a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Direct leak of 2048 byte(s) in 1 object(s) allocated from:
#0 0x7f788fcba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
#1 0x5337c0 in trace__sys_enter /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2342
#2 0x52bfb4 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3191
#3 0x52bfb4 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3699
#4 0x542883 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3726
#5 0x542883 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4069
#6 0x542883 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5155
#7 0x5ef232 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
#8 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
#9 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
#10 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
#11 0x7f788ec4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Indirect leak of 48 byte(s) in 1 object(s) allocated from:
#0 0x7fdf19aba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
#1 0x77b335 in intlist__new util/intlist.c:116
#2 0x5367fd in thread_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1293
#3 0x5367fd in thread__trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:1307
#4 0x5367fd in trace__sys_exit /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:2468
#5 0x52bf34 in trace__handle_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3177
#6 0x52bf34 in __trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3685
#7 0x542927 in trace__deliver_event /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3712
#8 0x542927 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:4055
#9 0x542927 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5141
#10 0x5ef1a2 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
#11 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
#12 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
#13 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
#14 0x7fdf18a4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6e73d0e957152d84..b7cbe4bcd136b137 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1296,6 +1296,19 @@ static struct thread_trace *thread_trace__new(void)
return ttrace;
}
+static void thread_trace__delete(void *pttrace)
+{
+ struct thread_trace *ttrace = pttrace;
+
+ if (!ttrace)
+ return;
+
+ intlist__delete(ttrace->syscall_stats);
+ ttrace->syscall_stats = NULL;
+ zfree(&ttrace->entry_str);
+ free(ttrace);
+}
+
static struct thread_trace *thread__trace(struct thread *thread, FILE *fp)
{
struct thread_trace *ttrace;
@@ -1635,6 +1648,8 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist)
if (trace->host == NULL)
return -ENOMEM;
+ thread__set_priv_destructor(thread_trace__delete);
+
err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr);
if (err < 0)
goto out;
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/6] perf trace: Really free the evsel->priv area
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2023-07-19 20:29 ` [PATCH 3/6] perf trace: Register a thread priv destructor Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 5/6] perf trace: Free thread_trace->files table Arnaldo Carvalho de Melo
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo, Riccardo Mancini
From: Arnaldo Carvalho de Melo <acme@redhat.com>
In 3cb4d5e00e037c70 ("perf trace: Free syscall tp fields in
evsel->priv") it only was freeing if strcmp(evsel->tp_format->system,
"syscalls") returned zero, while the corresponding initialization of
evsel->priv was being performed if it was _not_ zero, i.e. if the tp
system wasn't 'syscalls'.
Just stop looking for that and free it if evsel->priv was set, which
should be equivalent.
Also use the pre-existing evsel_trace__delete() function.
This resolves these leaks, detected with:
$ make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin
=================================================================
==481565==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097)
#1 0x987966 in zalloc (/home/acme/bin/perf+0x987966)
#2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307
#3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333
#4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458
#5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480
#6 0x540e8b in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3212
#7 0x540e8b in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891
#8 0x540e8b in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156
#9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
#10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
#11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
#12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
#13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097)
#1 0x987966 in zalloc (/home/acme/bin/perf+0x987966)
#2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307
#3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333
#4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458
#5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480
#6 0x540dd1 in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3205
#7 0x540dd1 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891
#8 0x540dd1 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156
#9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
#10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
#11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
#12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
#13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).
[root@quaco ~]#
With this we plug all leaks with "perf trace sleep 1".
Fixes: 3cb4d5e00e037c70 ("perf trace: Free syscall tp fields in evsel->priv")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b7cbe4bcd136b137..56651d666480cc16 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3151,13 +3151,8 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist)
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
- struct evsel_trace *et = evsel->priv;
-
- if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls"))
- continue;
-
- zfree(&et->fmt);
- free(et);
+ evsel_trace__delete(evsel->priv);
+ evsel->priv = NULL;
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/6] perf trace: Free thread_trace->files table
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2023-07-19 20:29 ` [PATCH 4/6] perf trace: Really free the evsel->priv area Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Arnaldo Carvalho de Melo
2023-07-19 22:34 ` [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Ian Rogers
6 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The fd->pathname table that is kept in 'struct thread_trace' and thus in
thread->priv must be freed when a thread is deleted.
This was also detected using -fsanitize=address.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 56651d666480cc16..7ece2521efb69182 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1296,6 +1296,8 @@ static struct thread_trace *thread_trace__new(void)
return ttrace;
}
+static void thread_trace__free_files(struct thread_trace *ttrace);
+
static void thread_trace__delete(void *pttrace)
{
struct thread_trace *ttrace = pttrace;
@@ -1305,6 +1307,7 @@ static void thread_trace__delete(void *pttrace)
intlist__delete(ttrace->syscall_stats);
ttrace->syscall_stats = NULL;
+ thread_trace__free_files(ttrace);
zfree(&ttrace->entry_str);
free(ttrace);
}
@@ -1346,6 +1349,17 @@ void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
static const size_t trace__entry_str_size = 2048;
+static void thread_trace__free_files(struct thread_trace *ttrace)
+{
+ for (int i = 0; i < ttrace->files.max; ++i) {
+ struct file *file = ttrace->files.table + i;
+ zfree(&file->pathname);
+ }
+
+ zfree(&ttrace->files.table);
+ ttrace->files.max = -1;
+}
+
static struct file *thread_trace__files_entry(struct thread_trace *ttrace, int fd)
{
if (fd < 0)
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
` (4 preceding siblings ...)
2023-07-19 20:29 ` [PATCH 5/6] perf trace: Free thread_trace->files table Arnaldo Carvalho de Melo
@ 2023-07-19 20:29 ` Arnaldo Carvalho de Melo
2023-07-19 22:34 ` [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Ian Rogers
6 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-19 20:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo, John Garry,
Alexander Shishkin, Ingo Molnar, Mark Rutland, Peter Zijlstra
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Now the perf tools development is done on these trees/branches:
git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git perf-tools
git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
For a while I'll continue mirroring what is these to the same branches
in my git tree.
Suggested-by: John Garry <john.g.garry@oracle.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/lkml/CAP-5=fVGOP6-k=BTRd_bn=N0HVy+1ShpdW5rk5ND0ZGhm_fQkg@mail.gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
MAINTAINERS | 2 ++
1 file changed, 2 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index aee340630ecaea38..e351cfc7cd41c570 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16629,6 +16629,8 @@ L: linux-kernel@vger.kernel.org
S: Supported
W: https://perf.wiki.kernel.org/
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git perf-tools
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
F: arch/*/events/*
F: arch/*/events/*/*
F: arch/*/include/asm/perf_event.h
--
2.41.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
@ 2023-07-19 22:31 ` Ian Rogers
2023-07-20 13:49 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 10+ messages in thread
From: Ian Rogers @ 2023-07-19 22:31 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, Jiri Olsa,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> So that when thread__delete() runs it can be called and free stuff tools
> stashed into thread->priv, like 'perf trace' does and will use this
> new facility to plug some leaks.
>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/thread.c | 11 +++++++++++
> tools/perf/util/thread.h | 2 ++
> 2 files changed, 13 insertions(+)
>
> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> index 0b166404c5c365cf..35dd4e716e411da9 100644
> --- a/tools/perf/util/thread.c
> +++ b/tools/perf/util/thread.c
> @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid)
> return NULL;
> }
>
> +static void (*thread__priv_destructor)(void *priv);
> +
> +void thread__set_priv_destructor(void (*destructor)(void *priv))
> +{
Perhaps:
assert(thread__priv_destructor == NULL);
To make it clear that there should never be >1 currently.
> + thread__priv_destructor = destructor;
> +}
> +
> void thread__delete(struct thread *thread)
> {
> struct namespaces *namespaces, *tmp_namespaces;
> @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread)
> exit_rwsem(thread__namespaces_lock(thread));
> exit_rwsem(thread__comm_lock(thread));
> thread__free_stitch_list(thread);
> +
> + if (thread__priv_destructor)
> + thread__priv_destructor(thread__priv(thread));
> +
> RC_CHK_FREE(thread);
> }
>
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index 9068a21ce0fa1b0f..e79225a0ea46b789 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid);
> int thread__init_maps(struct thread *thread, struct machine *machine);
> void thread__delete(struct thread *thread);
>
> +void thread__set_priv_destructor(void (*destructor)(void *priv));
> +
> struct thread *thread__get(struct thread *thread);
> void thread__put(struct thread *thread);
>
> --
> 2.41.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address.
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
` (5 preceding siblings ...)
2023-07-19 20:29 ` [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Arnaldo Carvalho de Melo
@ 2023-07-19 22:34 ` Ian Rogers
6 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2023-07-19 22:34 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, Jiri Olsa,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, John Garry
On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Hi,
>
> Please review/ack, I put it as well on the tmp.perf-tools-next
> in the perf-tools-next tree:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=tmp.perf-tools-next
>
> Best regards,
>
> - Arnaldo
>
> Arnaldo Carvalho de Melo (6):
> perf evsel: Free evsel->filter on the destructor
> perf thread: Allow tools to register a thread->priv destructor
> perf trace: Register a thread priv destructor
> perf trace: Really free the evsel->priv area
> perf trace: Free thread_trace->files table
> MAINTAINERS: Add git information for perf-tools and perf-tools-next
> trees/branches
Series:
Acked-by: Ian Rogers <irogers@google.com>
I think patch 2 could use an extra assert to be extra safe.
Thanks,
Ian
> MAINTAINERS | 2 ++
> tools/perf/builtin-trace.c | 38 +++++++++++++++++++++++++++++++-------
> tools/perf/util/evsel.c | 1 +
> tools/perf/util/thread.c | 11 +++++++++++
> tools/perf/util/thread.h | 2 ++
> 5 files changed, 47 insertions(+), 7 deletions(-)
>
> --
> 2.41.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor
2023-07-19 22:31 ` Ian Rogers
@ 2023-07-20 13:49 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-20 13:49 UTC (permalink / raw)
To: Ian Rogers
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, Jiri Olsa,
Adrian Hunter, Clark Williams, Kate Carcia, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
Em Wed, Jul 19, 2023 at 03:31:41PM -0700, Ian Rogers escreveu:
> On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > So that when thread__delete() runs it can be called and free stuff tools
> > stashed into thread->priv, like 'perf trace' does and will use this
> > new facility to plug some leaks.
> >
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> > tools/perf/util/thread.c | 11 +++++++++++
> > tools/perf/util/thread.h | 2 ++
> > 2 files changed, 13 insertions(+)
> >
> > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> > index 0b166404c5c365cf..35dd4e716e411da9 100644
> > --- a/tools/perf/util/thread.c
> > +++ b/tools/perf/util/thread.c
> > @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid)
> > return NULL;
> > }
> >
> > +static void (*thread__priv_destructor)(void *priv);
> > +
> > +void thread__set_priv_destructor(void (*destructor)(void *priv))
> > +{
>
> Perhaps:
> assert(thread__priv_destructor == NULL);
I'll add that.
> To make it clear that there should never be >1 currently.
>
> > + thread__priv_destructor = destructor;
> > +}
> > +
> > void thread__delete(struct thread *thread)
> > {
> > struct namespaces *namespaces, *tmp_namespaces;
> > @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread)
> > exit_rwsem(thread__namespaces_lock(thread));
> > exit_rwsem(thread__comm_lock(thread));
> > thread__free_stitch_list(thread);
> > +
> > + if (thread__priv_destructor)
> > + thread__priv_destructor(thread__priv(thread));
> > +
> > RC_CHK_FREE(thread);
> > }
> >
> > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> > index 9068a21ce0fa1b0f..e79225a0ea46b789 100644
> > --- a/tools/perf/util/thread.h
> > +++ b/tools/perf/util/thread.h
> > @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid);
> > int thread__init_maps(struct thread *thread, struct machine *machine);
> > void thread__delete(struct thread *thread);
> >
> > +void thread__set_priv_destructor(void (*destructor)(void *priv));
> > +
> > struct thread *thread__get(struct thread *thread);
> > void thread__put(struct thread *thread);
> >
> > --
> > 2.41.0
> >
--
- Arnaldo
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-07-20 13:50 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
2023-07-19 22:31 ` Ian Rogers
2023-07-20 13:49 ` Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 3/6] perf trace: Register a thread priv destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 4/6] perf trace: Really free the evsel->priv area Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 5/6] perf trace: Free thread_trace->files table Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Arnaldo Carvalho de Melo
2023-07-19 22:34 ` [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).