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 6/8] perf header: Do validation of perf.data HEADER_CPU_DOMAIN_INFO
Date: Wed, 08 Apr 2026 18:38:55 +0000	[thread overview]
Message-ID: <20260408183856.0CA3AC19421@smtp.kernel.org> (raw)
In-Reply-To: <20260408172846.96360-7-acme@kernel.org>

Sashiko AI review found 1 potential issue(s):
- [Critical] This problem wasn't introduced by this patch, but the patch fails to completely validate untrusted data from the `perf.data` file, leaving a critical out-of-bounds read and arbitrary free vulnerability. The bounds validation checks `cpu >= nra` and `domain >= max_sched_domains` but misses the validation of `nr_domains`. The variable `nr_domains` is read directly from the file and stored in `cd_map[cpu]->nr_domains`, while the `domains` array is allocated with a size of `max_sched_domains` (which is also read from the file). There is no check ensuring `nr_domains <= max_sched_domains`. If an attacker crafts a file where `nr_domains > max_sched_domains` and induces an early exit (e.g., by providing an invalid `domain` index, which the patch now explicitly catches and returns `-1`), the parsing function aborts and the cleanup function `free_cpu_domain_info()` is invoked. The cleanup loop iterates `j` from `0` up to `cd_map[cpu]->nr_domains - 1`, reading `cd_map[cpu]->domains[j]`. This reads out of bounds of the `domains` array, interpreting adjacent heap memory as `struct domain_info *` pointers. If these out-of-bounds values are non-NULL, the code calls `zfree()` on their fields and the pointer itself, resulting in a severe memory corruption vulnerability.
--

commit 5c7601d84031087ca2a9bfeeedd3934e8e426309
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf header: Do validation of perf.data HEADER_CPU_DOMAIN_INFO

This commit validates the cpu and domain values read from perf.data files
against nr_cpus_avail and max_sched_domains. The newly added validation
prevents using out-of-bounds indices to access the cd_map and domains
arrays.

> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index a18f216f77c27..4925e33778b91 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c

[ ... ]

> @@ -3736,6 +3741,12 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused
>  			if (do_read_u32(ff, &domain))
>  				return -1;
>  
> +			if (domain >= max_sched_domains) {
> +				pr_err("Invalid HEADER_CPU_DOMAIN_INFO: domain %d >= max_sched_domains (%d)\n",
> +				       domain, max_sched_domains);
> +				return -1;
> +			}
> +

Does this code leave nr_domains unvalidated against max_sched_domains?

Earlier in process_cpu_domain_info(), nr_domains is read and assigned to
the map, but the domains array is allocated using max_sched_domains:

	if (do_read_u32(ff, &nr_domains))
		return -1;

	cd_map[cpu]->nr_domains = nr_domains;

	cd_map[cpu]->domains = zalloc(sizeof(*d_info) * max_sched_domains);

If a perf.data file contains a nr_domains value greater than
max_sched_domains, and an invalid domain index triggers the new return -1
path shown above, could this lead to an out-of-bounds read during cleanup?

If the cleanup function iterates up to the unvalidated nr_domains, it would
read past the end of the domains array. If these out-of-bounds values are
then freed, could this regression result in an arbitrary free?

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

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

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

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=20260408183856.0CA3AC19421@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