Questions tagged [ebpf]

eBPF (from “extended Berkeley Packet Filter”) is a subsystem introduced in Linux and allowing to load user programs into the kernel, to verify them for safety, possibly to JIT (Just-In-Time) compile them, and to attach them to hook points, where they run on certain events. eBPF's performance and flexibility make it suitable for a wide range of use cases, the most prominent being network packet processing, system monitoring, and security enforcement.

eBPF (from “extended Berkeley Packet Filter”) is a subsystem allowing to load user programs into the kernel, to verify them for safety, possibly to JIT (Just-In-Time) compile them, and to attach them to hook points, where they run on certain events. eBPF's performance and flexibility make it suitable for a wide range of use cases, the most prominent being network packet processing, system monitoring, and security enforcement. Introduced in Linux, eBPF gained support to varying degrees on other systems, including Windows or FreeBSD.

See also https://ebpf.io/ for a more detailed introduction and for additional resources. More assistance can also be found at the following locations:

When submitting questions related to a specific eBPF piece of code, please consider including a full stand-alone reproducer, it helps a lot for debugging the issues.

Related tags include bpf, bcc-bpf, or xdp-bpf.

641 questions
2
votes
1 answer

Is it possible to use eBPF to block a malicious process in kernel space?

One way to block a malicious process is tracing its behavior in kernel space eBPF program and then just simply kill it in user space program, but there is latency before user space program receiving data from kernel space. I wonder if there is a way…
hdthky
  • 57
  • 1
  • 4
2
votes
0 answers

Unable to unload/unpin/detach BPF maps and programs in SKB mode

When a XDP program is loaded in SKB mode, I am unable to remove any maps and some programs from code. I can't remove these same BPF entities using bpftool either. Here's my code for cleaning up the entities: type BpfObjects struct { …
user2233706
  • 6,148
  • 5
  • 44
  • 86
2
votes
1 answer

Unable to unload BPF program

I am unable to unload a BPF program from code. I am using the Cilium eBPF library to load the program and netlink to add the BPF function to an interface. Here's what I'm doing: type BpfObjects struct { CollectIpsProg *ebpf.Program …
user2233706
  • 6,148
  • 5
  • 44
  • 86
2
votes
1 answer

BPF tail call not called

In the following code BPF program tail_prog is not getting tail called from main_prog: #include #include struct bpf_map_def SEC("maps") jump_table = { .type = BPF_MAP_TYPE_PROG_ARRAY, .key_size =…
user2233706
  • 6,148
  • 5
  • 44
  • 86
2
votes
1 answer

errno = 2 right after call to bpf_object__open_file and libbpf_get_error not saying anything

I wrote a simple ebpf so I opened it with obj = bpf_object__open_file(filename, NULL); then when I do prog = bpf_object__find_program_by_name(obj, "kprobe/__x64_sys_write"); This function returns NULL and prints message that printf("finding a prog…
user786
  • 3,902
  • 4
  • 40
  • 72
2
votes
0 answers

Different byte order in BPF program

I have two different types of BPF programs where I am printing the ip address with bpf_printk("%pI4", &ipv4.s_addr);. The xdp program is loaded in the loopback dev and the other is a bpf socket filter; i have a server and a client program that sends…
rhoward
  • 131
  • 2
  • 3
  • 10
2
votes
1 answer

Docker desktop macOS running Ubuntu 20 and hitting operation not permitted with bpf

Setup details: macoS 12.1, docker desktop: 4.3.2 Linux nsipsecinst-0 5.10.76-linuxkit #1 SMP Mon Nov 8 10:21:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Form within container lsb_release -a No LSB modules are available. Distributor ID:…
vtewari
  • 23
  • 4
2
votes
1 answer

Accessing BPF maps from kernel space

I am beginning with XDP and BPF maps. I understand that to access a BPF map from userspace, we use bpf_* syscalls. For example, bpf_map_lookup_elem() is used to lookup an element of a BPF map in the userspace program. However, I noticed that the…
diviquery
  • 569
  • 5
  • 19
2
votes
1 answer

cannot open shared object file: No such file or directory | including libbpf with userspace program

So in my userspace program I am calling some functions like bpf_object__open_file which are part of libbpf library installed with PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install So when I compile the it compiles just…
user786
  • 3,902
  • 4
  • 40
  • 72
2
votes
1 answer

How to let user space to populate an ebpf global data at load time?

I want to pass a variable value specified by the user from the command line from the user space program to the ebpf program. I know how to do it using bpf maps, but i heard there is a more efficient way to do this using bpf global data. Can anyone…
drdot
  • 3,215
  • 9
  • 46
  • 81
2
votes
1 answer

cannot read arguements properly from ebpf kprobe

I wrote a simple ebpf program (using libbpf) in which I hooked sendto syscall libbpf version: SEC("kprobe/sendto") int BPF_KPROBE(entry_sendto, int sockfd, char* buf, size_t len) { bpf_printk("libbpf - entry_sendto - 0 %p", ctx); …
Guy Arbitman
  • 21
  • 1
  • 1
2
votes
1 answer

Why should userspace applications lock Ebpf maps?

When you create EBPF maps, memory is allocated in kernel space. And kernel memory never gets swapped out. Then, why is there a need for the userspace application to call setrlimit() with RLIMIT_MEMLOCK?
joz
  • 319
  • 1
  • 9
2
votes
1 answer

BPF verifier rejetcs the use of an inode ptr as a key

I'm attempting to implement an eBPF code where I have a BPF MAP with the key of type struct inode * and some value. Please see the below sample code struct value { char data[10]; }; struct bpf_map_def info SEC("maps") ={ …
2
votes
1 answer

write and read netfilter connectrack using eBPF/XDP

i'm working on a NAT server in pure XDP. but to have a robust nat functionality i wanted to track the connection (storing and fetching tracking data) and i was thinking about using the already exist netfilter conntrack data structure and functions…
walid barakat
  • 455
  • 1
  • 6
  • 17
2
votes
1 answer

Problem with sending data from userspace to bpf program with maps

I have problem with my bpf program. I getting error while loading this program. my bpf program is: #include #include #include #include #include #include…
Redwan
  • 97
  • 6