Skip to contentSkip to conversation

tools: bpftool: fix truncated netlink dumps

PATCH Superseded Jakub Kicinski 2 participants 2 messages Dec 5, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

Fixes 7084566a236f ("tools/bpftool: Remove libbpf_internal.h usage in bpftool")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/bpf/bpftool/net.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/bpf/bpftool/net.c +5 -1
index cfc6f944f7c3..7f248fc01332 100644
@@ -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,10 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,
 					return ret;
 			}
 		}
+
+		if (len)
+	                fprintf(stderr, "Invalid message or trailing data in Netlink response: %d\n",
+				len);
 	}
 	ret = 0;
 done:
Signature · 1 line
2.52.0
maintainer
#1 lore raw
Quoted 40 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.

Fixes 7084566a236f ("tools/bpftool: Remove libbpf_internal.h usage in bpftool")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/bpf/bpftool/net.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/bpf/bpftool/net.c +1 -1
index cfc6f944f7c3..7f248fc01332 100644
@@ -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) {

tools/bpf/bpftool/net.c static int netlink_recv(int sock, __u32 nl_pid, __u32 seq, · line 207

Quoted 7 lines
tools/bpf/bpftool/net.c +4 -0
@@ -201,6 +201,10 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,
 					return ret;
 			}
 		}
+
+		if (len)
+	                fprintf(stderr, "Invalid message or trailing data in Netlink response: %d\n",
+				len);

Hi, it's been a while, thanks! :)

Can you please use p_err() rather than fprintf()? I'd also add what the printed value is, for example:

    p_err("Invalid message or trailing data in Netlink response: %d bytes left", len);

Can you please also check function libbpf_netlink_recv() in tools/lib/bpf/netlink.c? That's where the one in bpftool comes from and it seems it has the same issue.

Thanks,
Quentin