From: sashiko-bot@kernel.org
To: "Namhyung Kim" <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 08/11] perf tools: Export filename__read_build_id_ns()
Date: Mon, 16 Nov 2026 06:16:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-216252@kernel.org> (raw)
In-Reply-To: <20261116055731.707164-9-namhyung@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf build-id: filename__read_build_id_ns() checks host /proc
inside mountns
--
commit 32054987b7b4b030ff39e7d9b8a53cb7044261a7
Author: Namhyung Kim <namhyung@kernel.org>
perf tools: Export filename__read_build_id_ns()
This commit exports filename__read_build_id_ns() with a chroot fallback
and uses it in dsos__read_build_ids_cb() and perf-inject's
dso__read_build_id().
> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 02233ef0eafff..ff083a594b405 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -847,15 +847,23 @@ int build_id_cache__remove_s(const char *sbuild_id)
> return err;
> }
>
> -static int filename__read_build_id_ns(const char *filename,
> - struct build_id *bid,
> - struct nsinfo *nsi)
> +int filename__read_build_id_ns(const char *filename,
> + struct build_id *bid,
> + struct nsinfo *nsi)
> {
> struct nscookie nsc;
> int ret;
>
> nsinfo__mountns_enter(nsi, &nsc);
> ret = filename__read_build_id(filename, bid);
> + if (ret < 0 && errno == ENOENT && nsinfo__check_proc(nsi)) {
> + char *new_name = filename_with_chroot(nsinfo__pid(nsi), filename);
> +
> + if (new_name) {
> + ret = filename__read_build_id(new_name, bid);
> + free(new_name);
> + }
> + }
> nsinfo__mountns_exit(&nsc);
[Severity: Medium]
Does calling nsinfo__check_proc() and filename_with_chroot() before
nsinfo__mountns_exit() look up the host PID in the target mount
namespace's /proc?
When profiling a container with its own PID namespace and /proc mount,
any ENOENT from filename__read_build_id() (for example on [heap] or a
deleted binary) causes nsinfo__check_proc() to inspect
/proc/<host_pid>/task/<host_tid>/status inside the container's /proc:
tools/perf/util/namespaces.c:nsinfo__check_proc() {
...
scnprintf(spath, sizeof(spath), "/proc/%d/task/%d/status",
nsinfo__pid(nsi), nsinfo__tid(nsi));
if (nsinfo__get_nspid(&tgid, &nstgid, &in_pidns, spath) < 0 ||
tgid != nsinfo__pid(nsi)) {
nsinfo__set_exited(nsi);
return false;
}
...
}
Because the host PID is absent or belongs to a different process there,
nsinfo__check_proc() calls nsinfo__set_exited(nsi), clearing need_setns
and freeing mntns_path on the shared struct nsinfo, which disables mount
namespace entry for subsequent DSOs of that thread. Moving
nsinfo__mountns_exit(&nsc) before the fallback (or resolving new_name in
the host mount namespace) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116055731.707164-1-namhyung@kernel.org?part=8
next prev parent reply other threads:[~2026-11-16 6:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 5:57 [PATCH v2 00/11] perf tools: Enhance namespace and chroot handling Namhyung Kim
2026-11-16 5:57 ` [PATCH v2 01/11] perf tools: Add HEADER_BOOT_ID feature Namhyung Kim
2026-11-16 6:09 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 02/11] perf tools: Add perf_env__is_same_boot() Namhyung Kim
2026-11-16 6:02 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 03/11] perf tools: Add nsinfo__new_thread() to track tid Namhyung Kim
2026-11-16 6:16 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 04/11] perf tools: Add lock to struct nsinfo Namhyung Kim
2026-11-16 6:17 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 05/11] perf tools: Defer /proc lookup until nsinfo is used Namhyung Kim
2026-11-16 6:11 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 06/11] perf tools: Verify thread status and mount namespace inode Namhyung Kim
2026-11-16 6:14 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 07/11] perf tools: Check thread liveness when accessing /proc Namhyung Kim
2026-11-16 5:57 ` [PATCH v2 08/11] perf tools: Export filename__read_build_id_ns() Namhyung Kim
2026-11-16 6:16 ` sashiko-bot [this message]
2026-11-16 5:57 ` [PATCH v2 09/11] perf tools: Only enter mount namespace if necessary Namhyung Kim
2026-11-16 5:57 ` [PATCH v2 10/11] perf tools: Scope mount namespace entry in dso__load() Namhyung Kim
2026-11-16 6:16 ` sashiko-bot
2026-11-16 5:57 ` [PATCH v2 11/11] perf tests: Add namespace, nsinfo, and boot ID tests Namhyung Kim
2026-11-16 6:24 ` 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=sashiko-outbox-216252@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@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