Skip to content

Commit 1fb3158

Browse files
eddyz87anakryiko
authored andcommitted
selftests/bpf: Test with a very short loop
The test added is a simplified reproducer from syzbot report [1]. If verifier does not insert checkpoint somewhere inside the loop, verification of the program would take a very long time. This would happen because mark_chain_precision() for register r7 would constantly trace jump history of the loop back, processing many iterations for each mark_chain_precision() call. [1] https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent aa30eb3 commit 1fb3158

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Converted from tools/testing/selftests/bpf/verifier/search_pruning.c */
33

44
#include <linux/bpf.h>
5+
#include <../../../include/linux/filter.h>
56
#include <bpf/bpf_helpers.h>
67
#include "bpf_misc.h"
78

@@ -336,4 +337,26 @@ l0_%=: r1 = 42; \
336337
: __clobber_all);
337338
}
338339

340+
/* Without checkpoint forcibly inserted at the back-edge a loop this
341+
* test would take a very long time to verify.
342+
*/
343+
SEC("kprobe")
344+
__failure __log_level(4)
345+
__msg("BPF program is too large.")
346+
__naked void short_loop1(void)
347+
{
348+
asm volatile (
349+
" r7 = *(u16 *)(r1 +0);"
350+
"1: r7 += 0x1ab064b9;"
351+
" .8byte %[jset];" /* same as 'if r7 & 0x702000 goto 1b;' */
352+
" r7 &= 0x1ee60e;"
353+
" r7 += r1;"
354+
" if r7 s> 0x37d2 goto +0;"
355+
" r0 = 0;"
356+
" exit;"
357+
:
358+
: __imm_insn(jset, BPF_JMP_IMM(BPF_JSET, BPF_REG_7, 0x702000, -2))
359+
: __clobber_all);
360+
}
361+
339362
char _license[] SEC("license") = "GPL";

tools/testing/selftests/bpf/veristat.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ test_usdt*
1515
test_verif_scale*
1616
test_xdp_noinline*
1717
xdp_synproxy*
18+
verifier_search_pruning*

0 commit comments

Comments
 (0)