Re: [PATCH bpf] bpftool: Use libbpf error code for flow dissector query
From: Woojin Ji
Date: Tue Jun 02 2026 - 20:19:53 EST
Thanks for taking a look.
Yes, the fd is opened read-only, so I do not mean to claim that close() on
/proc/self/ns/net commonly fails in normal use, or that delayed writeback
errors are expected here.
The fragile part is that the BPF_PROG_QUERY error is consumed only after an
intervening close(), even though bpf_prog_query() has already returned the
negative errno in err. If close() changes errno, the old-kernel -EINVAL
compatibility case can be missed.
I reproduced this with an LD_PRELOAD fault injector that forced
BPF_PROG_QUERY for BPF_FLOW_DISSECTOR to fail with EINVAL, and then forced
close() on the netns fd to fail with EIO. The unpatched bpftool reported:
Error: can't query prog: Input/output error
With this patch, the same injected failure is handled as the intended
non-fatal EINVAL compatibility case.
I'll send a v2 with the commit message updated to make this clearer. The code
change itself is unchanged.