From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v4 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader
Date: Tue, 21 Jul 2026 19:26:46 +0000 [thread overview]
Message-ID: <20260721192647.3C6891F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721182150.94016-3-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Critical] Bypassing _FORTIFY_SOURCE array bounds checks introduces an exploitable stack buffer overflow when zeroing event trailers.
- [High] Removal of the stale build ID clearing leaks state and corrupts subsequent kernel module events.
Pre-existing issues:
- [High] Incomplete fix: _FORTIFY_SOURCE array bounds aborts still exist in multiple other synthesis functions.
--
--- Patch [2]: [PATCH v4 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader ---
commit ba0b89af1798a9c26d45cb174748a43558ce4d9d
Author: Ian Rogers <irogers@google.com>
perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader
This commit fixes bugs in read_proc_maps_line() and its callers by ensuring
proper line draining on parsing failures. It also adds standard fallbacks
for over-length paths, safely emits timeout flags, and introduces pointer
casts to prevent _FORTIFY_SOURCE array bounds aborts when zeroing trailers.
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index 5307d707711d8..e0680d770462c 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
[ ... ]
> @@ -463,45 +533,53 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool,
[ ... ]
> - memset(event->mmap2.filename + size, 0, machine->id_hdr_size +
> - (aligned_size - size));
> - event->mmap2.header.size += machine->id_hdr_size;
> + /* Zero the padding and ID header trailer safely! */
> + memset((char *)event + offsetof(struct perf_record_mmap2, filename) + size, 0,
> + (aligned_size - size) + machine->id_hdr_size);
> +
> + event->mmap2.header.size += machine->id_hdr_size;
[Severity: Critical]
Can bypassing the _FORTIFY_SOURCE array bounds checks introduce a stack
buffer overflow regression here?
When this function is called via machine__init_live(), the event union is
allocated on the stack without the extra padding for id_hdr_size:
tools/perf/util/machine.c:machine__init_live() {
union perf_event event;
memset(&event, 0, sizeof(event));
...
perf_event__synthesize_mmap_events(tool, &event, ...);
}
If an attacker provides a pathname approaching PATH_MAX in /proc/pid/maps,
size pushes the memset destination to the end of the union perf_event
structure. By bypassing the fortify check, this memset blindly writes
machine->id_hdr_size bytes of zeroes completely outside the bounds of the
stack variable, silently corrupting the stack frame instead of safely
aborting.
[Severity: High]
This is a pre-existing issue, but does the same _FORTIFY_SOURCE array
bounds abort regression still exist in other synthesis functions?
While this patch applies a cast bypass here in
perf_event__synthesize_mmap_events(), similar bounds-violating memset calls
remain in other paths.
For example, in perf_event__prepare_comm():
tools/perf/util/synthetic-events.c:perf_event__prepare_comm() {
...
memset(event->comm.comm + size, 0, machine->id_hdr_size);
...
}
Since event->comm.comm is a static 16-byte array, if a process name is 15
characters long, the memset begins exactly at the end of the array and
writes id_hdr_size bytes. Under modern compiler flags (_FORTIFY_SOURCE=2
or 3), this reliably triggers an abort because the compiler detects
the memset writing past the bounds of the array. The same pattern is
also present in perf_event__synthesize_cgroups().
[ ... ]
> @@ -703,11 +781,6 @@ static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)
>
> memcpy(event->mmap2.filename, dso__long_name(dso), dso__long_name_len(dso) + 1);
>
> - /* Clear stale build ID from previous module iteration */
> - event->mmap2.header.misc &= ~PERF_RECORD_MISC_MMAP_BUILD_ID;
> - memset(event->mmap2.build_id, 0, sizeof(event->mmap2.build_id));
> - event->mmap2.build_id_size = 0;
> -
> perf_record_mmap2__read_build_id(&event->mmap2, args->machine, false);
> } else {
> size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
[Severity: High]
Could removing this explicit clearing of the shared union's build ID leak
state between loop iterations?
The perf_event__synthesize_modules() function allocates a single
union perf_event structure outside the loop and reuses it for every kernel
module via maps__for_each_map().
By removing the explicit clearing of PERF_RECORD_MISC_MMAP_BUILD_ID, if one
module successfully reads a build ID, the flag remains set for all
subsequent modules.
When processing subsequent modules, perf_record_mmap2__read_build_id() sees
the flag is already set, assumes the event already contains a valid build
ID, and reads the stale build ID from the previous iteration. This could
attribute samples to incorrect binaries.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260721182150.94016-1-irogers@google.com?part=2
next prev parent reply other threads:[~2026-07-21 19:26 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 17:54 [PATCH v1 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-20 17:54 ` [PATCH v1 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-20 18:05 ` sashiko-bot
2026-07-20 17:54 ` [PATCH v1 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-20 18:08 ` sashiko-bot
2026-07-20 17:54 ` [PATCH v1 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-20 17:54 ` [PATCH v1 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-20 18:28 ` sashiko-bot
2026-07-20 22:51 ` [PATCH v2 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-20 22:51 ` [PATCH v2 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-20 22:51 ` [PATCH v2 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-20 23:03 ` sashiko-bot
2026-07-20 22:51 ` [PATCH v2 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-20 22:52 ` [PATCH v2 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-21 17:33 ` [PATCH v3 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-21 17:33 ` [PATCH v3 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-21 17:33 ` [PATCH v3 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-21 17:48 ` sashiko-bot
2026-07-21 17:33 ` [PATCH v3 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-21 17:47 ` sashiko-bot
2026-07-21 17:33 ` [PATCH v3 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-21 18:21 ` [PATCH v4 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-21 18:21 ` [PATCH v4 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-21 18:21 ` [PATCH v4 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-21 19:26 ` sashiko-bot [this message]
2026-07-21 18:21 ` [PATCH v4 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-21 18:21 ` [PATCH v4 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-21 19:25 ` sashiko-bot
2026-07-21 20:57 ` [PATCH v5 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-21 20:57 ` [PATCH v5 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-21 20:57 ` [PATCH v5 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-21 21:15 ` sashiko-bot
2026-07-21 20:57 ` [PATCH v5 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-21 20:57 ` [PATCH v5 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-21 23:09 ` [PATCH v6 0/4] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-21 23:09 ` [PATCH v6 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-21 23:09 ` [PATCH v6 2/4] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-21 23:24 ` sashiko-bot
2026-07-21 23:09 ` [PATCH v6 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-21 23:09 ` [PATCH v6 4/4] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-21 23:52 ` [PATCH v7 0/5] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
2026-07-21 23:52 ` [PATCH v7 1/5] perf find-map: Remove PATH_MAX 128-byte stack array restriction Ian Rogers
2026-07-21 23:52 ` [PATCH v7 2/5] perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps reader Ian Rogers
2026-07-22 0:10 ` sashiko-bot
2026-07-21 23:52 ` [PATCH v7 3/5] perf synthetic-events: Fix stack buffer overflow and bounds in cgroup synthesis Ian Rogers
2026-07-22 0:04 ` sashiko-bot
2026-07-21 23:52 ` [PATCH v7 4/5] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis Ian Rogers
2026-07-21 23:52 ` [PATCH v7 5/5] perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesis Ian Rogers
2026-07-22 0:13 ` [PATCH v7 0/5] perf: Fix and optimize maps parsing, boundaries, and bounds safety Ian Rogers
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=20260721192647.3C6891F000E9@smtp.kernel.org \
--to=sashiko-bot@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 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.