selftests/bpf: fix __retval() being always ignored
authorEduard Zingerman <eddyz87@gmail.com>
Thu, 20 Apr 2023 23:23:15 +0000 (02:23 +0300)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 20 Apr 2023 23:49:16 +0000 (16:49 -0700)
Florian Westphal found a bug in and suggested a fix for test_loader.c
processing of __retval tag. Because of this bug the function
test_loader.c:do_prog_test_run() never executed and all __retval test
tags were ignored.

If this bug is fixed a number of test cases from
progs/verifier_array_access.c fail with retval not matching the
expected value. This test was recently converted to use test_loader.c
and inline assembly in [1]. When doing the conversion I missed the
important detail of test_verifier.c operation: when it creates
fixup_map_array_ro, fixup_map_array_wo and fixup_map_array_small it
populates these maps with a dummy record.

Disabling the __retval checks for the affected verifier_array_access
in this commit to avoid false-postivies in any potential bisects.
The issue is addressed in the next patch.

I verified that the __retval tags are now respected by changing
expected return values for all tests annotated with __retval, and
checking that these tests started to fail.

[1] https://lore.kernel.org/bpf/20230325025524.144043-1-eddyz87@gmail.com/

Fixes: 19a8e06f5f91 ("selftests/bpf: Tests execution support for test_loader.c")
Reported-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/bpf/f4c4aee644425842ee6aa8edf1da68f0a8260e7c.camel@gmail.com/T/
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20230420232317.2181776-3-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/verifier_array_access.c
tools/testing/selftests/bpf/test_loader.c

index 95d7ecc..fceeeef 100644 (file)
@@ -330,7 +330,7 @@ l0_%=:      exit;                                           \
 
 SEC("socket")
 __description("valid read map access into a read-only array 1")
-__success __success_unpriv __retval(28)
+__success __success_unpriv /* __retval(28) temporarily disable */
 __naked void a_read_only_array_1_1(void)
 {
        asm volatile ("                                 \
@@ -351,7 +351,7 @@ l0_%=:      exit;                                           \
 
 SEC("tc")
 __description("valid read map access into a read-only array 2")
-__success __retval(65507)
+__success /* __retval(65507) temporarily disable */
 __naked void a_read_only_array_2_1(void)
 {
        asm volatile ("                                 \
index 47e9e07..e2a1bdc 100644 (file)
@@ -587,7 +587,7 @@ void run_subtest(struct test_loader *tester,
                /* For some reason test_verifier executes programs
                 * with all capabilities restored. Do the same here.
                 */
-               if (!restore_capabilities(&caps))
+               if (restore_capabilities(&caps))
                        goto tobj_cleanup;
 
                do_prog_test_run(bpf_program__fd(tprog), &retval);