|
23 | 23 |
|
24 | 24 | #include "disasm.h"
|
25 | 25 |
|
| 26 | +static const struct bpf_verifier_ops * const bpf_verifier_ops[] = { |
| 27 | +#define BPF_PROG_TYPE(_id, _name) \ |
| 28 | + [_id] = & _name ## _verifier_ops, |
| 29 | +#define BPF_MAP_TYPE(_id, _ops) |
| 30 | +#include <linux/bpf_types.h> |
| 31 | +#undef BPF_PROG_TYPE |
| 32 | +#undef BPF_MAP_TYPE |
| 33 | +}; |
| 34 | + |
26 | 35 | /* bpf_check() is a static code analyzer that walks eBPF program
|
27 | 36 | * instruction by instruction and updates register/stack state.
|
28 | 37 | * All paths of conditional branches are analyzed until 'bpf_exit' insn.
|
@@ -856,8 +865,8 @@ static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off,
|
856 | 865 | *reg_type = info.reg_type;
|
857 | 866 | return 0;
|
858 | 867 | }
|
859 |
| - } else if (env->prog->aux->vops->is_valid_access && |
860 |
| - env->prog->aux->vops->is_valid_access(off, size, t, &info)) { |
| 868 | + } else if (env->ops->is_valid_access && |
| 869 | + env->ops->is_valid_access(off, size, t, &info)) { |
861 | 870 | /* A non zero info.ctx_field_size indicates that this field is a
|
862 | 871 | * candidate for later verifier transformation to load the whole
|
863 | 872 | * field and then apply a mask when accessed with a narrower
|
@@ -1565,8 +1574,8 @@ static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
|
1565 | 1574 | return -EINVAL;
|
1566 | 1575 | }
|
1567 | 1576 |
|
1568 |
| - if (env->prog->aux->vops->get_func_proto) |
1569 |
| - fn = env->prog->aux->vops->get_func_proto(func_id); |
| 1577 | + if (env->ops->get_func_proto) |
| 1578 | + fn = env->ops->get_func_proto(func_id); |
1570 | 1579 |
|
1571 | 1580 | if (!fn) {
|
1572 | 1581 | verbose(env, "unknown func %s#%d\n", func_id_name(func_id),
|
@@ -4035,7 +4044,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of
|
4035 | 4044 | */
|
4036 | 4045 | static int convert_ctx_accesses(struct bpf_verifier_env *env)
|
4037 | 4046 | {
|
4038 |
| - const struct bpf_verifier_ops *ops = env->prog->aux->vops; |
| 4047 | + const struct bpf_verifier_ops *ops = env->ops; |
4039 | 4048 | int i, cnt, size, ctx_field_size, delta = 0;
|
4040 | 4049 | const int insn_cnt = env->prog->len;
|
4041 | 4050 | struct bpf_insn insn_buf[16], *insn;
|
@@ -4236,7 +4245,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
|
4236 | 4245 | insn = new_prog->insnsi + i + delta;
|
4237 | 4246 | }
|
4238 | 4247 | patch_call_imm:
|
4239 |
| - fn = prog->aux->vops->get_func_proto(insn->imm); |
| 4248 | + fn = env->ops->get_func_proto(insn->imm); |
4240 | 4249 | /* all functions that have prototype and verifier allowed
|
4241 | 4250 | * programs to call them, must be real in-kernel functions
|
4242 | 4251 | */
|
@@ -4294,6 +4303,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
|
4294 | 4303 | if (!env->insn_aux_data)
|
4295 | 4304 | goto err_free_env;
|
4296 | 4305 | env->prog = *prog;
|
| 4306 | + env->ops = bpf_verifier_ops[env->prog->type]; |
4297 | 4307 |
|
4298 | 4308 | /* grab the mutex to protect few globals used by verifier */
|
4299 | 4309 | mutex_lock(&bpf_verifier_lock);
|
@@ -4406,6 +4416,7 @@ int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
|
4406 | 4416 | if (!env->insn_aux_data)
|
4407 | 4417 | goto err_free_env;
|
4408 | 4418 | env->prog = prog;
|
| 4419 | + env->ops = bpf_verifier_ops[env->prog->type]; |
4409 | 4420 | env->analyzer_ops = ops;
|
4410 | 4421 | env->analyzer_priv = priv;
|
4411 | 4422 |
|
|
0 commit comments