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 2/8] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod
Date: Sun, 13 Sep 2026 22:39:17 +0000	[thread overview]
Message-ID: <20260913223918.050541F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260913222821.3353-3-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Thread-unsafe modification of process environment via `setenv` races with concurrent `getenv` calls.
- [Medium] Over-scoping of `debuginfod__fetch_lock` neutralizes concurrent lookup logic and makes condition variables dead code.
--

commit 61a7d2bee4ec3dc777a819193cbb18e4e7f04543
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod

This commit adds debuginfo__find_build_id() to fetch debuginfo files via
debuginfod based on their build ID. It falls back to debuginfod servers if
local debuginfo is missing, supporting cancellation and progress reporting.

> diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c
> index 84a78b30ceac1..21cdd3ec8e139 100644
> --- a/tools/perf/util/debuginfo.c
> +++ b/tools/perf/util/debuginfo.c

[ ... ]
> @@ -139,6 +149,677 @@ struct debuginfo *debuginfo__new(const char *path)
[ ... ]
> +static void debuginfod__urls_env_setup(void)
> +{
> +	char *urls = NULL;
[ ... ]
> +	if (urls != NULL) {
> +		setenv("DEBUGINFOD_URLS", urls, 1);

[Severity: High]
Does this thread-unsafe modification of the process environment via setenv()
race with concurrent getenv() calls?

This lazy initialization is triggered during active DSO processing in
debuginfod__fetch(). In multi-threaded commands like 'perf top', one thread
might perform a fetch while another thread simultaneously uses libdw to
process a different DSO (which calls getenv() inside elfutils). This data
race on the environ pointer could lead to memory corruption, use-after-free,
or segmentation faults.

> +		pr_debug("Set DEBUGINFOD_URLS from /etc/debuginfod: %s\n", urls);
> +	}
> +	free(urls);
> +}

[ ... ]
> +static void debuginfod__miss_add(const struct build_id *bid, bool cancelled)
> +{
> +	struct debuginfod_miss *miss = zalloc(sizeof(*miss));
> +
> +	if (miss == NULL)
> +		return;
> +
> +	miss->bid = *bid;
> +	miss->cancelled = cancelled;
> +
> +	debuginfod__missed_lock_init();
> +	mutex_lock(&debuginfod__missed_lock);

[Severity: Medium]
Is this inner lock redundant?

Since debuginfod__miss_add() is called from debuginfod__fetch() which is in
turn called from debuginfo_lookup__find_build_id(), the execution always
happens while debuginfod__fetch_lock is already held (acquired in
debuginfo__find_build_id()).

> +	list_add(&miss->node, &debuginfod__misses);
> +	mutex_unlock(&debuginfod__missed_lock);
> +}

[ ... ]
> +static int debuginfo_lookup__find_build_id(const struct build_id *bid, char **path)
> +{
[ ... ]
> +	/*
> +	 * Somebody else got here first: wait for the fetch that is in
> +	 * progress instead of starting another one, which, while that one
> +	 * is still running, would download the same file a second time.
> +	 */
> +	if (lookup->fetching) {
> +		lookup->nr_waiters++;
> +		waited = true;
> +
> +		while (lookup->fetching)
> +			cond_wait(&lookup->done, &debuginfod__fetch_lock);

[Severity: Medium]
Is this condition wait loop unreachable?

The outer lock (debuginfod__fetch_lock) is acquired in
debuginfo__find_build_id() before initiating any lookup or fetch,
encompassing the entire blocking network operation. This prevents any
concurrent thread from reaching this wait logic while fetching is in
progress, making the intended fine-grained condition variable logic dead
code and forcing fetches for different build IDs to unnecessarily block
each other.

> +	}

[ ... ]
> +int debuginfo__find_build_id(const struct build_id *bid, char **path)
> +{
[ ... ]
> +	/*
> +	 * The checks below have to be made with the lock held, as they look
> +	 * at the state the fetch changes: debuginfod can be turned off while
> +	 * a fetch is in progress, by the 'd' key in its progress line, and a
> +	 * build ID the fetch in progress just settled, as a miss or as a
> +	 * cancellation, is settled for whoever is waiting for the lock as
> +	 * well.  Deciding here and fetching there would repeat a fetch that
> +	 * was already made, and put the same build ID on the misses list
> +	 * twice.
> +	 */
> +	debuginfod__fetch_lock_init();
> +	mutex_lock(&debuginfod__fetch_lock);
> +
> +	if (symbol_conf.debuginfod) {
> +		bool cancelled;
> +
> +		if (debuginfod__cache_disabled()) {
> +			pr_debug("Build-id cache disabled (buildid dir is '%s'), not using debuginfod\n",
> +				 buildid_dir);
> +		} else if (debuginfod__missed(bid, &cancelled)) {
[ ... ]
> +		} else {
> +			err = debuginfo_lookup__find_build_id(bid, path);
> +		}
> +	}
> +
> +	mutex_unlock(&debuginfod__fetch_lock);
> +
> +	return err;
> +}

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

  reply	other threads:[~2026-09-13 22:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13 22:28 [PATCH v3 0/8] perf tools: Annotate fixes, stdio progress indication, debuginfo-client in more places Arnaldo Carvalho de Melo
2026-09-13 22:28 ` [PATCH 1/8] perf test: Skip data_type_profiling when the PMU cannot record memory events Arnaldo Carvalho de Melo
2026-09-13 22:34   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 2/8] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod Arnaldo Carvalho de Melo
2026-09-13 22:39   ` sashiko-bot [this message]
2026-09-13 22:28 ` [PATCH 3/8] perf symbol: Fall back to fetching the vmlinux by build ID Arnaldo Carvalho de Melo
2026-09-13 22:40   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 4/8] perf annotate-data: Show the sample count in the data-type browser Arnaldo Carvalho de Melo
2026-09-13 22:35   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 5/8] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-09-13 22:39   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 6/8] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-09-13 22:36   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 7/8] perf annotate-data: Resolve type DIEs in the debug file they came from Arnaldo Carvalho de Melo
2026-09-13 22:37   ` sashiko-bot
2026-09-13 22:28 ` [PATCH 8/8] perf mem record: Request PERF_SAMPLE_CPU by default Arnaldo Carvalho de Melo
2026-09-13 22:43   ` 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=20260913223918.050541F000FF@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.