aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Cree <ecree@solarflare.com>2017-09-15 09:37:38 -0400
committerDavid S. Miller <davem@davemloft.net>2017-09-15 18:01:32 -0400
commite67b8a685c7c984e834e3181ef4619cd7025a136 (patch)
treef6f0864ed6376f22696eee85a841e6bd38b820ec
parent8c7c19a55e41ae69d1cd18ab56e6e9b66a679a7c (diff)
bpf/verifier: reject BPF_ALU64|BPF_END
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>
-rw-r--r--kernel/bpf/verifier.c3
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c16
2 files changed, 18 insertions, 1 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 477b6932c3c1..799b2451ef2d 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2292,7 +2292,8 @@ static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)
2292 } 2292 }
2293 } else { 2293 } else {
2294 if (insn->src_reg != BPF_REG_0 || insn->off != 0 || 2294 if (insn->src_reg != BPF_REG_0 || insn->off != 0 ||
2295 (insn->imm != 16 && insn->imm != 32 && insn->imm != 64)) { 2295 (insn->imm != 16 && insn->imm != 32 && insn->imm != 64) ||
2296 BPF_CLASS(insn->code) == BPF_ALU64) {
2296 verbose("BPF_END uses reserved fields\n"); 2297 verbose("BPF_END uses reserved fields\n");
2297 return -EINVAL; 2298 return -EINVAL;
2298 } 2299 }
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 8eb09950258b..26f3250bdcd2 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -6629,6 +6629,22 @@ static struct bpf_test tests[] = {
6629 .result = REJECT, 6629 .result = REJECT,
6630 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, 6630 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
6631 }, 6631 },
6632 {
6633 "invalid 64-bit BPF_END",
6634 .insns = {
6635 BPF_MOV32_IMM(BPF_REG_0, 0),
6636 {
6637 .code = BPF_ALU64 | BPF_END | BPF_TO_LE,
6638 .dst_reg = BPF_REG_0,
6639 .src_reg = 0,
6640 .off = 0,
6641 .imm = 32,
6642 },
6643 BPF_EXIT_INSN(),
6644 },
6645 .errstr = "BPF_END uses reserved fields",
6646 .result = REJECT,
6647 },
6632}; 6648};
6633 6649
6634static int probe_filter_length(const struct bpf_insn *fp) 6650static int probe_filter_length(const struct bpf_insn *fp)