Re: [PATCH bpf-next v3 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 19:17 +0000, [email protected] wrote:
> Sashiko AI review found 1 potential issue(s):
> - [Medium] Unchecked return values of `sysctl_set()` in `serial_test_token()` can lead to confusing test failures.
> --
> 
> commit e7dc629b9f37dc08742ff9bbddeaaf65c1e34956
> 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 XDP program and its
> global subprogram appear in /proc/kallsyms when loaded using a user
> namespace BPF token. It also introduces a sysctl_set utility to configure
> system parameters needed to read kallsyms.
> 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
> > index b81dde283052e..cf5b94512cff4 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");
> 
> Should the return values of these sysctl_set calls be checked?
> 
> If the test is executed in an environment where these sysctls are read-only
> or inaccessible (such as inside a container), sysctl_set will silently fail.
> 
> This would cause load_kallsyms_local to read zeroed addresses because
> kptr_restrict wasn't successfully disabled, resulting in confusing test
> failures later at ASSERT_TRUE instead of catching the setup failure early.
> 
> Would it be better to wrap these with ASSERT_OK?

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);
> > +	}
> >  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.