All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tanushree Shah" <tshah@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v4 3/5] perf trace-event: Avoid double free and leak in trace_event__cleanup()/trace_event__init()
Date: Sat, 25 Jul 2026 19:30:29 +0000	[thread overview]
Message-ID: <20260725193030.0F80C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725184953.234759-4-tshah@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Fixing a memory leak in `trace_event__init()` introduces an exploitable Use-After-Free when processing malformed or crafted `perf.data` files with multiple `PERF_RECORD_HEADER_TRACING_DATA` headers.
--

--- Patch [3]: [PATCH v4 3/5] perf trace-event: Avoid double free and leak in trace_event__cleanup()/trace_event__init() ---
commit 47e0085adcff000a3a6472e037799a5ddd33c012
Author: Tanushree Shah <tshah@linux.ibm.com>

perf trace-event: Avoid double free and leak in trace_event__cleanup()/trace_event__init()

This commit addresses a double-free in trace_event__cleanup() and a memory
leak in trace_event__init() when a perf.data file contains multiple
PERF_RECORD_HEADER_TRACING_DATA headers. It fixes the leak by calling
trace_event__cleanup() before allocating a new tep handle.

> diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
> index 6a8c66c64b705..000c1e1d68c16 100644
> --- a/tools/perf/util/trace-event.c
> +++ b/tools/perf/util/trace-event.c
> @@ -26,7 +26,11 @@ static bool tevent_initialized;
>  
>  int trace_event__init(struct trace_event *t)
>  {
> -	struct tep_handle *pevent = tep_alloc();
> +	struct tep_handle *pevent;
> +
> +	trace_event__cleanup(t);
> +

[Severity: Critical]
Could this cleanup introduce a use-after-free when parsing a perf.data
file with multiple PERF_RECORD_HEADER_TRACING_DATA headers?

When trace_event__cleanup(t) frees the existing tep_event objects, any 
evsel->tp_format pointers that were set during the first header's parsing 
are left dangling.

Specifically, in tools/perf/util/header.c:evsel__prepare_tracepoint_event(),
it short-circuits if the pointer is already set:

	/* already prepared */
	if (evsel->tp_format)
		return 0;

This short-circuit prevents evsel->tp_format from being updated to point to
the newly allocated memory. Later, tools/perf/util/evsel.c:evsel__tp_format()
retrieves this dangling pointer:

	if (tp_format)
		return tp_format;

Does this leave the perf tool vulnerable to memory corruption when analyzing
a malformed or maliciously crafted perf.data file?

> +	pevent = tep_alloc();
>  
>  	if (pevent) {
>  		t->plugin_list = tep_load_plugins(pevent);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260725184953.234759-1-tshah@linux.ibm.com?part=3

  reply	other threads:[~2026-07-25 19:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 18:49 [PATCH v4 0/5] perf trace-event: Fix overflow, loop and cleanup bugs Tanushree Shah
2026-07-25 18:49 ` [PATCH v4 1/5] perf trace-event: Fix buffer overflow in read_string() Tanushree Shah
2026-07-25 19:27   ` sashiko-bot
2026-07-25 18:49 ` [PATCH v4 2/5] perf trace-event: Fix integer truncation in do_read() and skip() Tanushree Shah
2026-07-25 19:29   ` sashiko-bot
2026-07-25 18:49 ` [PATCH v4 3/5] perf trace-event: Avoid double free and leak in trace_event__cleanup()/trace_event__init() Tanushree Shah
2026-07-25 19:30   ` sashiko-bot [this message]
2026-07-25 18:49 ` [PATCH v4 4/5] perf trace-event: Fix heap overflows in read_ftrace_printk()/read_saved_cmdline() Tanushree Shah
2026-07-25 19:27   ` sashiko-bot
2026-07-25 18:49 ` [PATCH v4 5/5] perf trace-event: Fix infinite loop in skip() Tanushree Shah
2026-07-25 19:29   ` sashiko-bot

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=20260725193030.0F80C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tshah@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.