Re: [PATCH bpf-next v2 2/2] selftests/bpf: verify kallsyms entries for token-loaded subprograms
Eduard Zingerman <[email protected]>
| Newsgroups | dev.linux.lists.sashiko,org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 2026-04-15 at 01:21 +0000, [email protected] wrote: > Sashiko AI review found 1 potential issue(s): > - [Medium] The test modifies global sysctls (`perf_event_paranoid` and `kptr_restrict`) while running in parallel, causing race conditions and potential host state leakage. > -- > > commit 9e0a167112286dfb5b44d5686732b8297533a10b > Author: Eduard Zingerman <[email protected]> > > selftests/bpf: verify kallsyms entries for token-loaded subprograms > > This commit adds a test to verify that both the main program and its global > subprogram appear in /proc/kallsyms when loaded using a user namespace BPF > token. It temporarily modifies global sysctl variables to allow reading > kallsym addresses. > > > diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c > > index b81dde283052e..89da527ed9304 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/token.c > > +++ b/tools/testing/selftests/bpf/prog_tests/token.c > > [ ... ] > > > @@ -1194,4 +1252,23 @@ void test_token(void) > > > > subtest_userns(&opts, userns_bpf_token_info); > > } > > + if (test__start_subtest("obj_priv_prog_kallsyms")) { > > + char perf_paranoid_orig[32] = {}; > > + char kptr_restrict_orig[32] = {}; > > + struct bpffs_opts opts = { > > + .cmds = bit(BPF_BTF_LOAD) | bit(BPF_PROG_LOAD), > > + .progs = bit(BPF_PROG_TYPE_XDP), > > + .attachs = ~0ULL, > > + }; > > + > > + sysctl_set("/proc/sys/kernel/perf_event_paranoid", perf_paranoid_orig, "0"); > > + sysctl_set("/proc/sys/kernel/kptr_restrict", kptr_restrict_orig, "0"); > > The BPF selftest framework executes test_token() concurrently with other > tests because it lacks the serial_test_ prefix. > > If another parallel test modifies or relies on these sysctls simultaneously, > can this create a race condition where the parallel test reads the > already-modified "0" as its original state? > > This could result in the host permanently retaining the lowered security > settings once the tests complete. > > Should this test be renamed to serial_test_token() to prevent concurrent > modification of global system state? I don't think that we have tests that rely on these parameters atm, but suggestion makes sense. > > > + > > + subtest_userns(&opts, userns_obj_priv_prog_kallsyms); > > + > > + if (perf_paranoid_orig[0]) > > + sysctl_set("/proc/sys/kernel/perf_event_paranoid", NULL, perf_paranoid_orig); > > + if (kptr_restrict_orig[0]) > > + sysctl_set("/proc/sys/kernel/kptr_restrict", NULL, kptr_restrict_orig); > > + } > > }