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 <eddyz87@xxxxxxxxx> --- .../testing/selftests/bpf/prog_tests/verifier.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c index c9da06741104..cedb86d8f717 100644 --- a/tools/testing/selftests/bpf/prog_tests/verifier.c +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c @@ -115,14 +115,16 @@ struct test_val { __maybe_unused static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory, - pre_execution_cb pre_execution_cb) + pre_execution_cb pre_execution_cb, + bool drop_sysadmin) { struct test_loader tester = {}; - __u64 old_caps; + __u64 caps_to_drop, old_caps; int err; /* test_verifier tests are executed w/o CAP_SYS_ADMIN, do the same here */ - err = cap_disable_effective(1ULL << CAP_SYS_ADMIN, &old_caps); + caps_to_drop = drop_sysadmin ? 1ULL << CAP_SYS_ADMIN : 0; + err = cap_disable_effective(caps_to_drop, &old_caps); if (err) { PRINT_FAIL("failed to drop CAP_SYS_ADMIN: %i, %s\n", err, strerror(-err)); return; @@ -137,7 +139,8 @@ static void run_tests_aux(const char *skel_name, PRINT_FAIL("failed to restore CAP_SYS_ADMIN: %i, %s\n", err, strerror(-err)); } -#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL) +#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL, true) +#define RUN_FULL_CAPS(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL, false) void test_verifier_and(void) { RUN(verifier_and); } void test_verifier_arena(void) { RUN(verifier_arena); } @@ -272,7 +275,8 @@ void test_verifier_array_access(void) { run_tests_aux("verifier_array_access", verifier_array_access__elf_bytes, - init_array_access_maps); + init_array_access_maps, + true); } static int init_value_ptr_arith_maps(struct bpf_object *obj) @@ -284,5 +288,6 @@ void test_verifier_value_ptr_arith(void) { run_tests_aux("verifier_value_ptr_arith", verifier_value_ptr_arith__elf_bytes, - init_value_ptr_arith_maps); + init_value_ptr_arith_maps, + true); } -- 2.47.1