mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-11 11:09:06 +08:00
libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE
In commit da11b417583e ("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: da11b417583e ("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>
This commit is contained in:
committed by
yonghong-song
parent
1770ac49cf
commit
a74350fc04
@@ -259,7 +259,8 @@ out_umem_alloc:
|
|||||||
|
|
||||||
static int xsk_load_xdp_prog(struct xsk_socket *xsk)
|
static int xsk_load_xdp_prog(struct xsk_socket *xsk)
|
||||||
{
|
{
|
||||||
char bpf_log_buf[BPF_LOG_BUF_SIZE];
|
static const int log_buf_size = 16 * 1024;
|
||||||
|
char log_buf[log_buf_size];
|
||||||
int err, prog_fd;
|
int err, prog_fd;
|
||||||
|
|
||||||
/* This is the C-program:
|
/* This is the C-program:
|
||||||
@@ -308,10 +309,10 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
|
|||||||
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
|
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
|
||||||
|
|
||||||
prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, prog, insns_cnt,
|
prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, prog, insns_cnt,
|
||||||
"LGPL-2.1 or BSD-2-Clause", 0, bpf_log_buf,
|
"LGPL-2.1 or BSD-2-Clause", 0, log_buf,
|
||||||
BPF_LOG_BUF_SIZE);
|
log_buf_size);
|
||||||
if (prog_fd < 0) {
|
if (prog_fd < 0) {
|
||||||
pr_warning("BPF log buffer:\n%s", bpf_log_buf);
|
pr_warning("BPF log buffer:\n%s", log_buf);
|
||||||
return prog_fd;
|
return prog_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user