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 1/5] perf trace-event: Fix buffer overflow in read_string()
Date: Sat, 25 Jul 2026 19:27:32 +0000	[thread overview]
Message-ID: <20260725192732.CA9971F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725184953.234759-2-tshah@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Dangling pointer dereference of session->tevent.pevent on malformed perf.data due to error check bypass.
- [High] Implicit truncation of 64-bit sizes to 32-bit signed integers in `do_read` and `skip`, and integer overflows in allocations, lead to stack/heap buffer overflows and uninitialized memory disclosures.
--

--- Patch [1]: [PATCH v4 1/5] perf trace-event: Fix buffer overflow in read_string() ---
commit b0a22e84b8d80d3f8d078756fde29ba8352194d0
Author: Tanushree Shah <tshah@linux.ibm.com>

perf trace-event: Fix buffer overflow in read_string()

This commit fixes a stack buffer overflow in read_string() by adding a bounds
check before writing each character into the buffer. If the string from the
input is longer than BUFSIZ, it now prevents the overflow and returns NULL,
matching other error paths.

> diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
> index ecbbb93f01853..afd458cf1387d 100644
> --- a/tools/perf/util/trace-event-read.c
> +++ b/tools/perf/util/trace-event-read.c
> @@ -127,6 +127,11 @@ static char *read_string(void)
>  			}
>  		}
>  
> +		if (size >= (int)sizeof(buf) - 1) {
> +			pr_debug("string too long (max %zu bytes)", sizeof(buf) - 1);
> +			goto out;
> +		}
> +
>  		buf[size++] = c;
>  
>  		if (!c)

[Severity: High]
This isn't a bug introduced by this patch, but since we are fixing buffer
overflows in this file, are there similar truncation issues in do_read() and
skip()?

Looking at do_read() and skip() in tools/perf/util/trace-event-read.c, they
take size as a signed int:

static int do_read(void *data, int size)
static void skip(int size)

When a large 32-bit or 64-bit size is read from the trace data and passed to
these functions, it can be truncated to a negative integer. In skip(), could
this negative value cause the computed read amount to become negative,
triggering do_read() and eventually the read() system call to attempt reading a
massive amount of data into the local stack buffer?

Similarly, in read_ftrace_printk() and read_saved_cmdline(), can the
malloc(size + 1) calculation overflow to 0 when a large size is provided,
creating a tiny allocation before do_read() is called with the truncated
negative size, leading to a heap overflow?

[Severity: High]
This is a pre-existing issue, but can a malformed perf.data file cause a
dangling pointer dereference during error handling?

In tools/perf/util/header.c:perf_event__process_tracing_data(), if
trace_report() returns an error (-1), size_read becomes -1. The subsequent
padding calculation:

	padding = PERF_ALIGN(-1, 8) - (-1);

evaluates to 1. This means size_read + padding equals 0. If the provided event
size is 0, the size mismatch check:

	if (size_read + padding != size)

evaluates to 0 != 0, which is false, bypassing the error check.

Since trace_report() triggers trace_event__cleanup() on error paths, which
frees t->pevent without setting it to NULL:

tools/perf/util/trace-event.c:trace_event__cleanup() {
	tep_unload_plugins(t->plugin_list, t->pevent);
	tep_free(t->pevent);
}

Does this bypass lead to evlist__prepare_tracepoint_events() being called with
a dangling session->tevent.pevent pointer?

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

  reply	other threads:[~2026-07-25 19:27 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 [this message]
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
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=20260725192732.CA9971F000E9@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.