From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/4] perf header: Validate string length before allocating in do_read_string()
Date: Tue, 14 Apr 2026 21:51:26 +0000 [thread overview]
Message-ID: <20260414215127.35904C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260414204847.293557-3-acme@kernel.org>
Sashiko AI review found 2 potential issue(s):
- [Critical] `do_read_string()` fails to ensure null-termination, leading to out-of-bounds reads and heap buffer overflows.
- [Medium] The newly added size check is trivially bypassable because `ff->size` is unvalidated.
--
commit 1c3491f2bf9f038ae68f7007db4323e57b4d8132
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf header: Validate string length before allocating in do_read_string()
This commit attempts to prevent large memory allocations by verifying the
requested string length against the remaining section size before calling
malloc.
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index ca0c9e80345b2..f8acd06ae9235 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -259,6 +259,9 @@ static char *do_read_string(struct feat_fd *ff)
> if (do_read_u32(ff, &len))
> return NULL;
>
> + if (len > ff->size - ff->offset)
> + return NULL;
Is ff->size validated against the actual physical file size before this check?
If ff->size is initialized directly from the user-controlled section size in
the perf.data headers, couldn't a crafted file provide a maliciously large
section size?
This would allow the bounds check to pass, triggering the large allocation
this code was intended to prevent.
> +
> buf = malloc(len);
> if (!buf)
> return NULL;
>
> if (!__do_read(ff, buf, len)) {
> /*
> * strings are padded by zeroes
> * thus the actual strlen of buf
> * may be less than len
> */
> return buf;
> }
Does this guarantee the returned string is null-terminated?
If a crafted perf.data provides a string without a null byte, or if len is 0,
wouldn't callers invoking strlen(buf) read out-of-bounds into adjacent heap
memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260414204847.293557-1-acme@kernel.org?part=2
next prev parent reply other threads:[~2026-04-14 21:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 20:48 [PATCHES 0/4] More perf.data header validation Arnaldo Carvalho de Melo
2026-04-14 20:48 ` [PATCH 1/4] perf header: Add section bounds checking to the fd read path Arnaldo Carvalho de Melo
2026-04-14 21:24 ` sashiko-bot
2026-04-14 20:48 ` [PATCH 2/4] perf header: Validate string length before allocating in do_read_string() Arnaldo Carvalho de Melo
2026-04-14 21:51 ` sashiko-bot [this message]
2026-04-14 20:48 ` [PATCH 3/4] perf header: Sanity check HEADER_EVENT_DESC Arnaldo Carvalho de Melo
2026-04-14 22:20 ` sashiko-bot
2026-04-14 20:48 ` [PATCH 4/4] perf header: Validate bitmap size before allocating in do_read_bitmap() Arnaldo Carvalho de Melo
2026-04-14 22:46 ` sashiko-bot
2026-04-16 8:24 ` [PATCHES 0/4] More perf.data header validation James Clark
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=20260414215127.35904C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@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