Skip to content

Commit 3b39d73

Browse files
kuba-mooAlexei Starovoitov
authored andcommitted
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. Acked-by: Quentin Monnet <qmo@kernel.org> Fixes: 7084566 ("tools/bpftool: Remove libbpf_internal.h usage in bpftool") Signed-off-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20260217194150.734701-1-kuba@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 593fffb commit 3b39d73

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

tools/bpf/bpftool/net.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,
156156
bool multipart = true;
157157
struct nlmsgerr *err;
158158
struct nlmsghdr *nh;
159-
char buf[4096];
159+
char buf[8192];
160160
int len, ret;
161161

162162
while (multipart) {
@@ -201,6 +201,9 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,
201201
return ret;
202202
}
203203
}
204+
205+
if (len)
206+
p_err("Invalid message or trailing data in Netlink response: %d bytes left", len);
204207
}
205208
ret = 0;
206209
done:

tools/lib/bpf/netlink.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
143143
struct nlmsghdr *nh;
144144
int len, ret;
145145

146-
ret = alloc_iov(&iov, 4096);
146+
ret = alloc_iov(&iov, 8192);
147147
if (ret)
148148
goto done;
149149

@@ -212,6 +212,8 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
212212
}
213213
}
214214
}
215+
if (len)
216+
pr_warn("Invalid message or trailing data in Netlink response: %d bytes left\n", len);
215217
}
216218
ret = 0;
217219
done:

0 commit comments

Comments
 (0)