Skip to content

Commit

Permalink
perf trace: Use zfree() to reduce chances of use after free
Browse files Browse the repository at this point in the history
[ Upstream commit 9997d5d ]

Do defensive programming by using zfree() to initialize freed pointers
to NULL, so that eventual use after free result in a NULL pointer deref
instead of more subtle behaviour.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Stable-dep-of: 7962ef1 ("perf trace: Really free the evsel->priv area")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
acmel authored and gregkh committed Sep 19, 2023
1 parent eb17c3d commit e5dee82
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/perf/builtin-trace.c
Expand Up @@ -2293,7 +2293,7 @@ static void syscall__exit(struct syscall *sc)
if (!sc)
return;

free(sc->arg_fmt);
zfree(&sc->arg_fmt);
}

static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
Expand Down Expand Up @@ -3129,7 +3129,7 @@ static void evlist__free_syscall_tp_fields(struct evlist *evlist)
if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls"))
continue;

free(et->fmt);
zfree(&et->fmt);
free(et);
}
}
Expand Down Expand Up @@ -4765,11 +4765,11 @@ static void trace__exit(struct trace *trace)
int i;

strlist__delete(trace->ev_qualifier);
free(trace->ev_qualifier_ids.entries);
zfree(&trace->ev_qualifier_ids.entries);
if (trace->syscalls.table) {
for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
syscall__exit(&trace->syscalls.table[i]);
free(trace->syscalls.table);
zfree(&trace->syscalls.table);
}
syscalltbl__delete(trace->sctbl);
zfree(&trace->perfconfig_events);
Expand Down

0 comments on commit e5dee82

Please sign in to comment.