From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Namhyung Kim <namhyung@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
linux-perf-users@vger.kernel.org, Ben Gainey <ben.gainey@arm.com>,
Dmitry Vyukov <dvyukov@google.com>,
Blake Jones <blakejones@google.com>,
Chun-Tse Shao <ctshao@google.com>,
Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>
Subject: Re: [PATCH] tools: perf: session: avoid segfault on implicit stdin
Date: Fri, 12 Sep 2025 16:19:32 -0300 [thread overview]
Message-ID: <aMRyRNjEKoKeRXzY@x1> (raw)
In-Reply-To: <20250826001651.299560-1-stephen.s.brennan@oracle.com>
On Mon, Aug 25, 2025 at 05:16:48PM -0700, Stephen Brennan wrote:
> A user reported that running a command like:
>
> perf script flamegraph -ag -F99 -- sleep 10
>
> Resulted in a segmentation fault. The reason is twofold. First, the
> "flamegraph-report" script has a shebang line which ends with "--". This
> disables option parsing, so that the exec'd "perf script report" command
> does not see the option "-i -" which is appended to its command line.
> Second, despite the unprocessed "-i -" option, the default behavior of
> perf is to use stdin if it is a pipe -- and in this case, it is. Thus, the
> report continues running, but segfaults on accessing the filename.
>
> The fix for the second issue is a simple NULL check. Implement this
> here.
I did a test before and after and the problem is indeed present:
root@number:~# perf script flamegraph -ag -F99 -- sleep 1
/home/acme/libexec/perf-core/scripts/python/bin/flamegraph-report: line 3: 362975 Segmentation fault (core dumped) perf script -s "$PERF_EXEC_PATH"/scripts/python/flamegraph.py "$@"
root@number:~#
But even after your patch, it still segfaults.
I'll try to look at this after processing lower hanging patches.
Thanks for working on this!
- Arnaldo
> Fixes: 4553c431e7dd2 ("perf report: Display pregress bar on redirected pipe data")
>
> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
> ---
> tools/perf/util/session.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 26ae078278cd6..a9624505c0ca3 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -1854,9 +1854,11 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
> /*
> * If it's from a file saving pipe data (by redirection), it would have
> * a file name other than "-". Then we can get the total size and show
> - * the progress.
> + * the progress. However, be careful because path may be NULL if input
> + * is coming from stdin.
> */
> - if (strcmp(session->data->path, "-") && session->data->file.size) {
> + if (session->data->path && strcmp(session->data->path, "-")
> + && session->data->file.size) {
> ui_progress__init_size(&prog, session->data->file.size,
> "Processing events...");
> update_prog = true;
> --
> 2.47.3
prev parent reply other threads:[~2025-09-12 19:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 0:16 [PATCH] tools: perf: session: avoid segfault on implicit stdin Stephen Brennan
2025-09-12 19:19 ` Arnaldo Carvalho de Melo [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=aMRyRNjEKoKeRXzY@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ben.gainey@arm.com \
--cc=blakejones@google.com \
--cc=ctshao@google.com \
--cc=dvyukov@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=stephen.s.brennan@oracle.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