lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aMRyRNjEKoKeRXzY@x1>
Date: Fri, 12 Sep 2025 16:19:32 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Stephen Brennan <stephen.s.brennan@...cle.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
	Namhyung Kim <namhyung@...nel.org>, Ingo Molnar <mingo@...hat.com>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Andi Kleen <ak@...ux.intel.com>, linux-kernel@...r.kernel.org,
	Mark Rutland <mark.rutland@....com>,
	"Liang, Kan" <kan.liang@...ux.intel.com>,
	linux-perf-users@...r.kernel.org, Ben Gainey <ben.gainey@....com>,
	Dmitry Vyukov <dvyukov@...gle.com>,
	Blake Jones <blakejones@...gle.com>,
	Chun-Tse Shao <ctshao@...gle.com>, Ian Rogers <irogers@...gle.com>,
	Jiri Olsa <jolsa@...nel.org>,
	Adrian Hunter <adrian.hunter@...el.com>
Subject: Re: [PATCH] tools: perf: session: avoid segfault on implicit stdin

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@...ber:~# 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@...ber:~# 

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@...cle.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