From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 8/9] perf mem record: Request PERF_SAMPLE_CPU by default
Date: Mon, 14 Sep 2026 14:11:57 +0000 [thread overview]
Message-ID: <20260914141157.C1FA21F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914125451.2045-9-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Heap buffer overflow when constructing `rec_argv` in `builtin-c2c.c` for systems with a single memory PMU and multiple memory events.
--
commit 6b306f5272233833a7987c9e447a8e3a91ccaf75
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf mem record: Request PERF_SAMPLE_CPU by default
This commit enables requesting PERF_SAMPLE_CPU by default for perf mem record.
It allows the false-sharing detector to distinguish between reads and writes
from different cores and same-CPU traffic by providing a valid cpu field.
Additionally, it explicitly increases the rec_argv array allocation size to
prevent buffer overflows when adding these extra arguments.
[ ... ]
> diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
> index 6101a26b3a781..6f38cda1a45ad 100644
> --- a/tools/perf/builtin-mem.c
> +++ b/tools/perf/builtin-mem.c
> @@ -99,8 +99,13 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem,
> argc = parse_options(argc, argv, options, record_usage,
> PARSE_OPT_KEEP_UNKNOWN);
>
> - /* Max number of arguments multiplied by number of PMUs that can support them. */
> - rec_argc = argc + 9 * (perf_pmu__mem_events_num_mem_pmus(pmu) + 1);
> + /*
> + * Max number of arguments multiplied by number of PMUs that can
> + * support them, plus the arguments added directly below, at most:
> + * "record", "-W", "-d", "--sample-cpu", "--phys-data",
> + * "--data-page-size", "--all-user" and "--all-kernel".
> + */
> + rec_argc = argc + 8 + 9 * (perf_pmu__mem_events_num_mem_pmus(pmu) + 1);
[Severity: High]
This isn't a bug introduced by this patch, but since this explicitly fixes an
allocation under-sizing here, should a similar fix be applied to the
copy-pasted code in builtin-c2c.c?
In tools/perf/builtin-c2c.c:perf_c2c__record():
/* Max number of arguments multiplied by number of PMUs that can support them. */
rec_argc = argc + 11 * (perf_pmu__mem_events_num_mem_pmus(pmu) + 1);
rec_argv = calloc(rec_argc + 1, sizeof(char *));
...
for (j = 0; j < argc; j++, i++)
rec_argv[i] = argv[j];
If a user runs perf c2c record -e spe-load,spe-store,spe-ldst -u -k on a
system with a single memory PMU, rec_argc scales as argc + 11 * 1. However,
5 fixed flags are added, followed by 6 event flags (2 for each of the 3
events), and then 2 optional flags (-u, -k).
This totals 13 flags added, which would write 2 pointers past the allocated
bounds in the final loop. Since this also overwrites calloc's implicit NULL
terminator, cmd_record will then read out-of-bounds.
Can this heap buffer overflow crash the perf tool?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914125451.2045-1-acme@kernel.org?part=8
next prev parent reply other threads:[~2026-09-14 14:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 12:54 [PATCH v5 0/9] perf tools: Annotate fixes, stdio progress indication, debuginfo-client in more places Arnaldo Carvalho de Melo
2026-09-14 12:54 ` [PATCH 1/9] perf test: Skip data_type_profiling when the PMU cannot record memory events Arnaldo Carvalho de Melo
2026-09-14 13:00 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 2/9] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod Arnaldo Carvalho de Melo
2026-09-14 13:07 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 3/9] perf symbol: Fall back to fetching the vmlinux by build ID Arnaldo Carvalho de Melo
2026-09-14 13:18 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 4/9] perf annotate-data: Show the sample count in the data-type browser Arnaldo Carvalho de Melo
2026-09-14 13:24 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 5/9] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-09-14 13:37 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 6/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-09-14 13:44 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 7/9] perf annotate-data: Resolve type DIEs in the debug file they came from Arnaldo Carvalho de Melo
2026-09-14 13:54 ` sashiko-bot
2026-09-14 12:54 ` [PATCH 8/9] perf mem record: Request PERF_SAMPLE_CPU by default Arnaldo Carvalho de Melo
2026-09-14 14:11 ` sashiko-bot [this message]
2026-09-14 12:54 ` [PATCH 9/9] perf mem record: Use the IBS swfilt filter when available Arnaldo Carvalho de Melo
2026-09-14 14:15 ` 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=20260914141157.C1FA21F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--cc=linux-perf-users@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.