From: Tanushree Shah <tshah@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org,
Madhavan Srinivasan <maddy@linux.ibm.com>,
hbathini@linux.ibm.com, atrajeev@linux.ibm.com
Subject: Re: [PATCH v3 3/5] perf trace-event: Avoid double free in trace_event__cleanup()
Date: Sat, 25 Jul 2026 23:25:35 +0530 [thread overview]
Message-ID: <2caa358c-2127-4739-a2ae-cb7ffa201882@linux.ibm.com> (raw)
In-Reply-To: <20260724145514.90C7E1F000E9@smtp.kernel.org>
Thanks for the review
On 24/07/26 20:25, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Calling trace_event__init() repeatedly on the same struct trace_event leaks the previously allocated tep_handle and plugins.
> --
>
> --- Patch [3]: [PATCH v3 3/5] perf trace-event: Avoid double free in trace_event__cleanup() ---
> commit 1eb2775370e0095c8df022b4a83dcd46f4b90b94
> Author: Tanushree Shah <tshah@linux.ibm.com>
>
> perf trace-event: Avoid double free in trace_event__cleanup()
>
> trace_event__cleanup() frees t->pevent but never clears the pointer. It can be
> called twice on the same trace_event: once from trace_report()'s error path,
> and again from perf_session__delete() during session teardown, resulting in a
> double free / use-after-free.
>
>> diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
>> index 6a8c66c64b705..cf40e98d16177 100644
>> --- a/tools/perf/util/trace-event.c
>> +++ b/tools/perf/util/trace-event.c
>> @@ -63,8 +63,12 @@ int trace_event__register_resolver(struct machine *machine,
>>
>> void trace_event__cleanup(struct trace_event *t)
>> {
>> + if (!t->pevent)
>> + return;
>> +
>
> [Severity: High]
> This isn't a bug introduced by this patch, but while we are making it safe
> to call trace_event__cleanup() multiple times, should we also call it from
> trace_event__init() to prevent memory leaks?
>
> If a maliciously crafted perf.data file contains multiple
> PERF_RECORD_HEADER_TRACING_DATA headers, trace_report() can be called
> multiple times on the same session, invoking trace_event__init() repeatedly:
Confirmed, this is a real leak. I'll fold a fix into v4 alongside
the trace_event__cleanup() double-free fix, since the two are
related.
>
> tools/perf/util/trace-event-read.c:trace_report() {
> ...
> if (trace_event__init(tevent)) {
> ...
> }
>
> This overwrites the previously allocated tep_handle and plugins without
> freeing them, leaking the memory:
>
> tools/perf/util/trace-event.c:trace_event__init() {
> ...
> t->plugin_list = tep_load_plugins(pevent);
> t->pevent = pevent;
> ...
> }
>
>> tep_unload_plugins(t->plugin_list, t->pevent);
>> tep_free(t->pevent);
>> + t->pevent = NULL;
>> }
>>
>> /*
>
next prev parent reply other threads:[~2026-07-25 17:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 14:13 [PATCH v3 0/5] perf trace-event: Fix security bugs in trace-event-read.c and trace-event.c Tanushree Shah
2026-07-24 14:13 ` [PATCH v3 1/5] perf trace-event: Fix buffer overflow in read_string() Tanushree Shah
2026-07-24 14:47 ` sashiko-bot
2026-07-25 17:46 ` Tanushree Shah
2026-07-24 14:13 ` [PATCH v3 2/5] perf trace-event: Fix integer truncation in do_read() and skip() Tanushree Shah
2026-07-24 14:47 ` sashiko-bot
2026-07-25 17:51 ` Tanushree Shah
2026-07-24 14:13 ` [PATCH v3 3/5] perf trace-event: Avoid double free in trace_event__cleanup() Tanushree Shah
2026-07-24 14:55 ` sashiko-bot
2026-07-25 17:55 ` Tanushree Shah [this message]
2026-07-24 14:13 ` [PATCH v3 4/5] perf trace-event: Fix heap buffer overflow in read_ftrace_printk() Tanushree Shah
2026-07-24 14:54 ` sashiko-bot
2026-07-25 18:11 ` Tanushree Shah
2026-07-24 14:13 ` [PATCH v3 5/5] perf trace-event: Fix infinite loop in skip() Tanushree Shah
2026-07-24 14:57 ` sashiko-bot
2026-07-25 18:13 ` Tanushree Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2caa358c-2127-4739-a2ae-cb7ffa201882@linux.ibm.com \
--to=tshah@linux.ibm.com \
--cc=acme@kernel.org \
--cc=atrajeev@linux.ibm.com \
--cc=hbathini@linux.ibm.com \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=maddy@linux.ibm.com \
--cc=namhyung@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox