BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpftool: fix double close in map dump and batch file error handling
@ 2026-08-10  1:52 chenyuan_fl
  2026-08-10  1:52 ` [PATCH bpf-next 1/2] bpftool: fix double close in map dump chenyuan_fl
  2026-08-10  1:52 ` [PATCH bpf-next 2/2] bpftool: fix spurious batch file read error chenyuan_fl
  0 siblings, 2 replies; 4+ messages in thread
From: chenyuan_fl @ 2026-08-10  1:52 UTC (permalink / raw)
  To: bpf
  Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Yuan Chen

From: Yuan Chen <chenyuan@kylinos.cn>

bpftool's map dump closes the map fd twice: map_dump() closes it on both
its success and error paths, and do_dump() closes the same fd again.
This leaves errno set to EBADF after a dump.

The batch subcommand then misinterprets that stale errno: do_batch()
checks errno after reading the batch file to detect I/O failures, but
fgets() does not clear errno on success, so a leftover EBADF makes
bpftool report a spurious "reading batch file failed" error and exit
non-zero even though every command succeeded.

Patch 1 makes do_dump() the sole owner of the map fd by removing the
close from map_dump(), eliminating the double close and the EBADF source.
Patch 2 makes do_batch() use ferror() to detect genuine read failures
and tracks the too-long-line case explicitly, so stale errno can no
longer trigger a spurious error from any other source either.

Yuan Chen (2):
  bpftool: fix double close in map dump
  bpftool: fix spurious batch file read error

 tools/bpf/bpftool/main.c | 8 ++++++--
 tools/bpf/bpftool/map.c  | 1 -
 2 files changed, 6 insertions(+), 3 deletions(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-10  1:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10  1:52 [PATCH bpf-next 0/2] bpftool: fix double close in map dump and batch file error handling chenyuan_fl
2026-08-10  1:52 ` [PATCH bpf-next 1/2] bpftool: fix double close in map dump chenyuan_fl
2026-08-10  1:52 ` [PATCH bpf-next 2/2] bpftool: fix spurious batch file read error chenyuan_fl
2026-08-10  1:59   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox