All of lore.kernel.org
 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/4] perf config: Move perf_config__set_variable() to util/config.c
Date: Mon, 28 Sep 2026 22:19:24 +0000	[thread overview]
Message-ID: <20260928221925.76D751F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928220634.2451784-2-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf: data race in bad_config() causes stack UAF
--

commit 861fbcb5738f68f4bf3fa7cf60e666d3e7639e45
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 builtin so opt-in
features can persist their choice from outside it. It also serializes
parsing and rewriting with a mutex 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
> index 8fe43b032e9af..da4213a704899 100644
> --- a/tools/perf/util/config.c
> +++ b/tools/perf/util/config.c
[ ... ]
> @@ -926,6 +926,84 @@ void perf_config__exit(void)
>  	config_set = NULL;
>  }
>  
> +int perf_config_set__write(struct perf_config_set *set,
> +			   const char *file_name, bool system_config)
[ ... ]
> +int perf_config__set_variable(const char *var, const char *value)
> +{
> +	char path[PATH_MAX];
> +	char *user_config = mkpath(path, sizeof(path), "%s/.perfconfig", getenv("HOME"));
> +	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);
> +	set = perf_config_set__new();
> +	if (!set)
> +		goto out_err;
> +
> +	if (perf_config_set__collect(set, config_filename, var, value) < 0) {

[Severity: High]
Can this lead to a stack use-after-free during concurrent config parsing?

A writer thread running perf_config__set_variable() assigns the global
config_file_name to point to its local stack buffer (path) under config_mutex
in perf_config_set__collect().

Concurrently, a reader thread iterating cached configurations via perf_config()
might encounter a malformed value and invoke bad_config(). bad_config() reads
config_file_name locklessly:

tools/perf/util/config.c:bad_config() {
    ...
    if (config_file_name)
        pr_warning("bad config value for '%s' in %s, ignoring...\n",
                   name, config_file_name);
    ...
}

If the reader reads the pointer locklessly, and the writer finishes and
returns before the reader executes pr_warning(), won't the reader dereference
the destroyed stack frame for path?

> +		pr_err("Failed to add '%s=%s'\n", var, value);
> +		goto out_err;
> +	}
> +
> +	if (perf_config_set__write(set, config_filename, system_config) < 0) {
> +		pr_err("Failed to set the configs on %s\n", config_filename);
> +		goto out_err;
> +	}
> +
> +	ret = 0;
> +out_err:
> +	perf_config_set__delete(set);
> +	pthread_mutex_unlock(&config_update_mutex);
> +	return ret;
> +}

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

  reply	other threads:[~2026-09-28 22:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 22:06 [PATCH v3 0/4] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-09-28 22:06 ` [PATCH 1/4] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-09-28 22:19   ` sashiko-bot [this message]
2026-09-28 22:06 ` [PATCH 2/4] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-09-28 22:12   ` sashiko-bot
2026-09-29 18:29   ` Namhyung Kim
2026-09-28 22:06 ` [PATCH 3/4] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-09-28 22:16   ` sashiko-bot
2026-09-29 18:31   ` Namhyung Kim
2026-09-28 22:06 ` [PATCH 4/4] perf test: Add false_sharing workload exhibiting cross-CPU false sharing Arnaldo Carvalho de Melo
2026-09-28 22:14   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-09-28 16:22 [PATCH 0/4 v1] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-09-28 16:22 ` [PATCH 1/4] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-09-28 16:38   ` 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=20260928221925.76D751F000FF@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.