Subprogram name can be computed from function info and BTF, but it is convenient to have the name readily available for logging purposes. Signed-off-by: Eduard Zingerman --- include/linux/bpf_verifier.h | 1 + kernel/bpf/verifier.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 15f7f9f35be98f6f30c46cdf03cf5c0249a8ac38..410939d7b3253f62c18b85072c921395709d7a3a 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -664,6 +664,7 @@ enum priv_stack_mode { }; struct bpf_subprog_info { + const char *name; /* 'start' has to be the first field otherwise find_subprog() won't work */ u32 start; /* insn idx of function entry point */ u32 linfo_idx; /* The idx to the main_prog->aux->linfo */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index dd81cfbad680712e4d871163b8ee179fafe8587c..c1da28de869cbb395dee7d7f700d90113af9f433 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3635,9 +3635,12 @@ static int add_kfunc_in_insns(struct bpf_verifier_env *env, static int add_subprog_and_kfunc(struct bpf_verifier_env *env) { + struct bpf_func_info *func_info = env->prog->aux->func_info; struct bpf_subprog_info *subprog = env->subprog_info; int i, ret, insn_cnt = env->prog->len, ex_cb_insn; struct bpf_insn *insn = env->prog->insnsi; + struct btf *btf = env->prog->aux->btf; + const struct btf_type *t; /* Add entry function. */ ret = add_subprog(env, 0); @@ -3689,9 +3692,16 @@ static int add_subprog_and_kfunc(struct bpf_verifier_env *env) */ subprog[env->subprog_cnt].start = insn_cnt; + if (func_info) { + for (i = 0; i < env->subprog_cnt; i++) { + t = btf_type_by_id(btf, func_info[i].type_id); + subprog[i].name = btf_name_by_offset(btf, t->name_off); + } + } + if (env->log.level & BPF_LOG_LEVEL2) for (i = 0; i < env->subprog_cnt; i++) - verbose(env, "func#%d @%d\n", i, subprog[i].start); + verbose(env, "func#%d @%d %s\n", i, subprog[i].start, subprog[i].name ?: ""); return 0; } -- 2.53.0