]> git.hungrycats.org Git - linux/commitdiff
selftests/bpf: precision of a NULL global subprogram memory argument
authorEduard Zingerman <eddyz87@gmail.com>
Sat, 5 Sep 2026 00:05:55 +0000 (17:05 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 5 Sep 2026 01:17:30 +0000 (18:17 -0700)
Check that mark_chain_precision() is called for a NULL pointer passed
as a nullable pointer argument of a global subprogram.
(Pointer arguments of the global subprograms are nullable by default).

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260904-register-is-null-precise-fixes-v1-4-0f5a360ff15d@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/verifier_precision.c

index 3e290b07f67291938f49fc0ceaf870c68bc2c2d6..fb7dfa1246ef517f19b0d8fa8b65f850ede1d1ef 100644 (file)
@@ -676,4 +676,36 @@ __naked int null_mem_arg_zero_size(void)
                : __clobber_all);
 }
 
+__weak int subprog_mem_arg(int *p)
+{
+       if (p)
+               return *p;
+       return 0;
+}
+
+/*
+ * Verification takes two paths: with r1 being scalar zero on path (1)
+ * and with r1 being some other scalar on path (2).
+ * Check that the verifier does not use checkpoints created
+ * on path (1) to prune path (2).
+ */
+SEC("?raw_tp")
+__flag(BPF_F_TEST_STATE_FREQ)
+__failure __msg("R1 type=scalar expected=fp")
+__naked int null_mem_arg_global_subprog(void)
+{
+       asm volatile (
+               "call %[bpf_get_prandom_u32];"
+               "r1 = 42;"
+               "if r0 > 42 goto 1f;"
+               "r1 = 0;"
+       "1:"
+               "call subprog_mem_arg;"
+               "r0 = 0;"
+               "exit;"
+               :
+               : __imm(bpf_get_prandom_u32)
+               : __clobber_all);
+}
+
 char _license[] SEC("license") = "GPL";