From: Alexei Starovoitov 'tbl[i]()' loads a pointer from a table of functions in .rodata. When i is not a constant, the verifier continues with one state for each pointer that the load can give. It rejects a load that can give more than 64 pointers. Rust needs more. In one prog of rust-bpf, fmt() of a trait object has 245 implementations. The limit of 64 is arbitrary. Raise it to BPF_MAX_SUBPROGS. A table that contains each function one time cannot have more entries. The array of targets is now too large for the kernel stack, thus allocate it. Signed-off-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 93ca0126a310..d503dc7cea1f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7068,7 +7068,7 @@ static void mark_reg_func_ptr(struct bpf_verifier_env *env, struct bpf_reg_state } /* a read from a table of functions branches into that many states at most */ -#define BPF_MAX_FUNC_PTR_TARGETS 64 +#define BPF_MAX_FUNC_PTR_TARGETS BPF_MAX_SUBPROGS /* and that many pointers at most are next to what is read at variable offset */ #define BPF_MAX_FUNC_PTR_RANGE 4096 @@ -7114,17 +7114,20 @@ static int check_func_ptr_read(struct bpf_verifier_env *env, struct bpf_reg_stat struct bpf_reg_state *regs = cur_regs(env); struct bpf_map *map = reg->map_ptr; struct bpf_verifier_state *branch; - int subprog, targets[BPF_MAX_FUNC_PTR_TARGETS]; + u16 *targets __free(kfree) = NULL; struct bpf_func_ptr *ptrs; u32 i, cnt, n = 0; u64 o, lo, hi; - int err; + int err, subprog; ptrs = bpf_map_range_func_ptrs(env, map, min_off, max_off - min_off + size, &cnt); if (!ptrs) return -ENOENT; if (cnt > BPF_MAX_FUNC_PTR_RANGE) goto overlap; + targets = kmalloc_array(BPF_MAX_FUNC_PTR_TARGETS, sizeof(*targets), GFP_KERNEL_ACCOUNT); + if (!targets) + return -ENOMEM; for (i = 0; i < cnt; i++) { /* the offsets at which the read overlaps with the pointer */ -- 2.55.0