linux/tools
Jiri Olsa 380044c40b libbpf: Prevent double close and leak of btf objects
Sashiko found possible double close of btf object fd [1],
which happens when strdup in load_module_btfs fails at which
point the obj->btf_module_cnt is already incremented.

The error path close btf fd and so does later cleanup code in
bpf_object_post_load_cleanup function.

Also libbpf_ensure_mem failure leaves btf object not assigned
and it's leaked.

Replacing the err_out label with break to make the error path
less confusing as suggested by Alan.

Incrementing obj->btf_module_cnt only if there's no failure
and releasing btf object in error path.

Fixes: 91abb4a6d7 ("libbpf: Support attachment of BPF tracing programs to kernel modules")
[1] https://sashiko.dev/#/patchset/20260324081846.2334094-1-jolsa%40kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260416100034.1610852-1-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-04-16 16:00:10 -07:00
..
accounting delayacct: fix build regression on accounting tool 2026-02-12 15:45:56 -08:00
arch - Complete LASS enabling: deal with vsyscall and EFI 2026-04-14 14:24:45 -07:00
bootconfig tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure 2026-03-19 08:43:06 +09:00
bpf bpftool: add missing fsession to the usage and docs of bpftool 2026-04-12 12:42:38 -07:00
build tools build: Fix rust cross compilation 2026-03-04 11:37:30 -03:00
certs
cgroup
counter
crypto
debugging
dma
docs docs: kdoc_diff: add a helper tool to help checking kdoc regressions 2026-03-30 10:54:13 -06:00
firewire
firmware
gpio
hv
iio
include vfs-7.1-rc1.mount.v2 2026-04-14 19:59:25 -07:00
kvm/kvm_stat
laptop
leds
lib libbpf: Prevent double close and leak of btf objects 2026-04-16 16:00:10 -07:00
memory-model
mm
net tools: ynl: add sample for wireguard 2026-04-14 11:48:04 -07:00
objtool objtool updates for v7.1: 2026-04-14 13:00:04 -07:00
pcmcia
perf RISC-V updates for v7.0-rc8 2026-04-10 17:27:08 -07:00
power Power management updates for 7.1-rc1 2026-04-13 19:47:52 -07:00
rcu
sched
sched_ext tools/sched_ext: Add -fms-extensions to bpf build flags 2026-03-02 22:00:23 -10:00
scripts Kbuild/Kconfig updates for 7.1 2026-04-14 09:18:40 -07:00
sound
spi spi: tools: Add include folder to .gitignore 2026-02-09 12:27:31 +00:00
testing selftests/bpf: cover UTF-8 trace_printk output 2026-04-16 15:53:32 -07:00
thermal
time
tracing rtla: Fix build without libbpf header 2026-03-30 12:44:48 -04:00
unittests docs: kdoc: better handle source when producing YAML output 2026-03-25 13:36:46 -06:00
usb
verification
virtio
wmi
workqueue
writeback
Makefile