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 2/5] perf trace-event: Fix integer truncation in do_read() and skip()
Date: Sat, 25 Jul 2026 23:21:15 +0530 [thread overview]
Message-ID: <7148147b-c2b0-4d97-bf22-b4bdb50e768b@linux.ibm.com> (raw)
In-Reply-To: <20260724144741.5D8FE1F000E9@smtp.kernel.org>
Thanks for the review
On 24/07/26 20:17, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [Critical] Integer overflow in read_saved_cmdline() leads to massive heap buffer overflow
> --
>
> --- Patch [2]: [PATCH v3 2/5] perf trace-event: Fix integer truncation in do_read() and skip() ---
> commit 907c8b1b7591be61f25cc72141dbcdba5822dfa4
> Author: Tanushree Shah <tshah@linux.ibm.com>
>
> perf trace-event: Fix integer truncation in do_read() and skip()
>
> The do_read() and skip() functions use 'int' for size parameters,
> truncating 64-bit sizes from callers. This causes two issues:
>
> 1. Uninitialized memory dump: do_read() reads fewer bytes than
> allocated, leaving uninitialized heap memory that gets written
> to output files.
>
> 2. Out-of-bounds read: Parsing functions process the full 64-bit
> size while only partial data was read into the buffer.
>
> Change do_read(), __do_read(), and skip() to use size_t for size
> parameters and ssize_t for return values (where applicable), matching
> read()/write() system calls.
> Update callers to use ssize_t for storing return values.
>
>> diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
>> index afd458cf1387d..52ed496d92c3b 100644
>> --- a/tools/perf/util/trace-event-read.c
>> +++ b/tools/perf/util/trace-event-read.c
>
> [ ... ]
>
>> @@ -350,7 +350,7 @@ static int read_saved_cmdline(struct tep_handle *pevent)
>> {
>> unsigned long long size;
>> char *buf;
>> - int ret;
>> + ssize_t ret;
>>
>> /* it can have 0 size */
>> size = read8(pevent);
>
> [Severity: Critical]
> This is a pre-existing issue, but can this lead to a massive heap buffer
> overflow?
>
> In read_saved_cmdline(), size is an 8-byte value read directly from the
> untrusted file:
>
> size = read8(pevent);
> if (!size)
> return 0;
>
> buf = malloc(size + 1);
> if (buf == NULL)
> return -1;
>
> ret = do_read(buf, size);
>
> If the size read from the file is ULLONG_MAX (or UINT_MAX on 32-bit systems),
> the size + 1 expression will wrap to 0.
>
> The malloc(0) call will then succeed and return a small heap chunk, but the
> original unwrapped massive size is passed to do_read(), which will loop and
> read an enormous amount of data directly into the tiny buffer.
>
Confirmed. will send a v4 with a fix for this.
next prev parent reply other threads:[~2026-07-25 17:51 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 [this message]
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
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=7148147b-c2b0-4d97-bf22-b4bdb50e768b@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