Skip to content

Commit

Permalink
ebpf: add fallback when bpf(2) fails
Browse files Browse the repository at this point in the history
commit 9306457 was too eager to
use the same fallback with a log, and that could fail for other
reasons (e.g. not enough buffer space).  Add a fallback without using
the log, so that on kernels older than 5.11 we have better chance of
success.

Closes: containers#1400

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jan 30, 2024
1 parent 8b611f2 commit 983b400
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/libcrun/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,15 @@ libcrun_ebpf_load (struct bpf_program *program, int dirfd, const char *pin, libc
fd = bpf (BPF_PROG_LOAD, &attr, sizeof (attr));
if (fd < 0)
{
const size_t log_size = 8192;
cleanup_free char *log = xmalloc (log_size);

/* Prior to Linux 5.11, eBPF programs were accounted to the memlock
prlimit. Attempt to bump the limit, if possible. */
bump_memlock ();
fd = bpf (BPF_PROG_LOAD, &attr, sizeof (attr));
}
if (fd < 0)
{
const size_t log_size = 8192;
cleanup_free char *log = xmalloc (log_size);

log[0] = '\0';
attr.log_level = 1;
Expand Down

0 comments on commit 983b400

Please sign in to comment.