bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Edward Cree <ecree@solarflare.com>,
	john fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andriin@fb.com>, Jann Horn <jannh@google.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 2/9] selftests/bpf: fix tests due to const spill/fill
Date: Thu, 13 Jun 2019 15:09:24 -0700	[thread overview]
Message-ID: <CAEf4BzZPt_HwFiECemTsgXsE7J418rNa554-RZoPowrEosoXQA@mail.gmail.com> (raw)
In-Reply-To: <20190613042003.3791852-3-ast@kernel.org>

On Thu, Jun 13, 2019 at 9:50 AM Alexei Starovoitov <ast@kernel.org> wrote:
>
> fix tests that incorrectly assumed that the verifier
> cannot track constants through stack.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---

Acked-by: Andrii Nakryiko <andriin@fb.com>


>  .../bpf/verifier/direct_packet_access.c       |  3 +-
>  .../bpf/verifier/helper_access_var_len.c      | 28 ++++++++++---------
>  2 files changed, 17 insertions(+), 14 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/verifier/direct_packet_access.c b/tools/testing/selftests/bpf/verifier/direct_packet_access.c
> index d5c596fdc4b9..2c5fbe7bcd27 100644
> --- a/tools/testing/selftests/bpf/verifier/direct_packet_access.c
> +++ b/tools/testing/selftests/bpf/verifier/direct_packet_access.c
> @@ -511,7 +511,8 @@
>                     offsetof(struct __sk_buff, data)),
>         BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
>                     offsetof(struct __sk_buff, data_end)),
> -       BPF_MOV64_IMM(BPF_REG_0, 0xffffffff),
> +       BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
> +                   offsetof(struct __sk_buff, mark)),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8),
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffff),
> diff --git a/tools/testing/selftests/bpf/verifier/helper_access_var_len.c b/tools/testing/selftests/bpf/verifier/helper_access_var_len.c
> index 1f39d845c64f..67ab12410050 100644
> --- a/tools/testing/selftests/bpf/verifier/helper_access_var_len.c
> +++ b/tools/testing/selftests/bpf/verifier/helper_access_var_len.c
> @@ -29,9 +29,9 @@
>  {
>         "helper access to variable memory: stack, bitwise AND, zero included",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 64),
> @@ -46,9 +46,9 @@
>  {
>         "helper access to variable memory: stack, bitwise AND + JMP, wrong max",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 65),
> @@ -122,9 +122,9 @@
>  {
>         "helper access to variable memory: stack, JMP, bounds + offset",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 64, 5),
> @@ -143,9 +143,9 @@
>  {
>         "helper access to variable memory: stack, JMP, wrong max",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 65, 4),
> @@ -163,9 +163,9 @@
>  {
>         "helper access to variable memory: stack, JMP, no max check",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_MOV64_IMM(BPF_REG_4, 0),
> @@ -183,9 +183,9 @@
>  {
>         "helper access to variable memory: stack, JMP, no min check",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 64, 3),
> @@ -201,9 +201,9 @@
>  {
>         "helper access to variable memory: stack, JMP (signed), no min check",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
> -       BPF_MOV64_IMM(BPF_REG_2, 16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
>         BPF_JMP_IMM(BPF_JSGT, BPF_REG_2, 64, 3),
> @@ -244,6 +244,7 @@
>  {
>         "helper access to variable memory: map, JMP, wrong max",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
>         BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
> @@ -251,7 +252,7 @@
>         BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
>         BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 10),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
> -       BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
> +       BPF_MOV64_REG(BPF_REG_2, BPF_REG_6),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
>         BPF_JMP_IMM(BPF_JSGT, BPF_REG_2, sizeof(struct test_val) + 1, 4),
> @@ -262,7 +263,7 @@
>         BPF_MOV64_IMM(BPF_REG_0, 0),
>         BPF_EXIT_INSN(),
>         },
> -       .fixup_map_hash_48b = { 3 },
> +       .fixup_map_hash_48b = { 4 },
>         .errstr = "invalid access to map value, value_size=48 off=0 size=49",
>         .result = REJECT,
>         .prog_type = BPF_PROG_TYPE_TRACEPOINT,
> @@ -296,6 +297,7 @@
>  {
>         "helper access to variable memory: map adjusted, JMP, wrong max",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
>         BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
> @@ -304,7 +306,7 @@
>         BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 20),
> -       BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
> +       BPF_MOV64_REG(BPF_REG_2, BPF_REG_6),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
>         BPF_JMP_IMM(BPF_JSGT, BPF_REG_2, sizeof(struct test_val) - 19, 4),
> @@ -315,7 +317,7 @@
>         BPF_MOV64_IMM(BPF_REG_0, 0),
>         BPF_EXIT_INSN(),
>         },
> -       .fixup_map_hash_48b = { 3 },
> +       .fixup_map_hash_48b = { 4 },
>         .errstr = "R1 min value is outside of the array range",
>         .result = REJECT,
>         .prog_type = BPF_PROG_TYPE_TRACEPOINT,
> @@ -337,8 +339,8 @@
>  {
>         "helper access to variable memory: size > 0 not allowed on NULL (ARG_PTR_TO_MEM_OR_NULL)",
>         .insns = {
> +       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 0),
>         BPF_MOV64_IMM(BPF_REG_1, 0),
> -       BPF_MOV64_IMM(BPF_REG_2, 1),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 64),
> @@ -562,6 +564,7 @@
>  {
>         "helper access to variable memory: 8 bytes leak",
>         .insns = {
> +       BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, 8),
>         BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
>         BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
>         BPF_MOV64_IMM(BPF_REG_0, 0),
> @@ -572,7 +575,6 @@
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
> -       BPF_MOV64_IMM(BPF_REG_2, 1),
>         BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
>         BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
>         BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 63),
> --
> 2.20.0
>

  reply	other threads:[~2019-06-13 22:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13  4:19 [PATCH bpf-next 0/9] bpf: bounded loops and other features Alexei Starovoitov
2019-06-13  4:19 ` [PATCH bpf-next 1/9] bpf: track spill/fill of constants Alexei Starovoitov
2019-06-13 21:46   ` Andrii Nakryiko
2019-06-14  6:10     ` Alexei Starovoitov
2019-06-13  4:19 ` [PATCH bpf-next 2/9] selftests/bpf: fix tests due to const spill/fill Alexei Starovoitov
2019-06-13 22:09   ` Andrii Nakryiko [this message]
2019-06-13  4:19 ` [PATCH bpf-next 3/9] bpf: extend is_branch_taken to registers Alexei Starovoitov
2019-06-13 22:25   ` Andrii Nakryiko
2019-06-14  6:12     ` Alexei Starovoitov
2019-06-13  4:19 ` [PATCH bpf-next 4/9] bpf: introduce bounded loops Alexei Starovoitov
2019-06-13 23:04   ` Andrii Nakryiko
2019-06-14  6:18     ` Alexei Starovoitov
2019-06-13  4:19 ` [PATCH bpf-next 5/9] bpf: fix callees pruning callers Alexei Starovoitov
2019-06-13  4:20 ` [PATCH bpf-next 6/9] selftests/bpf: fix tests Alexei Starovoitov
2019-06-13 23:25   ` Andrii Nakryiko
2019-06-13  4:20 ` [PATCH bpf-next 7/9] selftests/bpf: add basic verifier tests for loops Alexei Starovoitov
2019-06-13  4:20 ` [PATCH bpf-next 8/9] selftests/bpf: add realistic loop tests Alexei Starovoitov
2019-06-13 23:33   ` Andrii Nakryiko
2019-06-14  6:20     ` Alexei Starovoitov
2019-06-13  4:20 ` [PATCH bpf-next 9/9] bpf: precise scalar_value tracking Alexei Starovoitov
2019-06-13  4:47 [PATCH bpf-next 0/9] bpf: bounded loops and other features Alexei Starovoitov
2019-06-13  4:47 ` [PATCH bpf-next 2/9] selftests/bpf: fix tests due to const spill/fill Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzZPt_HwFiECemTsgXsE7J418rNa554-RZoPowrEosoXQA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jannh@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).