From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: [PATCHES v1 0/8] perf tools: Fix OOB writes, refcount bugs, and BUG_ON in mmap/stat/c2c/sched
Date: Fri, 5 Jun 2026 17:33:08 -0300 [thread overview]
Message-ID: <20260605203316.1758661-1-acme@kernel.org> (raw)
Hi,
Eight 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. perf_mmap__aio_bind() passes cpu__get_node() return value to an
unsigned long. When -1 is returned, sign-extension to ULONG_MAX
causes bitmap_zalloc(0) and a massive OOB __set_bit.
2. Six perf_env__get_*_aggr_by_cpu() topology aggregation callbacks
in builtin-stat.c access env->cpu[cpu.cpu] after only checking
cpu.cpu != -1. A CPU index from untrusted perf.data exceeding
env->nr_cpus_avail causes OOB heap reads.
3. perf c2c: __set_bit on cpuset/nodeset bitmaps without bounds
checking sample->cpu and node IDs against their allocation sizes.
Also, cpu2node[] array accessed without upper bound check.
4. perf c2c: setup_nodes() iterates CPU maps from perf.data topology
and uses cpu.cpu directly as index into cpu2node[] and __set_bit
without validating against nr_cpus_avail.
5. get_idle_thread() leaves a partially initialized thread in
idle_threads[] when init_idle_thread() fails, causing subsequent
calls to return a thread with no priv data -- later cast to a
larger struct causes OOB writes.
6. timehist_sched_change_event() sets itr->last_thread to NULL
without calling thread__put() first, leaking a thread reference
on every idle context switch with --idle-hist.
7. free_idle_threads() calls thread__delete() directly instead of
thread__put(), bypassing the refcount lifecycle.
8. get_new_event() dereferences unchecked zalloc() result and uses
BUG_ON on realloc failure. add_sched_event_wakeup() passes
unchecked zalloc() to sem_init(). All crash on OOM with
untrusted input.
All require crafted or unusual perf.data inputs to trigger.
Verified with gcc and clang builds, checkpatch, and perf test.
Arnaldo Carvalho de Melo (8):
perf mmap: Guard cpu__get_node() return in aio_bind()
perf stat: Bounds-check CPU index in topology aggregation callbacks
perf c2c: Bounds-check CPU and node IDs before bitmap and array access
perf c2c: Bounds-check CPU IDs in setup_nodes() topology loop
perf sched: Clean up idle_threads entry on init failure
perf sched: Fix thread reference leak in idle hist processing
perf sched: Use thread__put() in free_idle_threads()
perf sched: Replace BUG_ON and add NULL checks in replay event helpers
tools/perf/builtin-c2c.c | 23 +++++++++++++++++++++--
tools/perf/builtin-sched.c | 37 +++++++++++++++++++++++++++++++------
tools/perf/builtin-stat.c | 13 +++++++------
tools/perf/util/mmap.c | 8 +++++++-
4 files changed, 66 insertions(+), 15 deletions(-)
Developed with AI assistance (Claude/sashiko), tagged in commits.
Thanks,
- Arnaldo
next reply other threads:[~2026-06-05 20:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 20:33 Arnaldo Carvalho de Melo [this message]
2026-06-05 20:33 ` [PATCH 1/8] perf mmap: Guard cpu__get_node() return in aio_bind() Arnaldo Carvalho de Melo
2026-06-05 20:48 ` sashiko-bot
2026-06-05 20:33 ` [PATCH 2/8] perf stat: Bounds-check CPU index in topology aggregation callbacks Arnaldo Carvalho de Melo
2026-06-05 20:33 ` [PATCH 3/8] perf c2c: Bounds-check CPU and node IDs before bitmap and array access Arnaldo Carvalho de Melo
2026-06-05 20:46 ` sashiko-bot
2026-06-05 20:33 ` [PATCH 4/8] perf c2c: Bounds-check CPU IDs in setup_nodes() topology loop Arnaldo Carvalho de Melo
2026-06-05 20:33 ` [PATCH 5/8] perf sched: Clean up idle_threads entry on init failure Arnaldo Carvalho de Melo
2026-06-05 20:53 ` sashiko-bot
2026-06-05 20:33 ` [PATCH 6/8] perf sched: Fix thread reference leak in idle hist processing Arnaldo Carvalho de Melo
2026-06-05 20:46 ` sashiko-bot
2026-06-05 20:33 ` [PATCH 7/8] perf sched: Use thread__put() in free_idle_threads() Arnaldo Carvalho de Melo
2026-06-05 20:49 ` sashiko-bot
2026-06-05 20:33 ` [PATCH 8/8] perf sched: Replace BUG_ON and add NULL checks in replay event helpers Arnaldo Carvalho de Melo
2026-06-05 20:46 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260605203316.1758661-1-acme@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox