Skip to content

Commit 3415ec6

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: set BTF FD for prog only when there is supported .BTF.ext data
5d01ab7 ("libbpf: fix erroneous multi-closing of BTF FD") introduced backwards-compatibility issue, manifesting itself as -E2BIG error returned on program load due to unknown non-zero btf_fd attribute value for BPF_PROG_LOAD sys_bpf() sub-command. This patch fixes bug by ensuring that we only ever associate BTF FD with program if there is a BTF.ext data that was successfully loaded into kernel, which automatically means kernel supports func_info/line_info and associated BTF FD for progs (checked and ensured also by BTF sanitization code). Fixes: 5d01ab7 ("libbpf: fix erroneous multi-closing of BTF FD") Reported-by: Andrey Ignatov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 56fbc24 commit 3415ec6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,11 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
24722472
load_attr.license = license;
24732473
load_attr.kern_version = kern_version;
24742474
load_attr.prog_ifindex = prog->prog_ifindex;
2475-
btf_fd = bpf_object__btf_fd(prog->obj);
2475+
/* if .BTF.ext was loaded, kernel supports associated BTF for prog */
2476+
if (prog->obj->btf_ext)
2477+
btf_fd = bpf_object__btf_fd(prog->obj);
2478+
else
2479+
btf_fd = -1;
24762480
load_attr.prog_btf_fd = btf_fd >= 0 ? btf_fd : 0;
24772481
load_attr.func_info = prog->func_info;
24782482
load_attr.func_info_rec_size = prog->func_info_rec_size;

0 commit comments

Comments
 (0)