From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
Clark Williams <williams@redhat.com>,
<linux-kernel@vger.kernel.org>,
<linux-perf-users@vger.kernel.org>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
sashiko-bot <sashiko-bot@kernel.org>, "Leo Yan" <leo.yan@arm.com>
Subject: Re: [PATCH 5/5] perf arm-spe: Reject zero nr_cpu in metadata to prevent division by zero
Date: Mon, 3 Aug 2026 21:46:49 +0300 [thread overview]
Message-ID: <df7bf01f-b0f6-403c-8415-305f3ea63fdb@intel.com> (raw)
In-Reply-To: <20260727161705.64807-6-acme@kernel.org>
On 27/07/2026 19:17, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> arm_spe__alloc_metadata() reads nr_cpu from the auxtrace_info priv
> array without validation. When a crafted perf.data provides nr_cpu=0,
> the per_cpu_sz calculation divides by zero:
>
> per_cpu_sz = (metadata_size - (hdr_sz * sizeof(u64))) / (*nr_cpu);
>
> Reject nr_cpu <= 0 early, before the division. The caller already
> treats NULL return with metadata_ver != 1 as a parse failure.
>
> Fixes: e52abceb4b6c2723 ("perf arm-spe: Dump metadata with version 2")
git blame shows 7842a4b6ff698 "perf arm-spe: Support metadata version 2"
for the relevant lines
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Cc: Leo Yan <leo.yan@arm.com>
> Cc: James Clark <james.clark@linaro.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Assisted-by: Claude:claude-opus-4.6
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/arm-spe.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 552f063f126e6769..401aab529309cbd6 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -1605,6 +1605,10 @@ static u64 **arm_spe__alloc_metadata(struct perf_record_auxtrace_info *info,
> hdr_sz = ptr[ARM_SPE_HEADER_SIZE];
> *nr_cpu = ptr[ARM_SPE_CPUS_NUM];
>
> + /* nr_cpu is used as a divisor below */
> + if (*nr_cpu <= 0)
> + return NULL;
> +
> metadata = calloc(*nr_cpu, sizeof(*metadata));
> if (!metadata)
> return NULL;
next prev parent reply other threads:[~2026-08-03 18:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 16:17 [PATCHES 0/5 v1] perf tools auxtrace hardening series Arnaldo Carvalho de Melo
2026-07-27 16:17 ` [PATCH 1/5] perf thread-stack: Fix heap buffer overflow on branch stack wrap copy Arnaldo Carvalho de Melo
2026-07-27 16:17 ` [PATCH 2/5] perf auxtrace: Fix queue grow overflow and old array leak Arnaldo Carvalho de Melo
2026-07-27 16:17 ` [PATCH 3/5] perf intel-pt: Fix off-by-one in auxtrace_info minimum size check Arnaldo Carvalho de Melo
2026-07-27 16:17 ` [PATCH 4/5] perf intel-bts: " Arnaldo Carvalho de Melo
2026-07-27 16:17 ` [PATCH 5/5] perf arm-spe: Reject zero nr_cpu in metadata to prevent division by zero Arnaldo Carvalho de Melo
2026-08-03 18:46 ` Adrian Hunter [this message]
2026-08-03 19:02 ` Arnaldo Carvalho de Melo
2026-08-03 19:41 ` Namhyung Kim
2026-07-27 16:31 ` [PATCHES 0/5 v1] perf tools auxtrace hardening series James Clark
2026-07-31 23:27 ` Namhyung Kim
2026-08-03 18:46 ` Adrian Hunter
2026-08-03 19:02 ` Arnaldo Carvalho de Melo
2026-08-04 17:04 ` Namhyung Kim
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=df7bf01f-b0f6-403c-8415-305f3ea63fdb@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox