]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
selftests/bpf: fix tests
authorAlexei Starovoitov <ast@kernel.org>
Sat, 15 Jun 2019 19:12:22 +0000 (12:12 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 19 Jun 2019 00:22:52 +0000 (02:22 +0200)
Fix tests that assumed no loops.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/test_verifier.c
tools/testing/selftests/bpf/verifier/calls.c
tools/testing/selftests/bpf/verifier/cfg.c

index cd0248c54e251debcd371eba31ec23a6099b1f6d..93e1d87a343abb96f815239fd4317010b8f2b5fa 100644 (file)
@@ -237,10 +237,10 @@ static void bpf_fill_scale1(struct bpf_test *self)
                insn[i++] = BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_6,
                                        -8 * (k % 64 + 1));
        }
-       /* every jump adds 1 step to insn_processed, so to stay exactly
-        * within 1m limit add MAX_TEST_INSNS - MAX_JMP_SEQ - 1 MOVs and 1 EXIT
+       /* is_state_visited() doesn't allocate state for pruning for every jump.
+        * Hence multiply jmps by 4 to accommodate that heuristic
         */
-       while (i < MAX_TEST_INSNS - MAX_JMP_SEQ - 1)
+       while (i < MAX_TEST_INSNS - MAX_JMP_SEQ * 4)
                insn[i++] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 42);
        insn[i] = BPF_EXIT_INSN();
        self->prog_len = i + 1;
@@ -269,10 +269,7 @@ static void bpf_fill_scale2(struct bpf_test *self)
                insn[i++] = BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_6,
                                        -8 * (k % (64 - 4 * FUNC_NEST) + 1));
        }
-       /* every jump adds 1 step to insn_processed, so to stay exactly
-        * within 1m limit add MAX_TEST_INSNS - MAX_JMP_SEQ - 1 MOVs and 1 EXIT
-        */
-       while (i < MAX_TEST_INSNS - MAX_JMP_SEQ - 1)
+       while (i < MAX_TEST_INSNS - MAX_JMP_SEQ * 4)
                insn[i++] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 42);
        insn[i] = BPF_EXIT_INSN();
        self->prog_len = i + 1;
index 9093a8f64dc6105b34c7f35d61e14bb18192c610..2d752c4f8d9d48373f417c352b4db584d7bd91ec 100644 (file)
        BPF_MOV64_IMM(BPF_REG_0, 3),
        BPF_JMP_IMM(BPF_JA, 0, 0, -6),
        },
-       .prog_type = BPF_PROG_TYPE_TRACEPOINT,
-       .errstr = "back-edge from insn",
-       .result = REJECT,
+       .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
+       .errstr_unpriv = "back-edge from insn",
+       .result_unpriv = REJECT,
+       .result = ACCEPT,
+       .retval = 1,
 },
 {
        "calls: conditional call 4",
        BPF_MOV64_IMM(BPF_REG_0, 3),
        BPF_EXIT_INSN(),
        },
-       .prog_type = BPF_PROG_TYPE_TRACEPOINT,
-       .errstr = "back-edge from insn",
-       .result = REJECT,
+       .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+       .result = ACCEPT,
+       .retval = 1,
 },
 {
        "calls: conditional call 6",
        .insns = {
+       BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
+       BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
        BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
-       BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, -2),
+       BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, -3),
        BPF_EXIT_INSN(),
        BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
                    offsetof(struct __sk_buff, mark)),
        BPF_EXIT_INSN(),
        },
-       .prog_type = BPF_PROG_TYPE_TRACEPOINT,
-       .errstr = "back-edge from insn",
+       .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+       .errstr = "infinite loop detected",
        .result = REJECT,
 },
 {
index 349c0862fb4c1e279d7ab77eca6a8a665b48aa37..4eb76ed739ce9ea0375cf23d80d7187cb512f486 100644 (file)
@@ -41,7 +41,8 @@
        BPF_JMP_IMM(BPF_JA, 0, 0, -1),
        BPF_EXIT_INSN(),
        },
-       .errstr = "back-edge",
+       .errstr = "unreachable insn 1",
+       .errstr_unpriv = "back-edge",
        .result = REJECT,
 },
 {
        BPF_JMP_IMM(BPF_JA, 0, 0, -4),
        BPF_EXIT_INSN(),
        },
-       .errstr = "back-edge",
+       .errstr = "unreachable insn 4",
+       .errstr_unpriv = "back-edge",
        .result = REJECT,
 },
 {
        "conditional loop",
        .insns = {
-       BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
+       BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
        BPF_MOV64_REG(BPF_REG_2, BPF_REG_0),
        BPF_MOV64_REG(BPF_REG_3, BPF_REG_0),
        BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, -3),
        BPF_EXIT_INSN(),
        },
-       .errstr = "back-edge",
+       .errstr = "infinite loop detected",
+       .errstr_unpriv = "back-edge",
        .result = REJECT,
 },