Skip to content

Commit 4a4b84b

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
selftests/bpf: verify jset handling in CFG computation
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3157f7e commit 4a4b84b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ __naked void if2(void)
240240
::: __clobber_all);
241241
}
242242

243+
/* Verifier misses that r2 is alive if jset is not handled properly */
244+
SEC("socket")
245+
__log_level(2)
246+
__msg("2: 012....... (45) if r1 & 0x7 goto pc+1")
247+
__naked void if3_jset_bug(void)
248+
{
249+
asm volatile (
250+
"r0 = 1;"
251+
"r2 = 2;"
252+
"if r1 & 0x7 goto +1;"
253+
"exit;"
254+
"r0 = r2;"
255+
"exit;"
256+
::: __clobber_all);
257+
}
258+
243259
SEC("socket")
244260
__log_level(2)
245261
__msg("0: .......... (b7) r1 = 0")

0 commit comments

Comments
 (0)