* [PATCH] perf header: Validate build_id filename length to prevent buffer overflow
@ 2026-02-06 8:37 SeungJu Cheon
2026-04-01 20:48 ` Ian Rogers
0 siblings, 1 reply; 2+ messages in thread
From: SeungJu Cheon @ 2026-02-06 8:37 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, linux-perf-users, linux-kernel, SeungJu Cheon
The build_id parsing functions calculate a filename length from the
event header size and read directly into a stack buffer of PATH_MAX
bytes without bounds checking. A malformed perf.data file with a
crafted header.size can cause the length to be negative or exceed
PATH_MAX, resulting in a stack buffer overflow.
Add bounds checking for the filename length in both
perf_header__read_build_ids() and the ABI quirk variant.
Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
---
| 6 ++++++
1 file changed, 6 insertions(+)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index f5cad377c99e..208ccaa62399 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2335,6 +2335,9 @@ static int perf_header__read_build_ids_abi_quirk(struct perf_header *header,
perf_event_header__bswap(&old_bev.header);
len = old_bev.header.size - sizeof(old_bev);
+ if (len < 0 || len >= PATH_MAX)
+ return -1;
+
if (readn(input, filename, len) != len)
return -1;
@@ -2377,6 +2380,9 @@ static int perf_header__read_build_ids(struct perf_header *header,
perf_event_header__bswap(&bev.header);
len = bev.header.size - sizeof(bev);
+ if (len < 0 || len >= PATH_MAX)
+ goto out;
+
if (readn(input, filename, len) != len)
goto out;
/*
--
2.52.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] perf header: Validate build_id filename length to prevent buffer overflow
2026-02-06 8:37 [PATCH] perf header: Validate build_id filename length to prevent buffer overflow SeungJu Cheon
@ 2026-04-01 20:48 ` Ian Rogers
0 siblings, 0 replies; 2+ messages in thread
From: Ian Rogers @ 2026-04-01 20:48 UTC (permalink / raw)
To: SeungJu Cheon
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, linux-perf-users, linux-kernel
On Fri, Feb 6, 2026 at 12:37 AM SeungJu Cheon <suunj1331@gmail.com> wrote:
>
> The build_id parsing functions calculate a filename length from the
> event header size and read directly into a stack buffer of PATH_MAX
> bytes without bounds checking. A malformed perf.data file with a
> crafted header.size can cause the length to be negative or exceed
> PATH_MAX, resulting in a stack buffer overflow.
>
> Add bounds checking for the filename length in both
> perf_header__read_build_ids() and the ABI quirk variant.
Lgtm, could we print errors when these conditions occur?
Thanks,
Ian
> Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
> ---
> tools/perf/util/header.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index f5cad377c99e..208ccaa62399 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -2335,6 +2335,9 @@ static int perf_header__read_build_ids_abi_quirk(struct perf_header *header,
> perf_event_header__bswap(&old_bev.header);
>
> len = old_bev.header.size - sizeof(old_bev);
> + if (len < 0 || len >= PATH_MAX)
> + return -1;
> +
> if (readn(input, filename, len) != len)
> return -1;
>
> @@ -2377,6 +2380,9 @@ static int perf_header__read_build_ids(struct perf_header *header,
> perf_event_header__bswap(&bev.header);
>
> len = bev.header.size - sizeof(bev);
> + if (len < 0 || len >= PATH_MAX)
> + goto out;
> +
> if (readn(input, filename, len) != len)
> goto out;
> /*
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-01 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-06 8:37 [PATCH] perf header: Validate build_id filename length to prevent buffer overflow SeungJu Cheon
2026-04-01 20:48 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®