From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, namhyung@kernel.org
Cc: adrian.hunter@intel.com, james.clark@linaro.org,
jolsa@kernel.org, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, mingo@redhat.com,
peterz@infradead.org, ravi.bangoria@amd.com,
swapnil.sapkal@amd.com
Subject: [PATCH v7 3/5] perf synthetic-events: Fix stack buffer overflow and bounds in cgroup synthesis
Date: Tue, 21 Jul 2026 16:52:52 -0700 [thread overview]
Message-ID: <20260721235254.294053-4-irogers@google.com> (raw)
In-Reply-To: <20260721235254.294053-1-irogers@google.com>
Fix a pre-existing stack buffer overflow bug in
perf_event__synthesize_cgroup() where an in-place null padding loop wrote
bytes past the end of the cgrp_root stack array buffer during cgroup tree
traversal. Eliminate in-place path mutation, use PERF_ALIGN for path_len,
clamp raw_path_len to prevent sample ID header trailer overruns, and use
strlcpy with combined zero padding for alignment and sample ID headers.
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/synthetic-events.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 832b74ffb4db..05075840707c 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -635,15 +635,22 @@ static int perf_event__synthesize_cgroup(const struct perf_tool *tool,
struct machine *machine)
{
size_t event_size = sizeof(event->cgroup) - sizeof(event->cgroup.path);
- size_t path_len = strlen(path) - mount_len + 1;
+ size_t raw_path_len, path_len, max_path_len;
struct {
struct file_handle fh;
uint64_t cgroup_id;
} handle;
int mount_id;
- while (path_len % sizeof(u64))
- path[mount_len + path_len++] = '\0';
+ if (strlen(path) < mount_len)
+ return -1;
+
+ max_path_len = sizeof(event->cgroup.path) - machine->id_hdr_size;
+ raw_path_len = strlen(path) - mount_len + 1;
+ if (raw_path_len > max_path_len)
+ raw_path_len = max_path_len;
+
+ path_len = PERF_ALIGN(raw_path_len, sizeof(u64));
memset(&event->cgroup, 0, event_size);
@@ -657,9 +664,9 @@ static int perf_event__synthesize_cgroup(const struct perf_tool *tool,
}
event->cgroup.id = handle.cgroup_id;
- strncpy(event->cgroup.path, path + mount_len, path_len);
- memset((char *)event + offsetof(struct perf_record_cgroup, path) + path_len,
- 0, machine->id_hdr_size);
+ strlcpy(event->cgroup.path, path + mount_len, raw_path_len);
+ memset((char *)event + offsetof(struct perf_record_cgroup, path) + raw_path_len,
+ 0, (path_len - raw_path_len) + machine->id_hdr_size);
if (perf_tool__process_synth_event(tool, event, machine, process) < 0) {
pr_debug("process synth event failed\n");
--
2.55.0.229.g6434b31f56-goog
next prev parent reply other threads:[~2026-07-21 23:53 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
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 ` Ian Rogers [this message]
2026-07-22 0:04 ` [PATCH v7 3/5] perf synthetic-events: Fix stack buffer overflow and bounds in cgroup synthesis 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=20260721235254.294053-4-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=swapnil.sapkal@amd.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 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.