Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/5] perf config: Move perf_config__set_variable() to util/config.c
Date: Tue, 29 Sep 2026 20:27:46 +0000	[thread overview]
Message-ID: <20260929202746.913671F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929201524.2507733-2-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: data race in perf_config__set_variable() on static path buffer
--

commit 6edfbfca7e25b1f211f3d43320a648de89590467
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf config: Move perf_config__set_variable() to util/config.c

This commit moves perf_config__set_variable() out of the perf config builtin
so that opt-in features can persist their choice from outside it. It also
adds mutexes to serialize parsing and rewriting since config file access can
now run on more than one thread.

> diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
> --- a/tools/perf/util/config.c
> +++ b/tools/perf/util/config.c
[ ... ]
> +int perf_config__set_variable(const char *var, const char *value)
> +{
> +	/*
> +	 * Not on the stack: the parser publishes this buffer as
> +	 * config_file_name, which another thread may still be reading.
> +	 */
> +	static char path[PATH_MAX];
> +	char *user_config = mkpath(path, sizeof(path), "%s/.perfconfig", getenv("HOME"));

[Severity: Medium]
Could the use of a static buffer here cause a data race if two threads
concurrently call perf_config__set_variable()?

Since mkpath() uses vsnprintf() to format the file path directly into the
shared static path array concurrently, couldn't this corrupt the resulting
file path and cause perf to read or write its configuration to an invalid
or garbage location?

> +	const char *config_filename = config_exclusive_filename ?: user_config;
> +		/*
> +	 * When rewriting the system wide file all entries are marked as coming
> +	 * from it and must be kept, or it would be truncated down to its
> +	 * header.
> +	 */
> +	bool system_config = strcmp(config_filename, perf_etc_perfconfig()) == 0;
> +	struct perf_config_set *set;
> +	int ret = -1;
> +
> +	pthread_mutex_lock(&config_update_mutex);

[Severity: Medium]
The lock intended to serialize the read-modify-write operation is acquired
here, but the static buffer was already mutated in the mkpath() call above.
Does this leave the static path array unprotected against the concurrent
race?

> +	set = perf_config_set__new();
> +	if (!set)
> +		goto out_err;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929201524.2507733-1-acme@kernel.org?part=1

  reply	other threads:[~2026-09-29 20:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 20:15 [PATCH v4 0/5] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-09-29 20:15 ` [PATCH 1/5] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-09-29 20:27   ` sashiko-bot [this message]
2026-09-29 20:15 ` [PATCH 2/5] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-09-29 20:23   ` sashiko-bot
2026-09-29 20:15 ` [PATCH 3/5] perf report: Add --no-progress option Arnaldo Carvalho de Melo
2026-09-29 20:24   ` sashiko-bot
2026-09-29 20:15 ` [PATCH 4/5] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-09-29 20:22   ` sashiko-bot
2026-09-29 20:15 ` [PATCH 5/5] perf test: Add false_sharing workload exhibiting cross-CPU false sharing Arnaldo Carvalho de Melo
2026-09-29 20:25   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-09-29 21:22 [PATCH v5 0/5] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-09-29 21:22 ` [PATCH 1/5] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-09-29 21:45   ` sashiko-bot

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=20260929202746.913671F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.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