Skip to content

perf tools: Fix OOB reads, reference leaks, and overflow in sched/script/auxtrace

Arnaldo Carvalho de Melo linux-perf-users lkml sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5perf tools: Guard remaining test_bit calls from OOB sample CPUtools/perf/builtin-script.c tools/perf/util/auxtrace.c+3 -20 replies
2/5perf tools: Add bounds check to cpu__get_node()tools/perf/util/cpumap.c+4 -01 reply
3/5perf sched: Fix thread reference leaks in timehist_get_thread()tools/perf/builtin-sched.c+7 -10 replies
4/5perf sched: Cap max_cpu at MAX_CPUS in timehist sample processingtools/perf/builtin-sched.c+5 -32 replies
5/5perf sched: Fix register_pid() overflow, strcpy, and BUG_ONtools/perf/builtin-sched.c+30 -100 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchDavid Ahern
1/5
2/5
3/5
4/5R-b
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCHES v1 0/5] perf tools: Fix OOB reads, reference leaks, and overflow in sched/script/auxtrace

Hi,

Five more pre-existing bugs found by sashiko-bot during AI-assisted review of the perf-data-validation hardening series. All are independent of that series -- they are latent bugs in surrounding code exposed during review.

1. test_bit(cpu, cpu_bitmap) reads out of bounds in auxtrace.c:filter_cpu() and builtin-script.c:filter_cpu() when the CPU value is negative or >= MAX_NR_CPUS. Same class of bug fixed in the previous series for annotate, diff, report, and sched.

2. cpu__get_node() in cpumap.c indexes cpunode_map[] without bounds checking against max_cpu_num. Callers like builtin-kmem pass untrusted sample->cpu from perf.data.

3. Thread reference leaks in perf sched timehist_get_thread() -- two error paths and the success path in the idle_hist block fail to release thread references acquired via machine__findnew_thread() and get_idle_thread().

4. sched->max_cpu updated from sample->cpu without bounds checking in perf_timehist__process_sample(). Later code uses max_cpu + 1 as iteration count over arrays allocated with MAX_CPUS entries. Also caps the env->nr_cpus_online initialization.

5. register_pid() in perf sched replay has integer overflow on 32-bit (pid * sizeof wraps), strcpy into fixed 20-byte buffer without length check, BUG_ON on allocation failure, and unsafe realloc pattern that leaks on failure.

All require crafted or unusual perf.data inputs to trigger. Verified with gcc and clang builds, checkpatch, and perf test.

Arnaldo Carvalho de Melo (5):
perf tools: Guard remaining test_bit calls from OOB sample CPU perf tools: Add bounds check to cpu__get_node()
perf sched: Fix thread reference leaks in timehist_get_thread() perf sched: Cap max_cpu at MAX_CPUS in timehist sample processing perf sched: Fix register_pid() overflow, strcpy, and BUG_ON

 tools/perf/builtin-sched.c  | 56 +++++++++++++++++++++++++++++++++------------
 tools/perf/builtin-script.c |  2 +-
 tools/perf/util/auxtrace.c  |  3 ++-
 tools/perf/util/cpumap.c    |  4 ++++
 4 files changed, 49 insertions(+), 16 deletions(-)

Developed with AI assistance (Claude/sashiko), tagged in commits.

Thanks,

- Arnaldo