Skip to contentSkip to conversation

selftests/bpf: add trusted global subprog arg tests

bug report Dan Carpenter 2 participants 2 messages Aug 9, 2024 Kselftest

lore
Share & tools
lore
#0 lore raw

Hello Andrii Nakryiko,

This is a semi-automatic email about new static checker warnings.

Commit c381203eadb7 ("selftests/bpf: add trusted global subprog arg tests") from Jan 29, 2024, leads to the following Smatch complaint:

./tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c:88 trusted_task_arg_nonnull_fail2()
warn: variable dereferenced before check 'nullable' (see line 86)

./tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c

    85		 /* should fail, PTR_TO_BTF_ID_OR_NULL */
    86		res = subprog_trusted_task_nonnull(nullable);
                                                   ^^^^^^^^

This is dereferenced

    87	
    88		if (nullable)
                    ^^^^^^^^

NULL check is too late

    89			bpf_task_release(nullable);
    90	

regards,
dan carpenter

#1 lore raw
Quoted 8 lines · Dan Carpenter

Hello Andrii Nakryiko,

This is a semi-automatic email about new static checker warnings.

Commit c381203eadb7 ("selftests/bpf: add trusted global subprog arg tests") from Jan 29, 2024, leads to the following Smatch complaint:

Quoted 8 lines

./tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c:88 trusted_task_arg_nonnull_fail2()
warn: variable dereferenced before check 'nullable' (see line 86)

./tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c

    85           /* should fail, PTR_TO_BTF_ID_OR_NULL */
    86          res = subprog_trusted_task_nonnull(nullable);
                                                   ^^^^^^^^

This is dereferenced

this is intentional, it's testing that verifier will catch this mistake

Quoted 11 lines
    87
    88          if (nullable)
                    ^^^^^^^^

NULL check is too late

    89                  bpf_task_release(nullable);
    90

regards,
dan carpenter