public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 5/8] perf header: Use a max number of command line args
Date: Wed, 08 Apr 2026 18:09:49 +0000	[thread overview]
Message-ID: <20260408180950.9349BC19421@smtp.kernel.org> (raw)
In-Reply-To: <20260408173203.96700-6-acme@kernel.org>

Sashiko AI review found 2 potential issue(s):
- [Critical] Unvalidated `ff->size` and unenforced string lengths lead to heap buffer overflow.
- [High] Missing null-termination validation causes out-of-bounds reads.
--

commit 1f222a4afd391a2d476456be29b779929e17885b
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf header: Use a max number of command line args

This commit sets a reasonable maximum number of command line arguments to
avoid overflows when reading perf.data files.

> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
[ ... ]
> @@ -2804,6 +2807,9 @@ static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused)
>  	if (do_read_u32(ff, &nr))
>  		return -1;
>  
> +	if (nr > MAX_CMDLINE_NR)
> +		return -1;
> +
>  	env->nr_cmdline = nr;
>  
>  	cmdline = zalloc(ff->size + nr + 1);

This problem wasn't introduced by this patch, but is there a potential integer
overflow here?

Because ff->size is attacker-controlled data from the perf.data file header
and is not validated, could an attacker set ff->size near the maximum value
to cause an integer overflow, resulting in zalloc allocating a tiny buffer?

Alternatively, even without an integer overflow, could an attacker set a small
ff->size but embed large strings in the file, bypassing validation if
do_read_string() does not enforce that the read bytes fit within the declared
ff->size?

This would cause the subsequent memcpy loop to write beyond the allocated
cmdline buffer, leading to a heap buffer overflow.

>  	if (!cmdline)
>  		return -1;
>  
>  	argv = zalloc(sizeof(char *) * (nr + 1));
>  	if (!argv)
>  		goto error;
>  
>  	for (i = 0; i < nr; i++) {
>  		str = do_read_string(ff);
>  		if (!str)
>  			goto error;
>  
>  		argv[i] = cmdline + len;
>  		memcpy(argv[i], str, strlen(str) + 1);

This issue was also not introduced by this patch, but does this code cause an
out-of-bounds read if the string is not null-terminated?

If do_read_string() allocates memory based on a length prefix and reads data
directly from the file without explicitly appending a null terminator, could a
malicious perf.data file provide a string length but fill the content entirely
with non-null bytes?

This would cause strlen(str) to scan past the end of the str allocation until
it encounters a null byte in adjacent heap memory.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260408173203.96700-1-acme@kernel.org?part=5

  reply	other threads:[~2026-04-08 18:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 17:31 [PATCHES perf-tools-next v6 0/8] Cleanups and fixes Arnaldo Carvalho de Melo
2026-04-08 17:31 ` [PATCH 1/8] perf symbols: Make variable receiving result strrchr() const Arnaldo Carvalho de Melo
2026-04-08 17:31 ` [PATCH 2/8] perf util: Kill die() prototype, dead for a long time Arnaldo Carvalho de Melo
2026-04-08 17:31 ` [PATCH 3/8] perf tools: Make more global variables static Arnaldo Carvalho de Melo
2026-04-08 17:31 ` [PATCH 4/8] perf bench: Constify tables Arnaldo Carvalho de Melo
2026-04-08 17:32 ` [PATCH 5/8] perf header: Use a max number of command line args Arnaldo Carvalho de Melo
2026-04-08 18:09   ` sashiko-bot [this message]
2026-04-08 17:32 ` [PATCH 6/8] perf header: Do validation of perf.data HEADER_CPU_DOMAIN_INFO Arnaldo Carvalho de Melo
2026-04-08 18:28   ` sashiko-bot
2026-04-08 17:32 ` [PATCH 7/8] perf tools: Use calloc() where applicable Arnaldo Carvalho de Melo
2026-04-08 18:47   ` sashiko-bot
2026-04-08 17:32 ` [PATCH 8/8] perf tools: Replace basename() calls with perf_basename() Arnaldo Carvalho de Melo
2026-04-09  2:20 ` [PATCHES perf-tools-next v6 0/8] Cleanups and fixes Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2026-04-08 17:28 [PATCHES perf-tools-next v5 0/7] " Arnaldo Carvalho de Melo
2026-04-08 17:28 ` [PATCH 5/8] perf header: Use a max number of command line args Arnaldo Carvalho de Melo
2026-04-08 18:17   ` 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=20260408180950.9349BC19421@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