From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: bpf@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [RFC PATCH v1 7/8] perf record: Add --buildid-offset option
Date: Fri, 07 Aug 2026 09:47:10 +0000 [thread overview]
Message-ID: <20260807094710.CA0491F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807071818.718751-8-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] evsel__parse_sample() is vulnerable to an out-of-bounds read when parsing PERF_SAMPLE_BUILD_ID_OFFSET due to missing bounds checks and under-counted sample_size.
- [High] --buildid-offset silently produces unusable recordings if --buildid-mmap is disabled or unsupported.
- [High] Integer overflow in OVERFLOW_CHECK calculation for PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET bypasses bounds verification on 32-bit hosts.
- [Medium] perf report natively handles callchain build ID offsets but its front-end argument validation incorrectly rejects them.
- [Low] An empty if block with commented-out code was added to cmd_record.
--
--- Patch [7]: [RFC PATCH v1 7/8] perf record: Add --buildid-offset option ---
commit 1f8464ef5aa5b3d651d1ae57de1909d39b5f085c
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 7 07:18:17 2026 +0000
perf record: Add --buildid-offset option
Add the --buildid-offset flag to perf record to natively request
PERF_SAMPLE_BUILD_ID_OFFSET and PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET
from the kernel. This configures the evsel attributes by replacing
the standard IP and CALLCHAIN bits with the build ID offset equivalents.
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index f58d7e3c7879e..9ff9cfc062788 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
[ ... ]
> @@ -4166,6 +4168,11 @@ int cmd_record(int argc, const char **argv)
> rec->no_buildid_cache = true;
> }
>
> + if (rec->opts.buildid_offset) {
> + /* Do not drop mmap events here so we can generate build ids later */
> + /* rec->opts.synth &= ~PERF_SYNTH_MMAP; */
> + }
> +
[Severity: Low]
Is this commented-out code still needed, or can this empty block be removed?
[Severity: High]
Can sample resolution silently fail if --buildid-mmap is unsupported or
disabled?
If a user explicitly requests --buildid-offset but disables --buildid-mmap,
or the kernel does not support MMAP build IDs (which causes perf to forcefully
disable --buildid-mmap), the MMAP events will lack build IDs.
This causes thread__find_map() and maps__find_by_build_id() to silently fail,
resulting in broken profiles with unknown symbols and bypassing the final
post-processing step to read build IDs from disk.
Should we enforce the dependency on rec->buildid_mmap here?
> if (rec->opts.record_cgroup && !perf_can_record_cgroup()) {
[ ... ]
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index d9a07f5825e82..587f0fa41cce8 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
[ ... ]
> @@ -1744,6 +1744,17 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,
> if (opts->sample_transaction)
> evsel__set_sample_bit(evsel, TRANSACTION);
>
> + if (opts->buildid_offset) {
> + if (evsel->core.attr.sample_type & PERF_SAMPLE_IP) {
> + evsel__reset_sample_bit(evsel, IP);
> + evsel__set_sample_bit(evsel, BUILD_ID_OFFSET);
[Severity: High]
Does this allow an out-of-bounds read in evsel__parse_sample()?
When evsel__set_sample_bit() is called, __evsel__set_sample_bit() blindly adds
sizeof(u64) (8 bytes) to evsel->sample_size. However, the actual payload for
PERF_SAMPLE_BUILD_ID_OFFSET is 32 bytes (24 bytes for build_id + 8 for offset).
Because of this under-counting, a crafted or truncated perf.data file can
pass the initial perf_event__check_size() validation. Then, in
evsel__parse_sample(), PERF_SAMPLE_BUILD_ID_OFFSET is parsed without any
explicit OVERFLOW_CHECK, allowing the pointer to read out-of-bounds.
> + }
> + if (evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
> + evsel__reset_sample_bit(evsel, CALLCHAIN);
> + evsel__set_sample_bit(evsel, CALLCHAIN_BUILD_ID_OFFSET);
[Severity: High]
Does this cause an integer overflow on 32-bit hosts?
When parsing PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET in evsel__parse_sample(),
a maliciously crafted file could provide a massive size (e.g., 0x08000001).
The macro OVERFLOW_CHECK performs sz * (sizeof(struct perf_build_id) +
sizeof(u64)), which is sz * 32. This results in 0x100000020 in 64-bit
arithmetic, but on 32-bit hosts, the pointer arithmetic inside OVERFLOW_CHECK
truncates the 64-bit size to 32 bits (0x20).
This trick effectively bypasses the bounds verification, while the raw
size is assigned to callchain_bids_nr, causing an out-of-bounds read during
iteration.
[Severity: Medium]
Will this replacement break perf report when users run it with -g?
If a file is natively recorded with --buildid-offset, the CALLCHAIN bit is
dynamically replaced by PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET.
However, in builtin-report.c:cmd_report():
if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (perf_hpp_list.parent) {
ui__error("Selected --sort parent, but no "
"callchain data. Did you call "
"'perf record' without -g?\n");
This strict check seems to completely ignore that the bit was replaced by
CALLCHAIN_BUILD_ID_OFFSET, causing perf report to incorrectly reject these
files.
> + }
> + }
> +
> if (opts->running_time) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807071818.718751-1-irogers@google.com?part=7
next prev parent reply other threads:[~2026-08-07 9:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 7:18 [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Ian Rogers
2026-08-07 7:18 ` [RFC PATCH v1 1/8] perf event: Factor build_id out into its own top-level struct Ian Rogers
2026-08-07 7:33 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 2/8] perf/core: Add BUILD_ID_OFFSET to UAPI Ian Rogers
2026-08-07 7:42 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 3/8] perf/core: Implement BUILD_ID_OFFSET sample type Ian Rogers
2026-08-07 7:54 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 4/8] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-08-07 8:20 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 5/8] perf tools: Internal support for BUILD_ID_OFFSET Ian Rogers
2026-08-07 8:41 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 6/8] perf inject: Extend perf inject to support bid_offset conversion Ian Rogers
2026-08-07 9:18 ` sashiko-bot
2026-08-07 7:18 ` [RFC PATCH v1 7/8] perf record: Add --buildid-offset option Ian Rogers
2026-08-07 9:47 ` sashiko-bot [this message]
2026-08-07 7:18 ` [RFC PATCH v1 8/8] perf tests: Add build_id_offset test coverage Ian Rogers
2026-08-07 9:58 ` sashiko-bot
2026-08-07 11:18 ` [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Peter Zijlstra
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=20260807094710.CA0491F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox