Skip to content

Commit 50bd645

Browse files
magnus-karlssonborkmann
authored andcommitted
libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE
In commit da11b41 ("libbpf: teach libbpf about log_level bit 2"), the BPF_LOG_BUF_SIZE was increased to 16M. The XDP socket part of libbpf allocated the log_buf on the stack, but for the new 16M buffer size this is not going to work. Change the code so it uses a 16K buffer instead. Fixes: da11b41 ("libbpf: teach libbpf about log_level bit 2") Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 69a0f9e commit 50bd645

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎tools/lib/bpf/xsk.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, __u64 size,
259259

260260
static int xsk_load_xdp_prog(struct xsk_socket *xsk)
261261
{
262-
char bpf_log_buf[BPF_LOG_BUF_SIZE];
262+
static const int log_buf_size = 16 * 1024;
263+
char log_buf[log_buf_size];
263264
int err, prog_fd;
264265

265266
/* This is the C-program:
@@ -308,10 +309,10 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
308309
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
309310

310311
prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, prog, insns_cnt,
311-
"LGPL-2.1 or BSD-2-Clause", 0, bpf_log_buf,
312-
BPF_LOG_BUF_SIZE);
312+
"LGPL-2.1 or BSD-2-Clause", 0, log_buf,
313+
log_buf_size);
313314
if (prog_fd < 0) {
314-
pr_warning("BPF log buffer:\n%s", bpf_log_buf);
315+
pr_warning("BPF log buffer:\n%s", log_buf);
315316
return prog_fd;
316317
}
317318

0 commit comments

Comments
 (0)