]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: fix erroneous multi-closing of BTF FD
authorAndrii Nakryiko <andriin@fb.com>
Fri, 26 Jul 2019 21:24:38 +0000 (14:24 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 27 Jul 2019 00:23:16 +0000 (17:23 -0700)
commit9c380a89d0df7b848325f5899b9082bc8adfb1e4
tree5d4799e4c7b1c856189060cf94d60dff4b5d3a5e
parent44d4ae75e4a3e34bedfadd16b10e22f956565293
libbpf: fix erroneous multi-closing of BTF FD

Libbpf stores associated BTF FD per each instance of bpf_program. When
program is unloaded, that FD is closed. This is wrong, because leads to
a race and possibly closing of unrelated files, if application
simultaneously opens new files while bpf_programs are unloaded.

It's also unnecessary, because struct btf "owns" that FD, and
btf__free(), called from bpf_object__close() will close it. Thus the fix
is to never have per-program BTF FD and fetch it from obj->btf, when
necessary.

Fixes: 405046661673 ("tools/bpf: add support to read .BTF.ext sections")
Reported-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c