[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bzbd8hgxggxmwMkLjZXGbroALhkY-JZzVpKgcWnaDZXRsA@mail.gmail.com>
Date: Thu, 13 Jun 2019 16:25:45 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <ast@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Daniel Borkmann <daniel@...earbox.net>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
Edward Cree <ecree@...arflare.com>,
john fastabend <john.fastabend@...il.com>,
Andrii Nakryiko <andriin@...com>, Jann Horn <jannh@...gle.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf-next 6/9] selftests/bpf: fix tests
On Thu, Jun 13, 2019 at 9:49 AM Alexei Starovoitov <ast@...nel.org> wrote:
>
> Fix tests that assumed no loops.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---
Acked-by: Andrii Nakryiko <andriin@...com>
> tools/testing/selftests/bpf/test_verifier.c | 11 ++++------
> tools/testing/selftests/bpf/verifier/calls.c | 22 ++++++++++++--------
> tools/testing/selftests/bpf/verifier/cfg.c | 11 ++++++----
> 3 files changed, 24 insertions(+), 20 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
> index cd0248c54e25..93e1d87a343a 100644
> --- a/tools/testing/selftests/bpf/test_verifier.c
> +++ b/tools/testing/selftests/bpf/test_verifier.c
> @@ -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;
> diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c
> index 9093a8f64dc6..2d752c4f8d9d 100644
> --- a/tools/testing/selftests/bpf/verifier/calls.c
> +++ b/tools/testing/selftests/bpf/verifier/calls.c
> @@ -215,9 +215,11 @@
> 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",
> @@ -250,22 +252,24 @@
> 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,
> },
> {
> diff --git a/tools/testing/selftests/bpf/verifier/cfg.c b/tools/testing/selftests/bpf/verifier/cfg.c
> index 349c0862fb4c..4eb76ed739ce 100644
> --- a/tools/testing/selftests/bpf/verifier/cfg.c
> +++ b/tools/testing/selftests/bpf/verifier/cfg.c
> @@ -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,
> },
> {
> @@ -53,18 +54,20 @@
> 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,
> },
> --
> 2.20.0
>
Powered by blists - more mailing lists