linux/tools/bpf/bpftool
Yuan Chen 259d60f5bf bpftool: Fix double close in map dump
map_dump() closes the map fd in its error path, and do_dump() then
closes the same fd again after a successful dump. Closing an already
closed fd leaves errno set to EBADF, which poisons later errno checks
such as the batch file read check in do_batch(). Let do_dump() own the
fd and remove the close from map_dump().

The same double-close pattern exists in do_show_subset(): both
show_map_close_json() and show_map_close_plain() already close the fd,
so drop the extra close() there as well.

Also propagate the error when bpf_map_get_info_by_fd() fails on a
subsequent map in do_dump(): set err = -1 before breaking out of the
loop, so a later failure is not silently hidden after an earlier
iteration succeeded.

Fixes: 99f9863a0c ("bpftool: Match maps by name")
Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20260810142224.2907373-2-chenyuan_fl@163.com
2026-08-13 14:54:06 -07:00
..
bash-completion bpftool: add missing fsession to the usage and docs of bpftool 2026-04-12 12:42:38 -07:00
Documentation bpftool: Add rhash map documentation 2026-06-05 08:00:08 -07:00
skeleton bpftool: Fix typo in MAX_NUM_METRICS macro name 2024-06-03 16:58:27 +02:00
.gitignore bpftool: Fix SPDX tag for Makefiles and .gitignore 2021-11-10 09:00:52 -08:00
btf_dumper.c bpftool: Use btf_vlen()/btf_kind()/btf_kflag() helpers consistently 2026-07-02 09:25:45 -07:00
btf.c bpftool: Use btf_vlen()/btf_kind()/btf_kflag() helpers consistently 2026-07-02 09:25:45 -07:00
cfg.c bpftool: Fix control flow graph segfault during edge creation 2025-01-10 14:16:13 -08:00
cfg.h bpftool: Support printing opcodes and source file references in CFG 2023-04-05 21:27:27 -07:00
cgroup.c bpftool: Fix vmlinux BTF leak in cgroup commands 2026-06-21 18:02:10 -07:00
common.c bpftool: Skip prog/map that disappears while looking it up by name 2026-07-20 17:02:31 +02:00
feature.c bpftool: Refactor kernel config reading into common helper 2025-09-02 17:20:54 +02:00
gen.c bpftool: Generate skeleton for global percpu data 2026-08-13 10:27:40 -07:00
iter.c bpftool: Use appropriate permissions for map access 2025-06-20 11:13:03 -07:00
jit_disasm.c bpftool: Enable aarch64 ISA extensions for JIT disassembly 2026-03-24 08:44:29 -07:00
json_writer.c tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
json_writer.h tools: bpftool: json: Fix backslash escape typo in jsonw_puts 2023-03-29 09:48:45 -07:00
link.c bpftool: Add tracing_multi link info output 2026-07-01 12:44:12 -07:00
main.c bpftool: Allow explicitly skip llvm, libbfd and libcrypto dependencies 2026-03-16 14:14:14 -07:00
main.h bpftool: Allow explicitly skip llvm, libbfd and libcrypto dependencies 2026-03-16 14:14:14 -07:00
Makefile bpftool: Strip all -Wformat* flags from bootstrap libbpf build 2026-07-01 11:14:34 -07:00
map_perf_ring.c bpftool: Use appropriate permissions for map access 2025-06-20 11:13:03 -07:00
map.c bpftool: Fix double close in map dump 2026-08-13 14:54:06 -07:00
net.c bpftool: Use libbpf error code for flow dissector query 2026-06-03 15:30:23 -07:00
netlink_dumper.c bpftool: Using the right format specifiers 2025-03-17 13:50:56 -07:00
netlink_dumper.h bpftool: Extend net dump with tcx progs 2023-07-19 10:07:28 -07:00
perf.c bpftool: fix perf help message 2023-08-11 20:54:29 -07:00
pids.c bpftool: ensure task comm is always NUL-terminated 2024-11-05 17:12:29 -08:00
prog.c bpftool: add missing fsession to the usage and docs of bpftool 2026-04-12 12:42:38 -07:00
sign.c bpftool: Cover loader metadata with the program signature 2026-07-08 20:04:58 +02:00
struct_ops.c tools/bpf/bpftool: Reset vmlinux BTF after struct_ops commands 2026-07-01 11:17:43 -07:00
token.c bpftool: Fix UAF in get_delegate_value 2025-09-19 15:37:30 -07:00
tracelog.c bpftool: Search for tracefs at /sys/kernel/tracing first 2025-09-15 10:10:28 -07:00
xlated_dumper.c bpf: Do not print a newline after disassembly in bpf_verbose_insn() 2026-08-08 11:05:49 +02:00
xlated_dumper.h bpftool: Dump the kernel symbol's module name 2023-07-11 20:07:50 -07:00