diff mbox series

bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

Message ID 20201006231706.2744579-1-haoluo@google.com
State New
Headers show
Series bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64 | expand

Commit Message

Hao Luo Oct. 6, 2020, 11:17 p.m. UTC
Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched
the order of check_subprogs() and resolve_pseudo_ldimm() in
the verifier. Now an empty prog and the prog of a single
invalid ldimm expect to see the error "last insn is not an
exit or jmp" instead, because the check for subprogs comes
first. Fix the expection of the error message.

Tested:
 # ./test_verifier
 Summary: 1130 PASSED, 538 SKIPPED, 0 FAILED
 and the full set of bpf selftests.

Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id")
Signed-off-by: Hao Luo <haoluo@google.com>
---
 tools/testing/selftests/bpf/verifier/basic.c    | 2 +-
 tools/testing/selftests/bpf/verifier/ld_imm64.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko Oct. 7, 2020, 12:43 a.m. UTC | #1
On Tue, Oct 6, 2020 at 4:45 PM Hao Luo <haoluo@google.com> wrote:
>

> Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched

> the order of check_subprogs() and resolve_pseudo_ldimm() in

> the verifier. Now an empty prog and the prog of a single

> invalid ldimm expect to see the error "last insn is not an

> exit or jmp" instead, because the check for subprogs comes

> first. Fix the expection of the error message.

>

> Tested:

>  # ./test_verifier

>  Summary: 1130 PASSED, 538 SKIPPED, 0 FAILED

>  and the full set of bpf selftests.

>

> Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id")

> Signed-off-by: Hao Luo <haoluo@google.com>

> ---

>  tools/testing/selftests/bpf/verifier/basic.c    | 2 +-

>  tools/testing/selftests/bpf/verifier/ld_imm64.c | 2 +-

>  2 files changed, 2 insertions(+), 2 deletions(-)

>

> diff --git a/tools/testing/selftests/bpf/verifier/basic.c b/tools/testing/selftests/bpf/verifier/basic.c

> index b8d18642653a..de84f0d57082 100644

> --- a/tools/testing/selftests/bpf/verifier/basic.c

> +++ b/tools/testing/selftests/bpf/verifier/basic.c

> @@ -2,7 +2,7 @@

>         "empty prog",

>         .insns = {

>         },

> -       .errstr = "unknown opcode 00",

> +       .errstr = "last insn is not an exit or jmp",


in this case the new message makes more sense, so this is a good change

>         .result = REJECT,

>  },

>  {

> diff --git a/tools/testing/selftests/bpf/verifier/ld_imm64.c b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> index 3856dba733e9..f300ba62edd0 100644

> --- a/tools/testing/selftests/bpf/verifier/ld_imm64.c

> +++ b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> @@ -55,7 +55,7 @@

>         .insns = {

>         BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),

>         },

> -       .errstr = "invalid bpf_ld_imm64 insn",

> +       .errstr = "last insn is not an exit or jmp",


but this completely defeats the purpose of the test; better add
BPF_EXIT_INSN() after ldimm64 instruction to actually get to
validation of ldimm64

>         .result = REJECT,

>  },

>  {

> --

> 2.28.0.806.g8561365e88-goog

>
Hao Luo Oct. 7, 2020, 12:50 a.m. UTC | #2
On Tue, Oct 6, 2020 at 5:43 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>

> On Tue, Oct 6, 2020 at 4:45 PM Hao Luo <haoluo@google.com> wrote:

> >

> > Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched

> > the order of check_subprogs() and resolve_pseudo_ldimm() in

> > the verifier. Now an empty prog and the prog of a single

> > invalid ldimm expect to see the error "last insn is not an

> > exit or jmp" instead, because the check for subprogs comes

> > first. Fix the expection of the error message.

> >

> > Tested:

> >  # ./test_verifier

> >  Summary: 1130 PASSED, 538 SKIPPED, 0 FAILED

> >  and the full set of bpf selftests.

> >

> > Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id")

> > Signed-off-by: Hao Luo <haoluo@google.com>

> > ---

[...]
> > diff --git a/tools/testing/selftests/bpf/verifier/ld_imm64.c b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > index 3856dba733e9..f300ba62edd0 100644

> > --- a/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > +++ b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > @@ -55,7 +55,7 @@

> >         .insns = {

> >         BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),

> >         },

