From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 2/5] perf header: Validate string length before allocating in do_read_string()
Date: Wed, 15 Apr 2026 21:14:21 -0300 [thread overview]
Message-ID: <20260416001424.362797-3-acme@kernel.org> (raw)
In-Reply-To: <20260416001424.362797-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
do_read_string() reads a u32 length from the file and immediately
allocates that many bytes. A crafted perf.data could claim a huge
string length, triggering a large allocation that would only be freed
moments later when __do_read() rejects the read against the section
bounds.
Check len against the remaining section size before the malloc().
Cc: Ian Rogers <irogers@google.com>
Assisted-by: Claude Code:claude-opus-4-6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 3 +++
1 file changed, 3 insertions(+)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 13bbf8df15f66cab..c27ed90727ea6629 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -269,6 +269,9 @@ static char *do_read_string(struct feat_fd *ff)
if (do_read_u32(ff, &len))
return NULL;
+ if (len > ff->size - ff->offset)
+ return NULL;
+
buf = malloc(len);
if (!buf)
return NULL;
--
2.53.0
next prev parent reply other threads:[~2026-04-16 0:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 0:14 [PATCHES 0/5 v2] More perf.data header validation Arnaldo Carvalho de Melo
2026-04-16 0:14 ` [PATCH 1/5] perf header: Add section bounds checking to the fd read path Arnaldo Carvalho de Melo
2026-04-16 0:59 ` sashiko-bot
2026-04-16 14:43 ` Arnaldo Carvalho de Melo
2026-04-16 0:14 ` Arnaldo Carvalho de Melo [this message]
2026-04-16 0:14 ` [PATCH 3/5] perf header: Sanity check HEADER_EVENT_DESC Arnaldo Carvalho de Melo
2026-04-16 1:54 ` sashiko-bot
2026-04-16 15:11 ` Arnaldo Carvalho de Melo
2026-04-16 0:14 ` [PATCH 4/5] perf header: Validate bitmap size before allocating in do_read_bitmap() Arnaldo Carvalho de Melo
2026-04-16 2:25 ` sashiko-bot
2026-04-16 15:26 ` Arnaldo Carvalho de Melo
2026-04-16 0:14 ` [PATCH 5/5] perf header: Fix 32-bit incompatibility in bitmap serialization Arnaldo Carvalho de Melo
2026-04-16 13:17 ` [PATCHES 0/5 v2] More perf.data header validation James Clark
2026-04-16 15:28 ` Arnaldo Carvalho de Melo
2026-04-16 16:46 ` Namhyung Kim
2026-04-16 19:35 ` Arnaldo Carvalho de Melo
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=20260416001424.362797-3-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.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.