Skip to content

Commit 45e99a3

Browse files
Yonghong SongKernel Patches Daemon
Yonghong Song
authored and
Kernel Patches Daemon
committed
selftests/bpf: Add tests with stack ptr register in conditional jmp
Add two tests: - one test has 'rX <op> r10' where rX is not r10, and - another test has 'rX <op> rY' where rX and rY are not r10 but there is an early insn 'rX = r10'. Without previous verifier change, both tests will fail. Signed-off-by: Yonghong Song <[email protected]>
1 parent 752b099 commit 45e99a3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,57 @@ __naked int state_loop_first_last_equal(void)
178178
);
179179
}
180180

181+
__used __naked static void __bpf_cond_op_r10(void)
182+
{
183+
asm volatile (
184+
"r2 = 2314885393468386424 ll;"
185+
"goto +0;"
186+
"if r2 <= r10 goto +3;"
187+
"if r1 >= -1835016 goto +0;"
188+
"if r2 <= 8 goto +0;"
189+
"if r3 <= 0 goto +0;"
190+
"exit;"
191+
::: __clobber_all);
192+
}
193+
194+
SEC("?raw_tp")
195+
__success __log_level(2)
196+
__msg("8: (bd) if r2 <= r10 goto pc+3")
197+
__msg("9: (35) if r1 >= 0xffe3fff8 goto pc+0")
198+
__msg("10: (b5) if r2 <= 0x8 goto pc+0")
199+
__msg("mark_precise: frame1: last_idx 10 first_idx 0 subseq_idx -1")
200+
__msg("mark_precise: frame1: regs=r2 stack= before 9: (35) if r1 >= 0xffe3fff8 goto pc+0")
201+
__msg("mark_precise: frame1: regs=r2 stack= before 8: (bd) if r2 <= r10 goto pc+3")
202+
__msg("mark_precise: frame1: regs=r2 stack= before 7: (05) goto pc+0")
203+
__naked void bpf_cond_op_r10(void)
204+
{
205+
asm volatile (
206+
"r3 = 0 ll;"
207+
"call __bpf_cond_op_r10;"
208+
"r0 = 0;"
209+
"exit;"
210+
::: __clobber_all);
211+
}
212+
213+
SEC("?raw_tp")
214+
__success __log_level(2)
215+
__msg("3: (bf) r3 = r10")
216+
__msg("4: (bd) if r3 <= r2 goto pc+1")
217+
__msg("5: (b5) if r2 <= 0x8 goto pc+2")
218+
__msg("mark_precise: frame0: last_idx 5 first_idx 0 subseq_idx -1")
219+
__msg("mark_precise: frame0: regs=r2 stack= before 4: (bd) if r3 <= r2 goto pc+1")
220+
__msg("mark_precise: frame0: regs=r2 stack= before 3: (bf) r3 = r10")
221+
__naked void bpf_cond_op_not_r10(void)
222+
{
223+
asm volatile (
224+
"r0 = 0;"
225+
"r2 = 2314885393468386424 ll;"
226+
"r3 = r10;"
227+
"if r3 <= r2 goto +1;"
228+
"if r2 <= 8 goto +2;"
229+
"r0 = 2 ll;"
230+
"exit;"
231+
::: __clobber_all);
232+
}
233+
181234
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)