From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v5 12/19] perf test cs-etm: Skip if not root
Date: Tue, 09 Jun 2026 16:13:54 +0000 [thread overview]
Message-ID: <20260609161354.DCA1F1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-james-cs-context-tracking-fix-v5-12-d53a7d096a19@linaro.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The script is vulnerable to a TOCTOU symlink attack that allows a local attacker to overwrite arbitrary system files with root privileges.
--
commit 31448575355dfbf022d3a5103f47303bea93bbf4
Author: James Clark <james.clark@linaro.org>
perf test cs-etm: Skip if not root
Use the common idiom for skipping tests if not running as root, which is
required for these tests.
> diff --git a/tools/perf/tests/shell/test_arm_coresight.sh b/tools/perf/tests/shell/test_arm_coresight.sh
> --- a/tools/perf/tests/shell/test_arm_coresight.sh
> +++ b/tools/perf/tests/shell/test_arm_coresight.sh
> @@ -20,6 +20,12 @@ skip_if_no_cs_etm_event() {
>
> skip_if_no_cs_etm_event || exit 2
>
> +if [ "$(id -u)" != 0 ]; then
> + # Requires root for -C and system wide tests
> + echo "[Skip] No root permission"
> + exit 2
> +fi
> +
> perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> file=$(mktemp /tmp/temporary_file.XXXXX)
[Severity: High]
This is a pre-existing issue, but does enforcing root execution expose these
temporary files to a symlink attack?
While the temporary files are securely generated with mktemp in the
world-writable /tmp/ directory, the script breaks these guarantees before
writing to them.
Looking at record_touch_file() in tools/perf/tests/shell/test_arm_coresight.sh:
record_touch_file() {
echo "Recording trace (only user mode) with path: CPU$2 => $1"
rm -f $file
perf record -o ${perfdata} -e cs_etm/@$1/u --per-thread \
-- taskset -c $2 touch $file > /dev/null 2>&1
}
This explicitly deletes the safe file and executes touch as root.
Additionally, looking at arm_cs_etm_system_wide_test():
arm_cs_etm_system_wide_test() {
echo "Recording trace with system wide mode"
perf record -o ${perfdata} -e cs_etm// -a -- ls > /dev/null 2>&1
Successive perf record calls rename the existing ${perfdata} to .old, freeing
the securely generated filename.
In both cases, could a local attacker use inotify to detect the deletion or
rename, and insert a symlink pointing to an arbitrary file (like /etc/shadow)?
Since this patch explicitly enforces the script to run as root, won't
subsequent file operations by perf record (which internally uses open with
O_CREAT | O_RDWR | O_TRUNC without O_NOFOLLOW) follow the symlink and
overwrite system files with root privileges?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-james-cs-context-tracking-fix-v5-0-d53a7d096a19@linaro.org?part=12
next prev parent reply other threads:[~2026-06-09 16:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 14:40 [PATCH v5 00/19] perf cs-etm: Queue context packets for frontend James Clark
2026-06-09 14:40 ` [PATCH v5 01/19] " James Clark
2026-06-09 14:40 ` [PATCH v5 02/19] perf test: Add workload-ctl option James Clark
2026-06-09 14:40 ` [PATCH v5 03/19] perf test: Add a workload that forces context switches James Clark
2026-06-09 14:40 ` [PATCH v5 04/19] perf test cs-etm: Test process attribution James Clark
2026-06-09 14:40 ` [PATCH v5 05/19] perf test: Add deterministic workload James Clark
2026-06-09 14:40 ` [PATCH v5 06/19] perf test cs-etm: Replace unroll loop thread with deterministic decode test James Clark
2026-06-09 17:04 ` Leo Yan
2026-06-09 14:40 ` [PATCH v5 07/19] perf test cs-etm: Remove asm_pure_loop test James Clark
2026-06-09 14:40 ` [PATCH v5 08/19] perf test cs-etm: Replace memcpy test with raw dump stress test James Clark
2026-06-09 17:16 ` Leo Yan
2026-06-09 14:40 ` [PATCH v5 09/19] perf test: Add named_threads workload James Clark
2026-06-09 16:00 ` sashiko-bot
2026-06-09 14:40 ` [PATCH v5 10/19] perf test cs-etm: Test decoding for concurrent threads test James Clark
2026-06-09 17:18 ` Leo Yan
2026-06-09 14:40 ` [PATCH v5 11/19] perf test cs-etm: Remove duplicate branch tests James Clark
2026-06-09 14:40 ` [PATCH v5 12/19] perf test cs-etm: Skip if not root James Clark
2026-06-09 16:13 ` sashiko-bot [this message]
2026-06-09 14:40 ` [PATCH v5 13/19] perf test cs-etm: Reduce snapshot size James Clark
2026-06-09 14:40 ` [PATCH v5 14/19] perf test cs-etm: Speed up basic test James Clark
2026-06-09 14:40 ` [PATCH v5 15/19] perf test cs-etm: Remove unused Coresight workloads James Clark
2026-06-09 17:22 ` Leo Yan
2026-06-09 14:40 ` [PATCH v5 16/19] perf test cs-etm: Make disassembly test use kcore James Clark
2026-06-09 14:40 ` [PATCH v5 17/19] perf test cs-etm: Add all branch instructions to test James Clark
2026-06-09 14:40 ` [PATCH v5 18/19] perf test cs-etm: Speed up disassembly test James Clark
2026-06-09 16:48 ` sashiko-bot
2026-06-09 14:40 ` [PATCH v5 19/19] perf test cs-etm: Move existing tests to coresight folder James Clark
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=20260609161354.DCA1F1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=james.clark@linaro.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