diff options
| author | SeungJu Cheon <suunj1331@gmail.com> | 2026-04-03 01:04:10 +0900 |
|---|---|---|
| committer | Namhyung Kim <namhyung@kernel.org> | 2026-04-02 18:11:24 -0700 |
| commit | 85a9a4abcdc09ee941273c99d3ad0bc2ddef09ea (patch) | |
| tree | 2995c7457f0cc408e5a78457b0fa9e504d1ca242 /tools/perf/util | |
| parent | e0f4767bf403131f7ec7378d0d23ad6c29b01936 (diff) | |
perf header: Validate build_id filename length to prevent buffer overflow
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. Print a
warning message when invalid length is detected.
Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/util')
| -rw-r--r-- | tools/perf/util/header.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 9142a8ba4019..9ffc0f4ca6d1 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2545,6 +2545,11 @@ 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) { + pr_warning("invalid build_id filename length %zd\n", len); + return -1; + } + if (readn(input, filename, len) != len) return -1; @@ -2587,6 +2592,11 @@ 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) { + pr_warning("invalid build_id filename length %zd\n", len); + goto out; + } + if (readn(input, filename, len) != len) goto out; /* |
