]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: verify jset handling in CFG computation
authorEduard Zingerman <eddyz87@gmail.com>
Fri, 13 Jun 2025 17:53:31 +0000 (10:53 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 13 Jun 2025 18:51:19 +0000 (11:51 -0700)
A test case to check if both branches of jset are explored when
computing program CFG.

At 'if r1 & 0x7 ...':
- register 'r2' is computed alive only if jump branch of jset
  instruction is followed;
- register 'r0' is computed alive only if fallthrough branch of jset
  instruction is followed.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20250613175331.3238739-2-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/compute_live_registers.c

index f3d79aecbf9356b4b9a147ead194d1d80b8f9927..6884ab99a421b5f5f689ceacee998e8cf7b1324e 100644 (file)
@@ -240,6 +240,22 @@ __naked void if2(void)
                ::: __clobber_all);
 }
 
+/* Verifier misses that r2 is alive if jset is not handled properly */
+SEC("socket")
+__log_level(2)
+__msg("2: 012....... (45) if r1 & 0x7 goto pc+1")
+__naked void if3_jset_bug(void)
+{
+       asm volatile (
+               "r0 = 1;"
+               "r2 = 2;"
+               "if r1 & 0x7 goto +1;"
+               "exit;"
+               "r0 = r2;"
+               "exit;"
+               ::: __clobber_all);
+}
+
 SEC("socket")
 __log_level(2)
 __msg("0: .......... (b7) r1 = 0")