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 v10 8/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck
Date: Sun, 04 Oct 2026 10:30:40 +0000	[thread overview]
Message-ID: <20261004103040.8CBE71F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004102133.26392-9-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf: PID reuse race condition (TOCTOU) allows attaching GDB to arbitrary process
- [Medium] perf: terminal escape sequence injection via unsanitized progress log
--

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

perf scripts: Add perf-stuck, to tell where a running perf is stuck

A perf that takes forever is hard to tell apart from one stuck in a
loop, and there is no way to see where without attaching gdb.
perf-stuck.sh samples a running process' /proc entries and its progress
line at a fixed interval, and with -g runs gdb when no progress is made
across two samples.

> diff --git a/tools/perf/scripts/perf-stuck.sh b/tools/perf/scripts/perf-stuck.sh
> new file mode 100755
> index 0000000000000..0bbcef6c82a4b
> --- /dev/null
> +++ b/tools/perf/scripts/perf-stuck.sh
[ ... ]
> +while :; do
> +	if [ ! -d /proc/"$pid" ]; then
> +		echo "$(date +%T) process gone"
> +		break
> +	fi

[Severity: Medium]
Could this simple directory existence check allow a race condition if the PID
terminates and gets recycled by another process?

If an attacker recycles the PID exactly during the sleep interval, gdb could be
attached to their process unwittingly, exposing the debugging session to
untrusted data when it later runs timeout below.

[ ... ]
> +	# Progress updates overwrite in place, \r separated, so the log is
> +	# one ever longer line: take the last update from a bounded tail
> +	# window and drop the \r's, so printing it doesn't reset the
> +	# terminal cursor on the state line.
> +	progress=
> +	if [ -n "$progress_log" ] && [ -s "$progress_log" ]; then
> +		progress=$(tail -c 8192 -- "$progress_log" | tr '\r\n' '\n\n' | tail -1)
> +	fi

[Severity: Medium]
Should the control characters in this string be explicitly stripped?

The cmdline variable is stripped of control characters, but progress only
replaces carriage returns and newlines.

If an untrusted log is monitored, could this allow terminal escape sequence
injection?

[ ... ]
> +	printf '%s state=%s cpu=+%d (%d.%02ds) rss=%dkB stack=%s %s %s\n' \
> +	       "$(date +%T)" "$state" "$cpu_delta" \
> +	       $(( cpu_delta / hz )) $(( (cpu_delta % hz) * 100 / hz )) \
> +	       "$rss" "$stack_txt" "$stuck_txt" "${progress:-(no progress log)}"

The unsanitized string is written directly to the terminal context here.

> +
> +	if [ -n "$use_gdb" ] && [ -z "$gdb_done" ] && [ "$stuck" -ge 2 ]; then
> +		gdb_log=$(mktemp /tmp/perf-stuck-gdb.XXXXXX)
> +		# The gdb script makes inferior calls, and a call into a perf
> +		# wedged in a loop never returns, so bound the run; SIGINT
> +		# releases the inferior instead of leaving perf stopped.
> +		timeout --signal=INT 30 gdb -p "$pid" -batch -x "$gdb_cmds" -ex bt \
> +		    -ex 'perf-die-chain-all' -ex perf-dso -ex detach > "$gdb_log" 2>&1

This is where gdb could be attached to a recycled PID.

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

  reply	other threads:[~2026-10-04 10:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 10:21 [PATCH v10 0/9] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-10-04 10:21 ` [PATCH v10 1/9] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-10-04 10:33   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 2/9] perf config: Make perf_etc_perfconfig() never return NULL Arnaldo Carvalho de Melo
2026-10-04 10:28   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 3/9] perf mutex: Add DEFINE_MUTEX() static initializer Arnaldo Carvalho de Melo
2026-10-04 10:26   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 4/9] perf mutex: Add DO_ONCE() for one-time initialization Arnaldo Carvalho de Melo
2026-10-04 10:27   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 5/9] perf config: Serialize config file access with a mutex Arnaldo Carvalho de Melo
2026-10-04 10:31   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 6/9] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-10-04 10:28   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 7/9] perf report: Add --no-progress option Arnaldo Carvalho de Melo
2026-10-04 10:29   ` sashiko-bot
2026-10-04 10:21 ` [PATCH v10 8/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-10-04 10:30   ` sashiko-bot [this message]
2026-10-04 10:21 ` [PATCH v10 9/9] perf test: Add false_sharing workload exhibiting cross-CPU false sharing Arnaldo Carvalho de Melo
2026-10-04 10:27   ` 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=20261004103040.8CBE71F000FF@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