]> www.infradead.org Git - users/dwmw2/linux.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Sep 2019 09:35:10 +0000 (10:35 +0100)
commita65fb2895af4a11b2ca0457926ae24c5feeaab6b
treec9a47d4f8c60e84907e7c52c050191e4891c1c5e
parentfa689968da499a6094228d9409e1cf100290de8a
libbpf: fix erroneous multi-closing of BTF FD

[ Upstream commit 5d01ab7bac467edfc530e6ccf953921def935c62 ]

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: 2993e0515bb4 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/libbpf.c