|
21 | 21 | #include <linux/vmalloc.h>
|
22 | 22 | #include <linux/stringify.h>
|
23 | 23 |
|
| 24 | +static const struct bpf_verifier_ops * const bpf_verifier_ops[] = { |
| 25 | +#define BPF_PROG_TYPE(_id, _name) \ |
| 26 | + [_id] = & _name ## _verifier_ops, |
| 27 | +#define BPF_MAP_TYPE(_id, _ops) |
| 28 | +#include <linux/bpf_types.h> |
| 29 | +#undef BPF_PROG_TYPE |
| 30 | +#undef BPF_MAP_TYPE |
| 31 | +}; |
| 32 | + |
24 | 33 | /* bpf_check() is a static code analyzer that walks eBPF program
|
25 | 34 | * instruction by instruction and updates register/stack state.
|
26 | 35 | * All paths of conditional branches are analyzed until 'bpf_exit' insn.
|
@@ -1145,8 +1154,8 @@ static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off,
|
1145 | 1154 | *reg_type = info.reg_type;
|
1146 | 1155 | return 0;
|
1147 | 1156 | }
|
1148 |
| - } else if (env->prog->aux->vops->is_valid_access && |
1149 |
| - env->prog->aux->vops->is_valid_access(off, size, t, &info)) { |
| 1157 | + } else if (env->ops->is_valid_access && |
| 1158 | + env->ops->is_valid_access(off, size, t, &info)) { |
1150 | 1159 | /* A non zero info.ctx_field_size indicates that this field is a
|
1151 | 1160 | * candidate for later verifier transformation to load the whole
|
1152 | 1161 | * field and then apply a mask when accessed with a narrower
|
@@ -1882,8 +1891,8 @@ static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
|
1882 | 1891 | return -EINVAL;
|
1883 | 1892 | }
|
1884 | 1893 |
|
1885 |
| - if (env->prog->aux->vops->get_func_proto) |
1886 |
| - fn = env->prog->aux->vops->get_func_proto(func_id); |
| 1894 | + if (env->ops->get_func_proto) |
| 1895 | + fn = env->ops->get_func_proto(func_id); |
1887 | 1896 |
|
1888 | 1897 | if (!fn) {
|
1889 | 1898 | verbose("unknown func %s#%d\n", func_id_name(func_id), func_id);
|
@@ -4607,7 +4616,7 @@ static void sanitize_dead_code(struct bpf_verifier_env *env)
|
4607 | 4616 | */
|
4608 | 4617 | static int convert_ctx_accesses(struct bpf_verifier_env *env)
|
4609 | 4618 | {
|
4610 |
| - const struct bpf_verifier_ops *ops = env->prog->aux->vops; |
| 4619 | + const struct bpf_verifier_ops *ops = env->ops; |
4611 | 4620 | int i, cnt, size, ctx_field_size, delta = 0;
|
4612 | 4621 | const int insn_cnt = env->prog->len;
|
4613 | 4622 | struct bpf_insn insn_buf[16], *insn;
|
@@ -4936,7 +4945,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
|
4936 | 4945 | insn = new_prog->insnsi + i + delta;
|
4937 | 4946 | }
|
4938 | 4947 | patch_call_imm:
|
4939 |
| - fn = prog->aux->vops->get_func_proto(insn->imm); |
| 4948 | + fn = env->ops->get_func_proto(insn->imm); |
4940 | 4949 | /* all functions that have prototype and verifier allowed
|
4941 | 4950 | * programs to call them, must be real in-kernel functions
|
4942 | 4951 | */
|
@@ -4993,6 +5002,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
|
4993 | 5002 | if (!env->insn_aux_data)
|
4994 | 5003 | goto err_free_env;
|
4995 | 5004 | env->prog = *prog;
|
| 5005 | + env->ops = bpf_verifier_ops[env->prog->type]; |
4996 | 5006 |
|
4997 | 5007 | /* grab the mutex to protect few globals used by verifier */
|
4998 | 5008 | mutex_lock(&bpf_verifier_lock);
|
@@ -5128,6 +5138,7 @@ int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
|
5128 | 5138 | if (!env->insn_aux_data)
|
5129 | 5139 | goto err_free_env;
|
5130 | 5140 | env->prog = prog;
|
| 5141 | + env->ops = bpf_verifier_ops[env->prog->type]; |
5131 | 5142 | env->analyzer_ops = ops;
|
5132 | 5143 | env->analyzer_priv = priv;
|
5133 | 5144 |
|
|
0 commit comments