From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 07/12] perf tests: Fix flakiness in trace record and replay test
Date: Tue, 16 Jun 2026 01:42:59 +0000 [thread overview]
Message-ID: <20260616014300.6BDBC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616012744.4049193-8-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Deleting a safely created `mktemp` file before reuse creates a Time-Of-Check to Time-Of-Use (TOCTOU) race condition, allowing arbitrary file overwrites.
- [High] The use of a predictable logfile path in `/tmp` combined with unsafe shell redirection allows local attackers to overwrite arbitrary files.
--
commit 9a64d257cf386372ecbfc443356890a8a5a33cd2
Author: Ian Rogers <irogers@google.com>
perf tests: Fix flakiness in trace record and replay test
The perf trace record and replay test fails intermittently on slow or
virtualized hosts because the default recording workload occasionally
completes without scheduling the target nanosleep system calls. Generalize
perf_record_with_retry to support a custom record command prefix via
PERF_RECORD_CMD and retry with scaled sleep durations.
Fixes: 15bcfb96d0dd ("perf test: Add trace record and replay test")
> diff --git a/tools/perf/tests/shell/lib/perf_record.sh b/tools/perf/tests/shell/lib/perf_record.sh
> index c5de252447705..5c7feb294ebbf 100644
> --- a/tools/perf/tests/shell/lib/perf_record.sh
> +++ b/tools/perf/tests/shell/lib/perf_record.sh
> @@ -21,9 +21,14 @@ perf_record_with_retry() {
> local duration
> local first_run=true
> local ret=1
> + local cmd_prefix="perf record"
> + if [ -n "${PERF_RECORD_CMD}" ]; then
> + cmd_prefix="${PERF_RECORD_CMD}"
> + fi
> +
> for duration in 0.01 0.1 0.3 1.0 2.0; do
> rm -f "${perfdata}" "${perfdata}".old
[Severity: High]
Does this rm -f introduce a time-of-check to time-of-use race condition?
In trace_record_replay.sh, the perfdata file is securely created using
mktemp:
tools/perf/tests/shell/trace_record_replay.sh:
file=$(mktemp /tmp/temporary_file.XXXXX)
...
PERF_RECORD_CMD="perf trace record" perf_record_with_retry "${file}" ...
By explicitly deleting this securely created file here in
perf_record_with_retry before executing the command, the script relinquishes
the uniqueness and security guarantees of mktemp.
Since the test enforces running as root, a local attacker monitoring /tmp
could create a symlink with the deleted file's name pointing to an arbitrary
critical system file.
When the perf command later calls open_file_write() in tools/perf/util/data.c
using O_TRUNC and without O_NOFOLLOW, it will follow the symlink and truncate
the attacker's target file.
> - perf record "$@" -o "${perfdata}" ${testprog_base} ${duration} > "$logfile" 2>&1
> + ${cmd_prefix} "$@" -o "${perfdata}" ${testprog_base} ${duration} > "$logfile" 2>&1
[Severity: High]
Could this shell redirection allow for arbitrary file overwrites via symlink
attacks?
This issue was introduced in an earlier patch in this series when
perf_record_with_retry was added. The logfile path is predictable:
tools/perf/tests/shell/lib/perf_record.sh:perf_record_with_retry() {
logfile="/tmp/__perf_record_retry.$(id -u).$BASHPID.log"
}
Since the process ID space is limited, a local attacker could pre-create
symlinks for likely process IDs pointing to sensitive system files.
When the script executes and the shell performs redirection without
noclobber enabled, it will blindly follow the symlink as root and
overwrite the target file.
> local record_exit=$?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260616012744.4049193-1-irogers@google.com?part=7
next prev parent reply other threads:[~2026-06-16 1:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 1:27 [PATCH v1 00/12] perf tests: Enhancements, speedups, and flakiness fixes Ian Rogers
2026-06-16 1:27 ` [PATCH v1 01/12] perf parse-events: Restrict core PMU bypass to --cputype option Ian Rogers
2026-06-16 1:44 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 02/12] perf test: Truncate test description to fit terminal width Ian Rogers
2026-06-16 1:38 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 03/12] perf tests workloads: Support sub-second durations in noploop and thloop Ian Rogers
2026-06-16 1:35 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 04/12] perf tests: Add robust record retry helper and use subsecond workloads Ian Rogers
2026-06-16 1:38 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 05/12] perf tests: Skip metrics validation if system-wide recording lacks permission Ian Rogers
2026-06-16 1:41 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 06/12] perf tests: Fix Python JIT dump profiling test failure Ian Rogers
2026-06-16 1:39 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 07/12] perf tests: Fix flakiness in trace record and replay test Ian Rogers
2026-06-16 1:42 ` sashiko-bot [this message]
2026-06-16 1:27 ` [PATCH v1 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers
2026-06-16 1:35 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 09/12] perf tests: Fix flakiness in branch stack sampling tests Ian Rogers
2026-06-16 1:27 ` [PATCH v1 10/12] perf tests: Speed up off-cpu profiling tests Ian Rogers
2026-06-16 1:41 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 11/12] perf tests: Speed up lock contention analysis shell test Ian Rogers
2026-06-16 1:27 ` [PATCH v1 12/12] perf tests: Speed up metrics checking shell tests Ian Rogers
-- strict thread matches above, loose matches on Subject: below --
2026-06-16 1:25 [PATCH v1 00/12] perf tests: Enhancements, speedups, and flakiness fixes Ian Rogers
2026-06-16 1:25 ` [PATCH v1 07/12] perf tests: Fix flakiness in trace record and replay test 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=20260616014300.6BDBC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--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