[PATCHES perf-tools-next v2 00/13] Sanity check perf.data headers

Arnaldo Carvalho de Melo posted 13 patches 2 months, 1 week ago
tools/perf/util/header.c | 220 +++++++++++++++++++++++++++++++++++++--
1 file changed, 214 insertions(+), 6 deletions(-)
[PATCHES perf-tools-next v2 00/13] Sanity check perf.data headers
Posted by Arnaldo Carvalho de Melo 2 months, 1 week ago
Hi,

        Sashiko recently mentioned the lack of sanity checking headers
in perf.data files, that with a fuzzy or maliciously crafted file could
make processing a perf.data file cause deleterious results.

        Add sanity checks and some arbitrarily generous upper limits to
headers, if some are found to be questionable, lets tweak them in
upcoming versions of this patchset.

        As registered in the Assisted-by tags in the patches, this was
done using Claude code to speed up development, hopefully no
hallucinations are present.

        I'm also trying to get some of these checks into review-prompts
skills, some of which were already merged, for instance:

  https://github.com/masoncl/review-prompts/commit/2bb2159893ea926e120105416e95629b9ef1508c

- Arnaldo

v2: Addressed some Sashiko comments for v1, some are valid but not
introduced by this patchset and will be addressed in a follow up series.

Arnaldo Carvalho de Melo (13):
  perf header: Validate nr_domains when reading HEADER_CPU_DOMAIN_INFO
  perf header: Bump up the max number of command line args allowed
  perf header: Sanity check HEADER_NRCPUS and HEADER_CPU_DOMAIN_INFO
  perf header: Sanity check HEADER_CPU_TOPOLOGY
  perf header: Sanity check HEADER_NUMA_TOPOLOGY
  perf header: Sanity check HEADER_MEM_TOPOLOGY
  perf header: Sanity check HEADER_PMU_MAPPINGS
  perf header: Sanity check HEADER_GROUP_DESC
  perf header: Sanity check HEADER_CACHE
  perf header: Sanity check HEADER_HYBRID_TOPOLOGY
  perf header: Sanity check HEADER_PMU_CAPS
  perf header: Sanity check HEADER_BPF_PROG_INFO
  perf header: Add sanity checks to HEADER_BPF_BTF processing

 tools/perf/util/header.c | 220 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 214 insertions(+), 6 deletions(-)

-- 
2.53.0
Re: [PATCHES perf-tools-next v2 00/13] Sanity check perf.data headers
Posted by Namhyung Kim 2 months, 1 week ago
On Fri, 10 Apr 2026 19:08:52 -0300, Arnaldo Carvalho de Melo wrote:
>         Sashiko recently mentioned the lack of sanity checking headers
> in perf.data files, that with a fuzzy or maliciously crafted file could
> make processing a perf.data file cause deleterious results.
> 
>         Add sanity checks and some arbitrarily generous upper limits to
> headers, if some are found to be questionable, lets tweak them in
> upcoming versions of this patchset.
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung
Re: [PATCHES perf-tools-next v2 00/13] Sanity check perf.data headers
Posted by Namhyung Kim 2 months, 1 week ago
Hi Arnaldo,

On Fri, Apr 10, 2026 at 07:08:52PM -0300, Arnaldo Carvalho de Melo wrote:
> Hi,
> 
>         Sashiko recently mentioned the lack of sanity checking headers
> in perf.data files, that with a fuzzy or maliciously crafted file could
> make processing a perf.data file cause deleterious results.
> 
>         Add sanity checks and some arbitrarily generous upper limits to
> headers, if some are found to be questionable, lets tweak them in
> upcoming versions of this patchset.

Yep, I think it's a bit tricky to handle malformed files.  But this
change would defend some of bad inputs.  We can add more later.

> 
>         As registered in the Assisted-by tags in the patches, this was
> done using Claude code to speed up development, hopefully no
> hallucinations are present.

It looks fine.

> 
>         I'm also trying to get some of these checks into review-prompts
> skills, some of which were already merged, for instance:
> 
>   https://github.com/masoncl/review-prompts/commit/2bb2159893ea926e120105416e95629b9ef1508c

Thanks for doing this!
Namhyung