Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tanushree Shah" <tshah@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFC PATCH v4 5/5] perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat'
Date: Sat, 22 Aug 2026 06:36:42 +0000	[thread overview]
Message-ID: <20260822063642.7CAA41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260822062729.882005-6-tshah@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Insecure temporary file reuse creates a time-of-check to time-of-use (TOCTOU) race condition and symlink attack vulnerability.
- [Medium] The commit message claims to test the 'cycles' event, but the script uses 'cpu-clock'.
- [Medium] The script leaks a temporary file (`${perfdata}.old`) in `/tmp` because `perf record` automatically backs up the existing non-empty output file.
--

--- Patch [5]: [RFC PATCH v4 5/5] perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat' ---
commit 9c32c2021bfda9ef574a5486cbcea176af233faa
Author: Tanushree Shah <tshah@linux.ibm.com>

perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat'

Add a shell test covering perf data convert --to-trace-dat,
alongside the existing --to-json and --to-ctf tests.

The test:
- skips if perf isn't linked with libtraceevent
- converts a plain sched:sched_switch recording to trace.dat
- converts a pipe-mode recording (perf record -o - | perf data
  convert -i -)
> - converts a recording with both tracepoint and non-tracepoint
>   events (sched:sched_switch,cycles)

[Severity: Medium]
Is this description accurate? The commit message mentions the "cycles"
event, but the code later tests the "cpu-clock" event instead.

- validates the resulting file with trace-cmd report if trace-cmd
  is installed, otherwise falls back to a basic non-empty-file check

Signed-off-by: Tanushree Shah <tshah@linux.ibm.com>

> diff --git a/tools/perf/tests/shell/test_perf_data_converter_tracepoints_trace_dat.sh b/tools/perf/tests/shell/test_perf_data_converter_tracepoints_trace_dat.sh
> new file mode 100755
> index 0000000000000..1c0bce270c389
> --- /dev/null
> +++ b/tools/perf/tests/shell/test_perf_data_converter_tracepoints_trace_dat.sh
> @@ -0,0 +1,173 @@
> +#!/bin/bash
> +# 'perf data convert --to-trace-dat' command test
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright 2026, IBM Corporation
> +# Author: Tanushree Shah <tshah@linux.ibm.com>
> +
> +set -e
> +
> +err=0
> +
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +
> +cleanup()
> +{
> +	rm -f "${perfdata}"

[Severity: Medium]
Does this code leak the backup file created by perf?

When perf record is called a second time in test_trace_converter_mixed_events()
with -o "$perfdata", it detects that the file already exists and has content.
perf record automatically renames the existing file to "${perfdata}.old" before
creating a new one.

Since cleanup() only removes "${perfdata}", does the .old file get left
behind in /tmp?

> +	rm -f "${result}"
> +	trap - exit term int
> +}
> +
[ ... ]
> +test_trace_converter_pipe()
> +{
> +	echo "Testing Perf Data Conversion Command to trace.dat (Pipe mode)"
> +
> +	rm -f "$result"
> +
> +	if ! perf record -e sched:sched_switch -a -o - -- sleep 0.1 | \
> +	   perf data convert --to-trace-dat "$result" --force -i -

[Severity: Medium]
Does this code create a time-of-check to time-of-use race condition?

The script securely creates a temporary file using mktemp, but explicitly
deletes it here with rm -f "$result". 

Since the predictable and unsecured path is then immediately reused for
perf data convert, could a local attacker insert a symlink during this window,
causing perf data convert to overwrite arbitrary files?

> +	then
> +		echo "Perf Data Converter Command to trace.dat (Pipe mode) [FAILED]"
> +		err=1
> +		return
> +	fi
> +
[ ... ]
> +test_trace_converter_mixed_events()
> +{
> +	echo "Testing Perf Data Conversion with tracepoint and non-tracepoint events"
> +
> +	rm -f "$result"
> +
> +	# Record both tracepoint and non-tracepoint events
> +	if ! perf record -e sched:sched_switch,cpu-clock -a -o "$perfdata" -- sleep 0.1
> +	then
> +		echo "Failed to record perf data (mixed events)"
> +		err=1
> +		return
> +	fi
> +
> +	if ! perf data convert --to-trace-dat "$result" --force -i "$perfdata"

[Severity: Medium]
Does this code repeat the symlink race condition mentioned above?

The securely created $result file is again explicitly deleted and its
path is reused here.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260822062729.882005-1-tshah@linux.ibm.com?part=5

      reply	other threads:[~2026-08-22  6:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-22  6:27 [RFC PATCH v4 0/5] Add perf.data tracepoint events to trace.dat conversion Tanushree Shah
2026-08-22  6:27 ` [RFC PATCH v4 1/5] perf/trace-dat: Add trace.dat export infrastructure Tanushree Shah
2026-08-22  6:40   ` sashiko-bot
2026-08-22  6:27 ` [RFC PATCH v4 2/5] perf/trace-event: Write trace.dat metadata sections during parsing Tanushree Shah
2026-08-22  6:44   ` sashiko-bot
2026-08-22  6:27 ` [RFC PATCH v4 3/5] perf data-convert: Add perf.data to trace.dat conversion backend Tanushree Shah
2026-08-22  6:38   ` sashiko-bot
2026-08-22  6:27 ` [RFC PATCH v4 4/5] perf data: Add --to-trace-dat option for converting perf.data tracepoint events into trace.dat format Tanushree Shah
2026-08-22  6:44   ` sashiko-bot
2026-08-22  6:27 ` [RFC PATCH v4 5/5] perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat' Tanushree Shah
2026-08-22  6:36   ` 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=20260822063642.7CAA41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tshah@linux.ibm.com \
    /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