Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <luis.gerhorst@fau.de>
Fixes: 9c9f73391310 ("selftests/bpf: allow checking xlated programs in verifier_* tests")
Fixes: 7d743e4c759c ("selftests/bpf: __jited test tag to check disassembly after jit")
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20250501073603.1402960-2-luis.gerhorst@fau.de
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Luis Gerhorst and committed by
Alexei Starovoitov
cf15cdc0 0f2d39f3

+8 -6
+8 -6
tools/testing/selftests/bpf/test_loader.c
··· 1042 1042 emit_verifier_log(tester->log_buf, false /*force*/); 1043 1043 validate_msgs(tester->log_buf, &subspec->expect_msgs, emit_verifier_log); 1044 1044 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 + 1045 1053 if (subspec->expect_xlated.cnt) { 1046 1054 err = get_xlated_program_text(bpf_program__fd(tprog), 1047 1055 tester->log_buf, tester->log_buf_sz); ··· 1075 1067 } 1076 1068 1077 1069 if (should_do_test_run(spec, subspec)) { 1078 - /* For some reason test_verifier executes programs 1079 - * with all capabilities restored. Do the same here. 1080 - */ 1081 - if (restore_capabilities(&caps)) 1082 - goto tobj_cleanup; 1083 - 1084 1070 /* Do bpf_map__attach_struct_ops() for each struct_ops map. 1085 1071 * This should trigger bpf_struct_ops->reg callback on kernel side. 1086 1072 */