From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v8 02/13] perf scripts: Add a coverage harness for perf
Date: Wed, 18 Nov 2026 22:48:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-222126@kernel.org> (raw)
In-Reply-To: <20261118223725.121500-3-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf scripts: TOCTOU race and chown on untrusted dir in
mkdir_checked()
--
commit 7ab6984627c594b546b3004b18a620f69c6a9e8e
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf scripts: Add a coverage harness for perf
This commit adds a clang source-based coverage script for perf along with
make targets to build, run tests, and report line and function coverage.
> diff --git a/tools/perf/scripts/coverage.sh b/tools/perf/scripts/coverage.sh
> new file mode 100755
> index 0000000000000..4176cdae79e25
> --- /dev/null
> +++ b/tools/perf/scripts/coverage.sh
[ ... ]
> +check_trusted_path()
> +{
> + local path=$1 raw=${2:-$1} leaf=$1 uid gid mode owners=root
> +
> + [ "$TRUST_UID" = 0 ] || owners="root or uid $TRUST_UID"
> + # abspath() resolves links such as /home -> /var/home on Silverblue
> + # and CoreOS, so a link is gone from the resolved path by the time
> + # the walk below sees it; reject one the path as given traversed
> + # that is not root's, since anybody who can write its directory can
> + # retarget the run.
> + while :; do
> + if [ -L "$raw" ]; then
> + if ! read -r uid gid mode < \
> + <(stat -c '%u %g %a' "$raw" 2>/dev/null); then
> + die "could not stat $raw"
> + fi
> + # The mode of a link means nothing, its owner does:
> + # only whoever can write the directory can replace it.
> + [ "$uid" = 0 ] || [ "$uid" = "$TRUST_UID" ] ||
> + die "$raw is a symbolic link owned by uid $uid, not by $owners"
> + fi
> + [ "$raw" = / ] && break
> + raw=$(dirname "$raw")
> + done
[ ... ]
> +mkdir_checked()
> +{
> + local path=$1 parent missing=()
> + while [ ! -d "$path" ]; do
> + missing=("$path" "${missing[@]}")
> + parent=$(dirname "$path")
> + [ "$parent" = "$path" ] && break
> + path=$parent
> + done
> + for path in "${missing[@]+"${missing[@]}"}"; do
> + if mkdir "$path" 2>/dev/null; then
> + MKDIR_CREATED+=("$path")
> + elif [ ! -d "$path" ]; then
> + die "could not create $path"
> + fi
> + done
> + check_trusted_path "$1"
> +}
[ ... ]
> +fix_ownership()
> +{
> + local uid=$TRUST_UID gid=$TRUST_GID path top=
> +
> + [ "$ROOT" = 1 ] && [ "$uid" != 0 ] || return 0
> +
> + for path in "${COV_WRITES[@]}"; do
> + [ -e "$COV_DIR/$path" ] || continue
> + chown -Rh "$uid:$gid" "$COV_DIR/$path" ||
> + warn "could not give $COV_DIR/$path back to uid $uid"
> + done
> + # The directories this run created, in creation order: chowning one
> + # covers everything below it, so skip those.
> + for path in "${MKDIR_CREATED[@]+"${MKDIR_CREATED[@]}"}"; do
> + if [ -n "$top" ]; then
> + case "$path" in "$top"/*) continue ;; esac
> + fi
> + chown -Rh "$uid:$gid" "$path" ||
> + warn "could not give $path back to uid $uid"
> + top=$path
> + done
[Severity: Low]
Can an unprivileged local user race with mkdir_checked() when /tmp/build
does not exist yet and cause fix_ownership() to run chown -Rh on an
untrusted path?
When /tmp/build is absent during the initial check_trusted_path() checks,
only /tmp exists and passes as a root-owned sticky directory. If another
local user creates /tmp/build before mkdir_checked() runs, the creation
loop accepts the existing /tmp/build without checking its owner or
whether it is a symlink, creates child directories such as
/tmp/build/perf-coverage inside it, and appends them to MKDIR_CREATED
before calling check_trusted_path().
When check_trusted_path() then calls die while the EXIT trap is installed
(for example during build_perf() or write_state()), fix_ownership() runs
chown -Rh on the child paths recorded in MKDIR_CREATED inside the
untrusted /tmp/build directory, allowing the owner of /tmp/build to swap
the child directory before chown -Rh runs.
In addition, the raw path walk in check_trusted_path() checks symlink
ownership with [ -L "$raw" ] but does not verify the ownership and write
permissions of the parent directory holding the symlink before abspath()
resolves that parent away.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118223725.121500-1-acme@kernel.org?part=2
next prev parent reply other threads:[~2026-11-18 22:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 22:37 [PATCH v8 00/13] perf coverage: A harness for perf, and the fixes it found Arnaldo Carvalho de Melo
2026-11-18 22:37 ` [PATCH v8 01/13] perf build: Link the jvmti agent and the GTK UI with EXTRA_CFLAGS Arnaldo Carvalho de Melo
2026-11-18 22:42 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 02/13] perf scripts: Add a coverage harness for perf Arnaldo Carvalho de Melo
2026-11-18 22:48 ` sashiko-bot [this message]
2026-11-18 22:37 ` [PATCH v8 03/13] perf annotate: Handle absolute addressing in data type profiling Arnaldo Carvalho de Melo
2026-11-18 22:49 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 04/13] perf tests: Exercise DW_OP_addrx global variables Arnaldo Carvalho de Melo
2026-11-18 22:52 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 05/13] perf tests: Exercise the flexible array member path Arnaldo Carvalho de Melo
2026-11-18 22:42 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 06/13] perf annotate-data: Count flexible array accesses for the whole struct Arnaldo Carvalho de Melo
2026-11-18 22:43 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 07/13] perf tests: Exercise data type resolution from a register Arnaldo Carvalho de Melo
2026-11-18 22:42 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 08/13] perf annotate: Print the stats after the annotations Arnaldo Carvalho de Melo
2026-11-18 22:42 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 09/13] perf tests: Silence the libbfd probe in build-test Arnaldo Carvalho de Melo
2026-11-18 22:41 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 10/13] perf build: Record the features checked outside FEATURE_TESTS Arnaldo Carvalho de Melo
2026-11-18 22:44 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 11/13] perf tests: Fix the Intel PT virtual LBR check Arnaldo Carvalho de Melo
2026-11-18 22:43 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 12/13] perf test: Drop samples without an IP in the dlfilter test Arnaldo Carvalho de Melo
2026-11-18 22:43 ` sashiko-bot
2026-11-18 22:37 ` [PATCH v8 13/13] perf test: Skip the LBR inline unwinding check when unsupported Arnaldo Carvalho de Melo
2026-11-18 22:44 ` 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=sashiko-outbox-222126@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