When adding tracing_multi link support for bpf progs, it must handle tgt_prog first in bpf_check_attach_target() to avoid the case: the btf_id is a valid BTF ID of tgt_prog, and also is "bpf_multi_func_btf_id[0]". Signed-off-by: Leon Hwang --- kernel/bpf/verifier.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2f190abe3448..f2af2bbdd6fb 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -22284,22 +22284,24 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, return -EOPNOTSUPP; } - /* - * *.multi programs don't need an address during program - * verification, we just take the module ref if needed. - */ - if (is_tracing_multi_id(prog, btf_id)) { + if (tgt_prog) { + if (subprog == 0) + addr = (long)tgt_prog->bpf_func; + else + addr = (long)tgt_prog->aux->func[subprog]->bpf_func; + } else if (is_tracing_multi_id(prog, btf_id)) { + /* + * *.multi programs don't need an address during program + * verification, we just take the module ref if needed. + * *.multi programs don't have tgt_prog during program + * verification. + */ if (btf_is_module(btf)) { mod = btf_try_get_module(btf); if (!mod) return -ENOENT; } addr = 0; - } else if (tgt_prog) { - if (subprog == 0) - addr = (long) tgt_prog->bpf_func; - else - addr = (long) tgt_prog->aux->func[subprog]->bpf_func; } else { if (btf_is_module(btf)) { mod = btf_try_get_module(btf); -- 2.55.0