bpf/verifier: reject BPF_ALU64|BPF_END
authorEdward Cree <ecree@solarflare.com>
Fri, 15 Sep 2017 13:37:38 +0000 (14:37 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Sep 2017 22:01:32 +0000 (15:01 -0700)
Neither ___bpf_prog_run nor the JITs accept it.
Also adds a new test case.

Fixes: 17a5267067f3 ("bpf: verifier (add verifier core)")
Signed-off-by: Edward Cree <ecree@solarflare.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/test_verifier.c

index 477b6932c3c1f2b9a1639b75f7ec919ba45e422c..799b2451ef2df42b17aadfe679a09dee9a0848c9 100644 (file)
@@ -2292,7 +2292,8 @@ static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)
                        }
                } else {
                        if (insn->src_reg != BPF_REG_0 || insn->off != 0 ||
-                           (insn->imm != 16 && insn->imm != 32 && insn->imm != 64)) {
+                           (insn->imm != 16 && insn->imm != 32 && insn->imm != 64) ||
+                           BPF_CLASS(insn->code) == BPF_ALU64) {
                                verbose("BPF_END uses reserved fields\n");
                                return -EINVAL;
                        }
index 8eb09950258bbcaee42b498d9f64953e1e74582a..26f3250bdcd2546c4f316eed8caffd9eb583e0d9 100644 (file)
@@ -6629,6 +6629,22 @@ static struct bpf_test tests[] = {
                .result = REJECT,
                .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
        },
+       {
+               "invalid 64-bit BPF_END",
+               .insns = {
+                       BPF_MOV32_IMM(BPF_REG_0, 0),
+                       {
+                               .code  = BPF_ALU64 | BPF_END | BPF_TO_LE,
+                               .dst_reg = BPF_REG_0,
+                               .src_reg = 0,
+                               .off   = 0,
+                               .imm   = 32,
+                       },
+                       BPF_EXIT_INSN(),
+               },
+               .errstr = "BPF_END uses reserved fields",
+               .result = REJECT,
+       },
 };
 
 static int probe_filter_length(const struct bpf_insn *fp)