Skip to content

Commit 280e4eb

Browse files
Alexei Starovoitovborkmann
authored andcommitted
selftests/bpf: Add tests for may_goto with negative offset.
Add few tests with may_goto and negative offset. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 2b2efe1 commit 280e4eb

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,58 @@ static __naked void iter_limit_bug_cb(void)
274274
);
275275
}
276276

277+
int tmp_var;
278+
SEC("socket")
279+
__failure __msg("infinite loop detected at insn 2")
280+
__naked void jgt_imm64_and_may_goto(void)
281+
{
282+
asm volatile (" \
283+
r0 = %[tmp_var] ll; \
284+
l0_%=: .byte 0xe5; /* may_goto */ \
285+
.byte 0; /* regs */ \
286+
.short -3; /* off -3 */ \
287+
.long 0; /* imm */ \
288+
if r0 > 10 goto l0_%=; \
289+
r0 = 0; \
290+
exit; \
291+
" :: __imm_addr(tmp_var)
292+
: __clobber_all);
293+
}
294+
295+
SEC("socket")
296+
__failure __msg("infinite loop detected at insn 1")
297+
__naked void may_goto_self(void)
298+
{
299+
asm volatile (" \
300+
r0 = *(u32 *)(r10 - 4); \
301+
l0_%=: .byte 0xe5; /* may_goto */ \
302+
.byte 0; /* regs */ \
303+
.short -1; /* off -1 */ \
304+
.long 0; /* imm */ \
305+
if r0 > 10 goto l0_%=; \
306+
r0 = 0; \
307+
exit; \
308+
" ::: __clobber_all);
309+
}
310+
311+
SEC("socket")
312+
__success __retval(0)
313+
__naked void may_goto_neg_off(void)
314+
{
315+
asm volatile (" \
316+
r0 = *(u32 *)(r10 - 4); \
317+
goto l0_%=; \
318+
goto l1_%=; \
319+
l0_%=: .byte 0xe5; /* may_goto */ \
320+
.byte 0; /* regs */ \
321+
.short -2; /* off -2 */ \
322+
.long 0; /* imm */ \
323+
if r0 > 10 goto l0_%=; \
324+
l1_%=: r0 = 0; \
325+
exit; \
326+
" ::: __clobber_all);
327+
}
328+
277329
SEC("tc")
278330
__failure
279331
__flag(BPF_F_TEST_STATE_FREQ)

0 commit comments

Comments
 (0)