Skip to content

perf: Fix and optimize maps parsing, boundaries, and bounds safety

Ian Rogers linux-perf-users lkml 7 versions – Applied

Status from this message: Applied to perf-tools-next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest5 patches 2 repliesApplied
  2. v64 patches 0 repliesSuperseded
  3. v54 patches 0 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v44 patches0 repliesSuperseded
v34 patches0 repliesSuperseded
v24 patches0 repliesSuperseded
v14 patches0 repliesSuperseded

Patches in v7 Applied

#Subject and filesSizeRepliesApplied
1/5perf find-map: Remove PATH_MAX 128-byte stack array restrictiontools/perf/util/find-map.c+8 -20 replies
2/5perf synthetic-events: Fix line synchronization, bounds, and truncation bugs in proc maps readertools/perf/util/synthetic-events.c+142 -620 replies
3/5perf synthetic-events: Fix stack buffer overflow and bounds in cgroup synthesistools/perf/util/synthetic-events.c+13 -60 replies
4/5perf synthetic-events: Fix bounds, stale state, and misc flags in kernel module synthesistools/perf/util/synthetic-events.c+50 -200 replies
5/5perf synthetic-events: Fix bounds and union member access in mmap2 build_id synthesistools/perf/util/synthetic-events.c+12 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 0/5] perf: Fix and optimize maps parsing, boundaries, and bounds safety

It turns out that PATH_MAX is respected by system calls but isn't respected by file paths in /proc/pid/maps and /proc/pid/smaps. In the kernel "//toolong" is placed in the filename of mmap/mmap2 events where the filename is longer than PATH_MAX, do the same in the mmap/mmap2 synthesis code to avoid overrunning the event buffer - note, the filename buffer is bounds checked but this makes the synthesis more similar to the kernel approach. With Gemini's help try to address other correctness and overrun issues.

V7 addresses security review feedback:
- Adds a standalone patch (Patch 3/5) to fix a pre-existing stack buffer overflow in perf_event__synthesize_cgroup(). Eliminates in-place null padding mutation of the path stack buffer, calculates aligned path_len using PERF_ALIGN, clamps raw_path_len to account for machine->id_hdr_size, and uses strlcpy with combined memset for alignment and sample ID header padding.

V6 addresses review feedback:
- Ensures Patch 2 leaves module synthesis callbacks completely untouched, preserving the pre-existing build ID clearing logic in baseline.
- Patch 4 explicitly clears PERF_RECORD_MISC_MMAP_BUILD_ID, build_id, and reserved union padding members in module synthesis callbacks to guarantee no stale Build-ID state leaks between module synthesis iterations.

V5 addresses technical review feedback:
- Clamps pathname buffer sizes in read_proc_maps_line() and module synthesis callbacks by subtracting machine->id_hdr_size.
- Casts member array memset destination pointers to
(char *)event + offsetof(...) across all synthesis handlers.
- Restricts max_filename_len in perf_event__synthesize_mmap2_build_id() to the minimum of filename array capacity and union payload space.

V4 addresses review feedback:
- Ensures io__drain_line()'s do-while loop is committed directly in Patch 2.

V3 addresses review feedback:
- Updates io__drain_line() loop condition from a while loop to a do-while loop.

V2 addresses community review feedback:
- Corrects read_proc_maps_line() and io__drain_line() to safely handle already consumed newlines.
- Restores early exit block for timeouts so TIMEOUT flag is emitted to tools.
- Removes unused assignment to avoid promoting warnings to build errors.

Ian Rogers (5):
perf find-map: Remove PATH_MAX 128-byte stack array restriction perf synthetic-events: Fix line synchronization, bounds, and
truncation bugs in proc maps reader
perf synthetic-events: Fix stack buffer overflow and bounds in cgroup
synthesis
perf synthetic-events: Fix bounds, stale state, and misc flags in
kernel module synthesis
perf synthetic-events: Fix bounds and union member access in mmap2
build_id synthesis

 tools/perf/util/find-map.c         |  10 +-
 tools/perf/util/synthetic-events.c | 309 ++++++++++++++++++++---------
 2 files changed, 223 insertions(+), 96 deletions(-)
Signature · 1 line
2.55.0.229.g6434b31f56-goog