Skip to content

Commit d4cb6ec

Browse files
committed
selftests/bpf: allow tests from verifier.c not to drop CAP_SYS_ADMIN
Originally prog_tests/verifier.c was developed to run tests ported from test_verifier binary. test_verifier runs tests with CAP_SYS_ADMIN dropped, hence this behaviour was copied in prog_tests/verifier.c. BPF_OBJ_GET_NEXT_ID BPF syscall command fails w/o CAP_SYS_ADMIN and this prevents libbpf from loading module BTFs. This commit adds an optout from capability drop. Signed-off-by: Eduard Zingerman <[email protected]>
1 parent dd82cf3 commit d4cb6ec

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,16 @@ struct test_val {
115115
__maybe_unused
116116
static void run_tests_aux(const char *skel_name,
117117
skel_elf_bytes_fn elf_bytes_factory,
118-
pre_execution_cb pre_execution_cb)
118+
pre_execution_cb pre_execution_cb,
119+
bool drop_sysadmin)
119120
{
120121
struct test_loader tester = {};
121-
__u64 old_caps;
122+
__u64 caps_to_drop, old_caps;
122123
int err;
123124

124125
/* test_verifier tests are executed w/o CAP_SYS_ADMIN, do the same here */
125-
err = cap_disable_effective(1ULL << CAP_SYS_ADMIN, &old_caps);
126+
caps_to_drop = drop_sysadmin ? 1ULL << CAP_SYS_ADMIN : 0;
127+
err = cap_disable_effective(caps_to_drop, &old_caps);
126128
if (err) {
127129
PRINT_FAIL("failed to drop CAP_SYS_ADMIN: %i, %s\n", err, strerror(-err));
128130
return;
@@ -137,7 +139,8 @@ static void run_tests_aux(const char *skel_name,
137139
PRINT_FAIL("failed to restore CAP_SYS_ADMIN: %i, %s\n", err, strerror(-err));
138140
}
139141

140-
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
142+
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL, true)
143+
#define RUN_FULL_CAPS(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL, false)
141144

142145
void test_verifier_and(void) { RUN(verifier_and); }
143146
void test_verifier_arena(void) { RUN(verifier_arena); }
@@ -272,7 +275,8 @@ void test_verifier_array_access(void)
272275
{
273276
run_tests_aux("verifier_array_access",
274277
verifier_array_access__elf_bytes,
275-
init_array_access_maps);
278+
init_array_access_maps,
279+
true);
276280
}
277281

278282
static int init_value_ptr_arith_maps(struct bpf_object *obj)
@@ -284,5 +288,6 @@ void test_verifier_value_ptr_arith(void)
284288
{
285289
run_tests_aux("verifier_value_ptr_arith",
286290
verifier_value_ptr_arith__elf_bytes,
287-
init_value_ptr_arith_maps);
291+
init_value_ptr_arith_maps,
292+
true);
288293
}

0 commit comments

Comments
 (0)