A tracing multi program loaded with the BTF of a module gets the IDs of its targets with its link. bpf_check_attach_btf_id_multi() takes the prototype from the ID, but the address of the function of the same name in the module, as bpf_prog_load() does for one target. Refuse the ID of a vmlinux function there in the same case. Fixes: aef4dfa790b2 ("bpf: Add bpf_trampoline_multi_attach/detach functions") Signed-off-by: Anton Protopopov --- kernel/bpf/verifier.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d4598b6cd440..22e25aec5033 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -26968,6 +26968,12 @@ int bpf_check_attach_btf_id_multi(struct bpf_verifier_log *log, struct btf *btf, tname = btf_name_by_offset(btf, t->name_off); if (!tname) return -EINVAL; + /* The same as in bpf_prog_load() */ + if (btf_is_base_func(btf, btf_id) && btf_has_own_func(btf, btf_id)) { + bpf_log(log, "Cannot attach to vmlinux target %u:%s with the BTF of a module.\n", + btf_id, tname); + return -EINVAL; + } t = btf_attach_func_proto(log, btf, btf_id); if (!t || !btf_type_is_func_proto(t)) return -EINVAL; -- 2.43.0