]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
nfp: bpf: reject program on instructions unknown to the JIT compiler
authorQuentin Monnet <quentin.monnet@netronome.com>
Tue, 16 Jan 2018 23:51:50 +0000 (15:51 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 17 Jan 2018 00:15:06 +0000 (01:15 +0100)
If an eBPF instruction is unknown to the driver JIT compiler, we can
reject the program at verification time.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/ethernet/netronome/nfp/bpf/jit.c
drivers/net/ethernet/netronome/nfp/bpf/main.h
drivers/net/ethernet/netronome/nfp/bpf/verifier.c

index cdc949fabe98429646bd78e487cf982b92d179aa..56451edf01c2c689ee8199aa765f59e4ffa21d8e 100644 (file)
@@ -2907,6 +2907,11 @@ void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog, unsigned int cnt)
        }
 }
 
+bool nfp_bpf_supported_opcode(u8 code)
+{
+       return !!instr_cb[code];
+}
+
 void *nfp_bpf_relo_for_vnic(struct nfp_prog *nfp_prog, struct nfp_bpf_vnic *bv)
 {
        unsigned int i;
index b80e75a8ecdac2590b737eed4aa0bb512e8e6c63..c476bca15ba405cb3c8c771b546c2d54298ed982 100644 (file)
@@ -324,6 +324,7 @@ struct nfp_bpf_vnic {
 
 void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog, unsigned int cnt);
 int nfp_bpf_jit(struct nfp_prog *prog);
+bool nfp_bpf_supported_opcode(u8 code);
 
 extern const struct bpf_prog_offload_ops nfp_bpf_analyzer_ops;
 
index 81dab462456ccbf1d089a9a3a09893042e5aff59..479f602887e947fe60a14baad9718f84072fa29b 100644 (file)
@@ -290,6 +290,12 @@ nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx)
        meta = nfp_bpf_goto_meta(nfp_prog, meta, insn_idx, env->prog->len);
        nfp_prog->verifier_meta = meta;
 
+       if (!nfp_bpf_supported_opcode(meta->insn.code)) {
+               pr_vlog(env, "instruction %#02x not supported\n",
+                       meta->insn.code);
+               return -EINVAL;
+       }
+
        if (meta->insn.src_reg >= MAX_BPF_REG ||
            meta->insn.dst_reg >= MAX_BPF_REG) {
                pr_vlog(env, "program uses extended registers - jit hardening?\n");