From: Alexei Starovoitov A number goes up by 3. In front of the jump that counts the loop it moves over S64_MAX in one pair of progs and by S64_MAX in the other. The store behind the jump takes it as an index. In the progs that have to be rejected the store is one byte behind the value at run time. Signed-off-by: Alexei Starovoitov --- .../selftests/bpf/progs/verifier_loop_latch.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_loop_latch.c b/tools/testing/selftests/bpf/progs/verifier_loop_latch.c index 12c1cb2f0384..8b9a2853ea05 100644 --- a/tools/testing/selftests/bpf/progs/verifier_loop_latch.c +++ b/tools/testing/selftests/bpf/progs/verifier_loop_latch.c @@ -117,6 +117,29 @@ LOOP(behind_moved, "w8 = 0; r9 = r6; r9 += 2043;", MOVED(4) "goto 1b;") BAD("a store behind the jump that counts, the pointer has moved too far") LOOP(behind_moved_bad, "w8 = 0; r9 = r6; r9 += 2044;", MOVED(4) "goto 1b;") +/* + * A number goes up by 3 and has moved in front of the jump. At the store it is @first or + * @first + 3. Moved over S64_MAX it has another residue: 2^64 is not a multiple of 3. It keeps + * the range of all three iterations then. + */ +#define NUM(by, back, first, off) \ + "r3 = " #by " ll; r9 += r3; if w8 == 2 goto 9f; r2 = r9; r3 = " #first " ll; r2 -= r3;" \ + "r2 += r5; *(u8 *)(r2 + " #off ") = r1; r3 = " #back " ll; r9 += r3; w8 += 1; goto 1b;" +#define OVER(off) NUM(100, -97, 0x8000000000000031, off) +#define FAR(off) NUM(0x7fffffffffffffff, 0x8000000000000004, 0x7ffffffffffffffa, off) + +OK("behind the jump that counts, a number has moved over S64_MAX", "3") +LOOP(moved_over, "w8 = 0; r5 = r6; r9 = 0x7fffffffffffffcd ll;", OVER(2041)) + +BAD("behind the jump that counts, a number has moved over S64_MAX, too far") +LOOP(moved_over_bad, "w8 = 0; r5 = r6; r9 = 0x7fffffffffffffcd ll;", OVER(2045)) + +OK("behind the jump that counts, a number has moved by S64_MAX", "3") +LOOP(moved_far, "w8 = 0; r5 = r6; r9 = -5;", FAR(2044)) + +BAD("behind the jump that counts, a number has moved by S64_MAX, one too far") +LOOP(moved_far_bad, "w8 = 0; r5 = r6; r9 = -5;", FAR(2045)) + OK("a store behind the jump that counts two back edges", "5") LOOP(behind_two, "w8 = 0; r9 = r6; r9 += 2044;", AT_TOP(4) "if r7 == 7 goto 1b; goto 1b;")