Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 8/8] perf sched: Replace BUG_ON and add NULL checks in replay event helpers
Date: Fri, 05 Jun 2026 20:46:08 +0000	[thread overview]
Message-ID: <20260605204609.23ED41F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605203316.1758661-9-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Heap buffer overflow in register_pid() due to unbounded strcpy() from untrusted input.
--

commit d49e324b240110a80380fd996077045c127efafa
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf sched: Replace BUG_ON and add NULL checks in replay event helpers

This commit replaces BUG_ON() calls with graceful error handling and adds
missing NULL checks for memory allocations in the perf sched replay helpers.
It ensures the tool returns early instead of crashing when processing
untrusted perf.data input that triggers memory exhaustion.

>     get_new_event() has three issues:
>     
>     1. The zalloc() result is dereferenced without a NULL check, crashing
>        on allocation failure.
>     
>     2. BUG_ON(!task->atoms) kills the process when realloc() fails.
>        Since perf.data is untrusted input, this should be a graceful error.

[Severity: Critical]
This is a pre-existing issue, but since perf.data is treated as untrusted
input, does register_pid() have a heap buffer overflow?

When register_pid() allocates a new task_desc, it blindly copies the comm
parameter into a fixed-size buffer:

tools/perf/builtin-sched.c:register_pid() {
	...
	task = zalloc(sizeof(*task));
	task->pid = pid;
	task->nr = sched->nr_tasks;
	strcpy(task->comm, comm);
	...
}

If a crafted perf.data file supplies a trace event containing a comm
string significantly longer than the task->comm array (typically 16 bytes),
could this unbounded strcpy() overflow the buffer and overwrite subsequent
struct fields like nr_events or the atoms array pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260605203316.1758661-1-acme@kernel.org?part=8

      reply	other threads:[~2026-06-05 20:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 20:33 [PATCHES v1 0/8] perf tools: Fix OOB writes, refcount bugs, and BUG_ON in mmap/stat/c2c/sched Arnaldo Carvalho de Melo
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 [this message]

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=20260605204609.23ED41F00893@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox