From: sashiko-bot@kernel.org
To: "Namhyung Kim" <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 11/11] perf tests: Add namespace, nsinfo, and boot ID tests
Date: Mon, 16 Nov 2026 06:24:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-216273@kernel.org> (raw)
In-Reply-To: <20261116055731.707164-12-namhyung@kernel.org>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] perf tests: unlinked DSO triggers assert in
run_mountns_and_chroot_tests()
- [Low] perf tests: raw nsinfo pointer comparison in
test__nsinfo_thread_liveness()
- [Low] perf tests: missing signal.h include in namespaces.c
- [Low] perf tests: TEST_ASSERT_VAL() skips cleanup in
test__nsinfo_boot_id()
- [Low] perf tests: leaked thread ref on failure in
test__nsinfo_thread_liveness()
- [Low] perf tests: leaked chroot path string on failure in namespaces.c
- [Low] perf tests: unchecked allocations in
run_mountns_and_chroot_tests()
--
commit c5ab486958138682ed6911ecda820dca7b29d74d
Author: Namhyung Kim <namhyung@kernel.org>
perf tests: Add namespace, nsinfo, and boot ID tests
This commit adds a unit test suite for namespaces, nsinfo, and boot ID
handling, and extends the perf header shell test to verify the boot ID.
> diff --git a/tools/perf/tests/namespaces.c b/tools/perf/tests/namespaces.c
> new file mode 100644
> index 0000000000000..cfc654db48f92
> --- /dev/null
> +++ b/tools/perf/tests/namespaces.c
> @@ -0,0 +1,1035 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <limits.h>
> +#include <pthread.h>
> +#include <sched.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/mman.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
[Severity: Low]
run_mountns_and_chroot_tests() calls kill() with SIGKILL, so signal.h
should be included explicitly rather than relying on transitive headers.
[ ... ]
> +static int test__nsinfo_boot_id(struct test_suite *test __maybe_unused,
> + int subtest __maybe_unused)
> +{
> + struct perf_env live_env, off_env;
> + char host_boot_id[64];
> + const char *bid;
> + int ret = TEST_FAIL;
> +
> + if (read_host_boot_id_str(host_boot_id, sizeof(host_boot_id)) < 0) {
> + pr_debug("SKIP: cannot read host boot_id from procfs\n");
> + return TEST_SKIP;
> + }
> +
> + perf_env__init(&live_env);
> + perf_env__init(&off_env);
> +
> + TEST_ASSERT_VAL("NULL env should match current host boot",
> + perf_env__is_same_boot(NULL));
> +
> + TEST_ASSERT_VAL("live env should match current host boot",
> + perf_env__is_same_boot(&live_env));
[Severity: Low]
Does TEST_ASSERT_VAL() return TEST_FAIL directly and skip
perf_env__exit() at the out label if either check fails? Jumping to out
instead avoids leaking live_env.boot_id and leaving the perf_env locks
undestroyed.
[ ... ]
> + thread__e_machine_endian(off_sub, off_m, NULL, NULL);
> + if (machine__find_thread(off_m, self_pid, self_pid) != NULL) {
> + pr_debug("thread__e_machine_endian() unexpectedly recreated exited leader\n");
> + goto out;
> + }
> + machine__remove_thread(off_m, off_sub);
> + thread__put(off_sub);
> + off_sub = NULL;
> +
> + /* Live thread tracking, reset on exec/namespaces, and exit propagation. */
> + th = machine__findnew_thread(live_m, self_pid, self_pid);
> + if (!th || !thread__is_alive(th)) {
> + pr_debug("current live thread reported as dead\n");
> + goto out;
> + }
> +
> + nsi1 = thread__get_nsinfo(th);
> + if (!nsi1)
> + goto out;
> +
> + if (__thread__set_comm(th, "execed", 1000, /*exec=*/true) != 0)
> + goto out;
> + nsi2 = thread__get_nsinfo(th);
> + if (!nsi2 || nsi2 == nsi1) {
> + pr_debug("exec did not replace thread->nsinfo\n");
> + goto out;
> + }
> +
> + ns_ev = calloc(1, sizeof(*ns_ev) + sizeof(ns_ev->link_info[0]));
> + if (!ns_ev)
> + goto out;
> + ns_ev->nr_namespaces = 1;
> + if (thread__set_namespaces(th, 2000, ns_ev) != 0) {
> + free(ns_ev);
> + goto out;
> + }
> + free(ns_ev);
> +
> + nsi3 = thread__get_nsinfo(th);
> + if (!nsi3 || nsi3 == nsi2) {
> + pr_debug("PERF_RECORD_NAMESPACES did not replace thread->nsinfo\n");
> + goto out;
> + }
[Severity: Low]
Should nsi2 == nsi1 and nsi3 == nsi2 use RC_CHK_EQUAL() instead of raw
pointer equality?
Because struct nsinfo is declared with DECLARE_RC_STRUCT(nsinfo), each
thread__get_nsinfo() call allocates a distinct wrapper pointer when built
with REFCNT_CHECKING, so raw pointer equality will always evaluate to
false even if thread->nsinfo was not replaced.
[ ... ]
> + memset(&ev, 0, sizeof(ev));
> + ev.fork.header.type = PERF_RECORD_EXIT;
> + ev.fork.header.size = sizeof(ev.fork);
> + ev.fork.pid = self_pid;
> + ev.fork.tid = self_pid;
> + ev.fork.ppid = 1;
> + ev.fork.ptid = 1;
> + if (perf_event__exit_del_thread(&tool, &ev, &sample, live_m) != 0)
> + goto out;
> + if (!RC_CHK_ACCESS(del_nsi)->exited || nsinfo__check_proc(del_nsi) ||
> + machine__find_thread(live_m, self_pid, self_pid) != NULL) {
> + pr_debug("perf_event__exit_del_thread() did not mark nsinfo exited\n");
> + goto out;
> + }
[Severity: Low]
Does calling machine__find_thread() directly in the if condition here and
after thread__e_machine_endian() above leak a thread reference if a
thread is found? machine__find_thread() returns a refcounted struct
thread * that must be released with thread__put().
[ ... ]
> + /* Guarded chroot/build-id lookups must bail out immediately when exited. */
> + dso = dso__new("/bin/sh");
> + nsi = nsinfo__new_thread(getpid(), getpid());
> + if (!dso || !nsi)
> + goto out;
> + nsinfo__set_exited(nsi);
> + dso__set_nsinfo(dso, nsinfo__get(nsi));
> +
> + if (dso__filename_with_chroot(dso, "/bin/sh") != NULL) {
> + pr_debug("dso__filename_with_chroot() did not respect exited nsinfo\n");
> + goto out;
> + }
[Severity: Low]
Does this leak the heap string returned by dso__filename_with_chroot() if
the check fails (as well as in the exited chroot check in
run_mountns_and_chroot_tests() below)?
[ ... ]
> + dso = dso__new(target_bin);
> + if (!dso) {
> + machine__exit(&machine);
> + goto out_wait;
> + }
> + dso__set_nsinfo(dso, nsinfo__get(nsi));
> +#ifndef HAVE_LIBELF_SUPPORT
> + /* Without libelf, filename__has_section() cannot auto-detect binary_type. */
> + dso__set_binary_type(dso, DSO_BINARY_TYPE__SYSTEM_PATH_DSO);
> + dso__set_bintype_searched(dso);
> +#endif
> + if (dso__data_read_offset(dso, &machine, 0, magic, sizeof(magic)) != sizeof(magic) ||
> + memcmp(magic, "\x7f" "ELF", 4) != 0) {
[Severity: Medium]
Does calling dso__data_read_offset() on a standalone dso without adding
it via dsos__add(&machine.dsos, dso) trigger an assertion failure in
DEBUG=1 builds?
dso__data_read_offset() -> data_read_write_offset() ->
dso__data_file_size() -> file_size() -> try_to_open_dso() -> open_dso()
calls dso__list_add(dso), which asserts that dso__dsos(dso) is non-NULL:
tools/perf/util/dso.c:dso__list_add() {
...
/* Assume the dso is part of dsos, hence the optional reference count above. */
assert(dso__dsos(dso));
}
[ ... ]
> + if (cpid > 0 && read(cpipe[0], &sig, 1) == 1 && sig == '1') {
> + struct nsinfo *cnsi = nsinfo__new_thread(cpid, cpid);
> + struct stat st1, st2;
> + char *resolved = NULL;
> +
> + chroot_dso = dso__new("/chroot_elf");
> + if (chroot_dso && cnsi) {
[Severity: Low]
If either nsinfo__new_thread() or dso__new() returns NULL here, does the
test silently skip the chroot checks and still set ret = TEST_OK?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116055731.707164-1-namhyung@kernel.org?part=11
prev parent reply other threads:[~2026-11-16 6:24 UTC|newest]
Thread overview: 23+ 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 6:38 ` sashiko-bot
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
2026-11-16 5:57 ` [PATCH v2 09/11] perf tools: Only enter mount namespace if necessary Namhyung Kim
2026-11-16 6:34 ` sashiko-bot
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 [this message]
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-216273@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