Skip to content

Commit cf15cdc

Browse files
luisgerhorstAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Fix caps for __xlated/jited_unpriv
Currently, __xlated_unpriv and __jited_unpriv do not work because the BPF syscall will overwrite info.jited_prog_len and info.xlated_prog_len with 0 if the process is not bpf_capable(). This bug was not noticed before, because there is no test that actually uses __xlated_unpriv/__jited_unpriv. To resolve this, simply restore the capabilities earlier (but still after loading the program). Adding this here unconditionally is fine because the function first checks that the capabilities were initialized before attempting to restore them. This will be important later when we add tests that check whether a speculation barrier was inserted in the correct location. Signed-off-by: Luis Gerhorst <[email protected]> Fixes: 9c9f733 ("selftests/bpf: allow checking xlated programs in verifier_* tests") Fixes: 7d743e4 ("selftests/bpf: __jited test tag to check disassembly after jit") Acked-by: Kumar Kartikeya Dwivedi <[email protected]> Tested-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0f2d39f commit cf15cdc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tools/testing/selftests/bpf/test_loader.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,14 @@ void run_subtest(struct test_loader *tester,
10421042
emit_verifier_log(tester->log_buf, false /*force*/);
10431043
validate_msgs(tester->log_buf, &subspec->expect_msgs, emit_verifier_log);
10441044

1045+
/* Restore capabilities because the kernel will silently ignore requests
1046+
* for program info (such as xlated program text) if we are not
1047+
* bpf-capable. Also, for some reason test_verifier executes programs
1048+
* with all capabilities restored. Do the same here.
1049+
*/
1050+
if (restore_capabilities(&caps))
1051+
goto tobj_cleanup;
1052+
10451053
if (subspec->expect_xlated.cnt) {
10461054
err = get_xlated_program_text(bpf_program__fd(tprog),
10471055
tester->log_buf, tester->log_buf_sz);
@@ -1067,12 +1075,6 @@ void run_subtest(struct test_loader *tester,
10671075
}
10681076

10691077
if (should_do_test_run(spec, subspec)) {
1070-
/* For some reason test_verifier executes programs
1071-
* with all capabilities restored. Do the same here.
1072-
*/
1073-
if (restore_capabilities(&caps))
1074-
goto tobj_cleanup;
1075-
10761078
/* Do bpf_map__attach_struct_ops() for each struct_ops map.
10771079
* This should trigger bpf_struct_ops->reg callback on kernel side.
10781080
*/

0 commit comments

Comments
 (0)