tools/perf/tests/sample-parsing.c | 109 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/evsel.c | 20 +++---- 2 files changed, 120 insertions(+), 9 deletions(-)
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@gmail.com>
---
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@gmail.com
To: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Jiri Olsa <jolsa@kernel.org>
To: Ian Rogers <irogers@google.com>
To: Adrian Hunter <adrian.hunter@intel.com>
To: James Clark <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
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@gmail.com>
On Thu, Sep 3, 2026 at 4:05 AM Mark Amirkan via B4 Relay <devnull+markdamirkan.gmail.com@kernel.org> wrote: > > 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@gmail.com> Reviewed-by: Ian Rogers <irogers@google.com> Thanks, Ian > --- > 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@gmail.com > > To: Peter Zijlstra <peterz@infradead.org> > To: Ingo Molnar <mingo@redhat.com> > To: Arnaldo Carvalho de Melo <acme@kernel.org> > To: Namhyung Kim <namhyung@kernel.org> > To: Mark Rutland <mark.rutland@arm.com> > To: Alexander Shishkin <alexander.shishkin@linux.intel.com> > To: Jiri Olsa <jolsa@kernel.org> > To: Ian Rogers <irogers@google.com> > To: Adrian Hunter <adrian.hunter@intel.com> > To: James Clark <james.clark@linaro.org> > Cc: linux-perf-users@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > > --- > 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@gmail.com> > >
On Thu, Sep 03, 2026 at 01:19:07PM -0700, Ian Rogers wrote: > On Thu, Sep 3, 2026 at 4:05 AM Mark Amirkan via B4 Relay > <devnull+markdamirkan.gmail.com@kernel.org> wrote: > > > > 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@gmail.com> > > Reviewed-by: Ian Rogers <irogers@google.com> Thanks, applied to perf-tools-next, for v7.4. - Arnaldo
© 2016 - 2026 Red Hat, Inc.