> > -       .errstr = "invalid bpf_ld_imm64 insn",

> > +       .errstr = "last insn is not an exit or jmp",

>

> but this completely defeats the purpose of the test; better add

> BPF_EXIT_INSN() after ldimm64 instruction to actually get to

> validation of ldimm64

>


Actually there is already a test (test4) that covers this case. So it
makes sense to remove it, I think. I will resend with this change.

> >         .result = REJECT,

> >  },

> >  {

> > --

> > 2.28.0.806.g8561365e88-goog

> >
Andrii Nakryiko Oct. 7, 2020, 12:56 a.m. UTC | #3
On Tue, Oct 6, 2020 at 5:51 PM Hao Luo <haoluo@google.com> wrote:
>

> On Tue, Oct 6, 2020 at 5:43 PM Andrii Nakryiko

> <andrii.nakryiko@gmail.com> wrote:

> >

> > On Tue, Oct 6, 2020 at 4:45 PM Hao Luo <haoluo@google.com> wrote:

> > >

> > > Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched

> > > the order of check_subprogs() and resolve_pseudo_ldimm() in

> > > the verifier. Now an empty prog and the prog of a single

> > > invalid ldimm expect to see the error "last insn is not an

> > > exit or jmp" instead, because the check for subprogs comes

> > > first. Fix the expection of the error message.

> > >

> > > Tested:

> > >  # ./test_verifier

> > >  Summary: 1130 PASSED, 538 SKIPPED, 0 FAILED

> > >  and the full set of bpf selftests.

> > >

> > > Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id")

> > > Signed-off-by: Hao Luo <haoluo@google.com>

> > > ---

> [...]

> > > diff --git a/tools/testing/selftests/bpf/verifier/ld_imm64.c b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > > index 3856dba733e9..f300ba62edd0 100644

> > > --- a/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > > +++ b/tools/testing/selftests/bpf/verifier/ld_imm64.c

> > > @@ -55,7 +55,7 @@

> > >         .insns = {

> > >         BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),

> > >         },

> > > -       .errstr = "invalid bpf_ld_imm64 insn",

> > > +       .errstr = "last insn is not an exit or jmp",

> >

> > but this completely defeats the purpose of the test; better add

> > BPF_EXIT_INSN() after ldimm64 instruction to actually get to

> > validation of ldimm64

> >

>

> Actually there is already a test (test4) that covers this case. So it

> makes sense to remove it, I think. I will resend with this change.


ah, this test validates that half of ldimm64 at the very end won't
cause any troubles to verifier... Yeah, I guess now it's pointless
because it can never be the very last instruction.

>

> > >         .result = REJECT,

> > >  },

> > >  {

> > > --

> > > 2.28.0.806.g8561365e88-goog

> > >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/verifier/basic.c b/tools/testing/selftests/bpf/verifier/basic.c
index b8d18642653a..de84f0d57082 100644
--- a/tools/testing/selftests/bpf/verifier/basic.c
+++ b/tools/testing/selftests/bpf/verifier/basic.c
@@ -2,7 +2,7 @@ 
 	"empty prog",
 	.insns = {
 	},
-	.errstr = "unknown opcode 00",
+	.errstr = "last insn is not an exit or jmp",
 	.result = REJECT,
 },
 {
diff --git a/tools/testing/selftests/bpf/verifier/ld_imm64.c b/tools/testing/selftests/bpf/verifier/ld_imm64.c
index 3856dba733e9..f300ba62edd0 100644
--- a/tools/testing/selftests/bpf/verifier/ld_imm64.c
+++ b/tools/testing/selftests/bpf/verifier/ld_imm64.c
@@ -55,7 +55,7 @@ 
 	.insns = {
 	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),
 	},
-	.errstr = "invalid bpf_ld_imm64 insn",
+	.errstr = "last insn is not an exit or jmp",
 	.result = REJECT,
 },
 {