From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 7/8] perf sched: Replace BUG_ON on invalid CPU with graceful skip
Date: Wed, 03 Jun 2026 01:16:06 +0000 [thread overview]
Message-ID: <20260603011606.86CA41F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260602235709.1541603-8-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Pre-existing NULL pointer dereference when machine__findnew_thread fails in latency_runtime_event.
- [High] Missing `thread__put()` for `sched_out` and `sched_in` on the error path of `add_sched_out_event()`.
- [High] Missing bounds check on `sample->cpu` causes out-of-bounds reads in `test_bit()` across multiple perf tools.
--
commit a94415fdfe25f82cda0feb4b93da07a2fcbbe10d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf sched: Replace BUG_ON on invalid CPU with graceful skip
This commit replaces BUG_ON assertions for invalid sample CPUs with graceful
skips and warnings in latency_switch_event(), latency_runtime_event(), and
map_switch_event(). It handles cases where PERF_SAMPLE_CPU is absent and
initialized to (u32)-1 by evsel__parse_sample().
> The central CPU validation in perf_session__deliver_event() intentionally
> preserves the (u32)-1 sentinel for downstream tools like perf script
> and perf inject, so leaf callbacks must handle it themselves.
[Severity: High]
This isn't a regression introduced by this patch, but do other leaf callbacks
properly handle the (u32)-1 sentinel when using the --cpu list option?
In process_sample_event() in tools/perf/builtin-annotate.c:
if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
goto out_put;
And similarly in hist_iter_cb_cmp() in tools/perf/builtin-diff.c:
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) {
return -1;
}
And in process_sample_event() in tools/perf/builtin-report.c:
if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
goto out_put;
If sample->cpu is (u32)-1, could passing this to test_bit() compute an invalid
bit offset and cause a deterministic out-of-bounds read and segmentation fault?
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 9ec8e049e19b0..81833d1694705 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -1145,7 +1145,12 @@ static int latency_switch_event(struct perf_sched *sched,
> int cpu = sample->cpu, err = -1;
> s64 delta;
>
> - BUG_ON(cpu >= MAX_CPUS || cpu < 0);
> + /* perf.data is untrusted input — CPU may be absent or corrupted */
> + if (cpu >= MAX_CPUS || cpu < 0) {
> + pr_warning("WARNING: at offset %#" PRIx64 ": out-of-bound sample CPU %d, skipping sample\n",
> + sample->file_offset, cpu);
> + return 0;
> + }
[Severity: High]
This isn't a regression introduced by this patch, but does the error path for
add_sched_out_event() further down in latency_switch_event() leak thread
references?
If machine__findnew_thread() successfully acquires references for sched_out and
sched_in, and we later fail here:
if (add_sched_out_event(out_events, prev_state, timestamp))
return -1;
Could returning -1 directly bypass the thread__put() cleanup sequence at the
out_put label and leak the thread objects?
[ ... ]
> @@ -1215,7 +1220,13 @@ static int latency_runtime_event(struct perf_sched *sched,
> if (thread == NULL)
> return -1;
[Severity: High]
This isn't a regression introduced by this patch, but could this cause a null
pointer dereference before the validation check is reached?
At the start of latency_runtime_event(), atoms is initialized by passing
thread to thread_atoms_search():
struct thread *thread = machine__findnew_thread(machine, -1, pid);
struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread,
&sched->cmp_pid);
...
if (thread == NULL)
return -1;
If machine__findnew_thread() fails and returns null, would thread_atoms_search()
dereference the null pointer before we reach this validation check?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260602235709.1541603-1-acme@kernel.org?part=7
next prev parent reply other threads:[~2026-06-03 1:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 23:56 [PATCHES 0/8] perf tools: Diagnostic offsets in skip messages + two hardening fixes Arnaldo Carvalho de Melo
2026-06-02 23:57 ` [PATCH 1/8] perf sample: Add file_offset field to struct perf_sample Arnaldo Carvalho de Melo
2026-06-03 15:11 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 2/8] perf session: Include file offset in event skip/stop messages Arnaldo Carvalho de Melo
2026-06-03 15:12 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 3/8] perf sched: Include file offset in event skip messages Arnaldo Carvalho de Melo
2026-06-03 15:13 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 4/8] perf timechart: Include file offset in CPU bounds check messages Arnaldo Carvalho de Melo
2026-06-03 0:36 ` sashiko-bot
2026-06-03 15:14 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 5/8] perf tools: Include file offset and event type name in skip messages Arnaldo Carvalho de Melo
2026-06-03 15:14 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 6/8] perf timechart: Fix cat_backtrace() use-after-free on corrupted callchain Arnaldo Carvalho de Melo
2026-06-03 15:16 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 7/8] perf sched: Replace BUG_ON on invalid CPU with graceful skip Arnaldo Carvalho de Melo
2026-06-03 1:16 ` sashiko-bot [this message]
2026-06-03 15:17 ` Ian Rogers
2026-06-02 23:57 ` [PATCH 8/8] perf test: Add file offset diagnostic test for corrupted perf.data Arnaldo Carvalho de Melo
2026-06-03 1:32 ` sashiko-bot
2026-06-03 15:19 ` Ian Rogers
2026-06-03 15:06 ` [PATCHES 0/8] perf tools: Diagnostic offsets in skip messages + two hardening fixes Ian Rogers
2026-06-03 19:27 ` Arnaldo Carvalho de Melo
2026-06-03 19:44 ` Ian Rogers
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=20260603011606.86CA41F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.