Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis
Date: Tue, 21 Jul 2026 17:47:43 +0000	[thread overview]
Message-ID: <20260721174744.715211F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721173347.9163-4-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The memset used to clear the filename padding and ID header trailer will trigger a _FORTIFY_SOURCE runtime abort when a DSO name length approaches PATH_MAX.
--

--- Patch [3]: [PATCH v3 3/4] perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis ---
commit e862d233381463bc8c1e84b7d335152fe0a7c118
Author: Ian Rogers <irogers@google.com>

perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesis

This commit clamps long DSO names to mmap/mmap2 filename boundaries to prevent
buffer overruns in perf_event__synthesize_modules_maps_cb(). It also explicitly
clears misc flags and union padding to prevent stale Build-ID state from leaking
between module synthesis events.

> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c

[ ... ]

> @@ -761,49 +762,78 @@ static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)
>  	if (!symbol_conf.no_buildid_mmap2) {
>  		const char *long_name = dso__long_name(dso);
>  
> -		size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
> +		size = strlen(long_name);
> +		if (size >= sizeof(event->mmap2.filename))
> +			size = sizeof(event->mmap2.filename) - 1;
> +
> +		strlcpy(event->mmap2.filename, long_name,
> +			sizeof(event->mmap2.filename));
> +
> +		aligned_size = PERF_ALIGN(size + 1, sizeof(u64));
>  		event->mmap2.header.type = PERF_RECORD_MMAP2;
> -		event->mmap2.header.size = (sizeof(event->mmap2) -
> -					(sizeof(event->mmap2.filename) - size));
> -		memset(event->mmap2.filename + size, 0, args->machine->id_hdr_size);
> +		event->mmap2.header.misc = args->misc;
> +		event->mmap2.header.size =
> +			offsetof(struct perf_record_mmap2, filename) +
> +			aligned_size;
> +
> +		/* Zero the padding and ID header trailer safely! */
> +		memset(event->mmap2.filename + size, 0,
> +		       (aligned_size - size) + args->machine->id_hdr_size);

[Severity: High]
This is a pre-existing issue, but can this memset trigger a _FORTIFY_SOURCE
runtime abort when a DSO name length approaches PATH_MAX?

The event->mmap2.filename field is declared as a fixed-size array of
PATH_MAX (4096 bytes). If a kernel module path is very long, size is clamped
to 4095 and aligned_size evaluates to 4096. The memset then attempts to write
(1 + args->machine->id_hdr_size) bytes starting at event->mmap2.filename + 4095.

Because the memset is anchored to the filename member array, _FORTIFY_SOURCE
dynamically tracks that there is only 1 byte remaining in that specific member.
Since 1 + id_hdr_size > 1, this exceeds the compiler-enforced array bound,
triggering __chk_fail() and terminating perf, even though the underlying
allocation is large enough.

> +
>  		event->mmap2.header.size += args->machine->id_hdr_size;
>  		event->mmap2.start = map__start(map);

[ ... ]

>  		perf_record_mmap2__read_build_id(&event->mmap2, args->machine, false);
>  	} else {
> -		size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
> +		const char *long_name = dso__long_name(dso);
> +
> +		size = strlen(long_name);
> +		if (size >= sizeof(event->mmap.filename))
> +			size = sizeof(event->mmap.filename) - 1;
> +
> +		strlcpy(event->mmap.filename, long_name,
> +			sizeof(event->mmap.filename));
> +
> +		aligned_size = PERF_ALIGN(size + 1, sizeof(u64));
>  		event->mmap.header.type = PERF_RECORD_MMAP;
> -		event->mmap.header.size = (sizeof(event->mmap) -
> -					(sizeof(event->mmap.filename) - size));
> -		memset(event->mmap.filename + size, 0, args->machine->id_hdr_size);
> +		event->mmap.header.misc = args->misc;
> +		event->mmap.header.size =
> +			offsetof(struct perf_record_mmap, filename) +
> +			aligned_size;
> +
> +		/* Zero the padding and ID header trailer safely! */
> +		memset(event->mmap.filename + size, 0,
> +		       (aligned_size - size) + args->machine->id_hdr_size);

[Severity: High]
This is a pre-existing issue, but this memset is subject to the same
_FORTIFY_SOURCE abort as the mmap2 case above when the DSO name approaches
PATH_MAX and sample IDs are enabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721173347.9163-1-irogers@google.com?part=3

  reply	other threads:[~2026-07-21 17:47 UTC|newest]

Thread overview: 34+ 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 [this message]
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
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

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=20260721174744.715211F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox