Skip to content

Commit d519594

Browse files
Amery HungAlexei Starovoitov
authored andcommitted
bpf: Search and add kfuncs in struct_ops prologue and epilogue
Currently, add_kfunc_call() is only invoked once before the main verification loop. Therefore, the verifier could not find the bpf_kfunc_btf_tab of a new kfunc call which is not seen in user defined struct_ops operators but introduced in gen_prologue or gen_epilogue during do_misc_fixup(). Fix this by searching kfuncs in the patching instruction buffer and add them to prog->aux->kfunc_tab. Signed-off-by: Amery Hung <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent f3c2d24 commit d519594

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3275,6 +3275,21 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
32753275
return res ? &res->func_model : NULL;
32763276
}
32773277

3278+
static int add_kfunc_in_insns(struct bpf_verifier_env *env,
3279+
struct bpf_insn *insn, int cnt)
3280+
{
3281+
int i, ret;
3282+
3283+
for (i = 0; i < cnt; i++, insn++) {
3284+
if (bpf_pseudo_kfunc_call(insn)) {
3285+
ret = add_kfunc_call(env, insn->imm, insn->off);
3286+
if (ret < 0)
3287+
return ret;
3288+
}
3289+
}
3290+
return 0;
3291+
}
3292+
32783293
static int add_subprog_and_kfunc(struct bpf_verifier_env *env)
32793294
{
32803295
struct bpf_subprog_info *subprog = env->subprog_info;
@@ -20433,7 +20448,7 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
2043320448
{
2043420449
struct bpf_subprog_info *subprogs = env->subprog_info;
2043520450
const struct bpf_verifier_ops *ops = env->ops;
20436-
int i, cnt, size, ctx_field_size, delta = 0, epilogue_cnt = 0;
20451+
int i, cnt, size, ctx_field_size, ret, delta = 0, epilogue_cnt = 0;
2043720452
const int insn_cnt = env->prog->len;
2043820453
struct bpf_insn *epilogue_buf = env->epilogue_buf;
2043920454
struct bpf_insn *insn_buf = env->insn_buf;
@@ -20462,6 +20477,10 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
2046220477
return -ENOMEM;
2046320478
env->prog = new_prog;
2046420479
delta += cnt - 1;
20480+
20481+
ret = add_kfunc_in_insns(env, epilogue_buf, epilogue_cnt - 1);
20482+
if (ret < 0)
20483+
return ret;
2046520484
}
2046620485
}
2046720486

@@ -20482,6 +20501,10 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
2048220501

2048320502
env->prog = new_prog;
2048420503
delta += cnt - 1;
20504+
20505+
ret = add_kfunc_in_insns(env, insn_buf, cnt - 1);
20506+
if (ret < 0)
20507+
return ret;
2048520508
}
2048620509
}
2048720510

0 commit comments

Comments
 (0)