[PATCH v2 0/2] perf evsel: Validate cross-endian samples before byte swapping
From: Mark Amirkan via B4 Relay
Date: Thu Sep 03 2026 - 07:12:29 EST
Two paths in __evsel__parse_sample() use values from an
opposite-endian perf.data record to modify the record before checking that
the data fits within event->header.size.
Patch 1 checks the complete branch stack before swapping entry flags.
Patch 2 checks the RAW payload and the complete 64-bit words touched by
mem_bswap_64() before swapping the data.
The malformed branch-stack and RAW records reproduce as out-of-bounds
reads and writes. Each patch adds a Sample parsing regression test that
checks rejected records do not modify data past the declared event.
Signed-off-by: Mark Amirkan <markdamirkan@xxxxxxxxx>
---
Changes in v2:
- Add the adjacent PERF_SAMPLE_RAW fix found during v1 review.
- Keep the branch-stack fix unchanged.
- Link to v1: https://patch.msgid.link/20260903-sympwn-linux-002-final-v2-v1-1-7c6e4166b814@xxxxxxxxx
To: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: Ingo Molnar <mingo@xxxxxxxxxx>
To: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
To: Namhyung Kim <namhyung@xxxxxxxxxx>
To: Mark Rutland <mark.rutland@xxxxxxx>
To: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
To: Jiri Olsa <jolsa@xxxxxxxxxx>
To: Ian Rogers <irogers@xxxxxxxxxx>
To: Adrian Hunter <adrian.hunter@xxxxxxxxx>
To: James Clark <james.clark@xxxxxxxxxx>
Cc: linux-perf-users@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
Mark Amirkan (2):
perf evsel: Validate branch stack before byte swapping
perf evsel: Validate RAW sample before byte swapping
tools/perf/tests/sample-parsing.c | 109 ++++++++++++++++++++++++++++++++++++++
tools/perf/util/evsel.c | 20 +++----
2 files changed, 120 insertions(+), 9 deletions(-)
---
base-commit: aadea57f532882d8bab444646863c7ef8a778ff1
change-id: 20260903-sympwn-linux-002-final-v2-e30a8df210c1
Best regards,
--
Mark Amirkan <markdamirkan@xxxxxxxxx>