libbpf: Fix crash if SEC("freplace") programs don't have attach_prog_fd set
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 9 Sep 2022 19:30:52 +0000 (12:30 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 16 Sep 2022 20:39:37 +0000 (22:39 +0200)
commit749c202cb6ea40f4d7ac95c4a1217a7b506f43a8
tree7b6539a5913cb136e857889f7ddd07b1f719affa
parentcf060c2c399fa457569123bb9806b455ff53e64c
libbpf: Fix crash if SEC("freplace") programs don't have attach_prog_fd set

Fix SIGSEGV caused by libbpf trying to find attach type in vmlinux BTF
for freplace programs. It's wrong to search in vmlinux BTF and libbpf
doesn't even mark vmlinux BTF as required for freplace programs. So
trying to search anything in obj->vmlinux_btf might cause NULL
dereference if nothing else in BPF object requires vmlinux BTF.

Instead, error out if freplace (EXT) program doesn't specify
attach_prog_fd during at the load time.

Fixes: 91abb4a6d79d ("libbpf: Support attachment of BPF tracing programs to kernel modules")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220909193053.577111-3-andrii@kernel.org
tools/lib/bpf/libbpf.c