tools: bpftool: fix truncated netlink dumps
PATCH v3 1/1 tools: bpftool: fix truncated netlink dumps
Netlink requires that the recv buffer used during dumps is at least min(PAGE_SIZE, 8k) (see the man page). Otherwise the messages will get truncated. Make sure bpftool follows this requirement, avoid missing information on systems with large pages.
---
v3:
- add missing new line
v2: https://lore.kernel.org/[email protected]
- make the same change in libbpf_netlink_recv()
note that libbpf_netlink_recv() does a PEEK and then realloc if the message is larger, so it's technically already safe but probably better if we are consistent
- fprintf(stderr) -> p_err()
- adjust msg
v1: https://lore.kernel.org/bpf/[email protected]/
--- tools/bpf/bpftool/net.c | 5 ++++- tools/lib/bpf/netlink.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-)
tools/bpf/bpftool/net.c +4 -1
@@ -156,7 +156,7 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,bool multipart = true;struct nlmsgerr *err;struct nlmsghdr *nh; -char buf[4096 ]; +char buf[8192 ];int len, ret;while (multipart) {
@@ -201,6 +201,9 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,return ret; } } + +if (len) +p_err ("Invalid message or trailing data in Netlink response: %d bytes left" , len); } ret =0 ; done:
tools/lib/bpf/netlink.c +3 -1
@@ -143,7 +143,7 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,struct nlmsghdr *nh;int len, ret; - ret =alloc_iov (&iov,4096 ); + ret =alloc_iov (&iov,8192 );if (ret) goto done;
@@ -212,6 +212,8 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq, } } } +if (len) +pr_warn ("Invalid message or trailing data in Netlink response: %d bytes left\n" , len); } ret =0 ; done:
Signature · 1 line
2.53.0
Alexei Starovoitov
AppliedQuoted 9 lines · Jakub Kicinski
Netlink requires that the recv buffer used during dumps is at least
min(PAGE_SIZE, 8k)(see the man page). Otherwise the messages will get truncated. Make sure bpftool follows this requirement, avoid missing information on systems with large pages.Acked-by Quentin Monnet <[email protected]>Fixes 7084566a236f ("tools/bpftool: Remove libbpf_internal.h usage in bpftool")Signed-off-by Jakub Kicinski <[email protected]>
Applied to bpf tree.
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Tue, 17 Feb 2026 11:41:50 -0800 you wrote:
Netlink requires that the recv buffer used during dumps is at least
min(PAGE_SIZE, 8k)(see the man page). Otherwise the messages will get truncated. Make sure bpftool follows this requirement, avoid missing information on systems with large pages.Acked-by Quentin Monnet <[email protected]>Fixes 7084566a236f ("tools/bpftool: Remove libbpf_internal.h usage in bpftool")Signed-off-by Jakub Kicinski <[email protected]>[...]
Here is the summary with links:
- [bpf,v3] tools: bpftool: fix truncated netlink dumps
https://git.kernel.org/bpf/bpf/c/3b39d73cc337
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html