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
3
votes
1 answer

Thread safe operations on XDP

I was able to confirm from the documentation that bpf_map_update_elem is an atomic operation if done on HASH_MAPs. Source (https://man7.org/linux/man-pages/man2/bpf.2.html). [Cite: map_update_elem() replaces existing elements atomically] My question…
Rishab
  • 73
  • 4
3
votes
1 answer

eBPF: 'bpf_map_update()' returns the 'invalid indirect read from stack' error

I have an eBPF program with the following map definitions: struct bpf_map_def SEC("maps") servers = { .type = BPF_MAP_TYPE_HASH, .key_size = sizeof(struct ip_key), .value_size = sizeof(struct dest_info), .max_entries =…
Ferrar
  • 65
  • 7
3
votes
1 answer

No direct packet access in BPF program with just CAP_BPF?

Up until Linux 5.8 CAP_SYSADMIN was required to load any but the most basic BPF program. The recently introduced CAP_BPF is a welcome addition as it allows to run software leveraging BPF with less privileges. Certain types of BPF programs can access…
Nick Zavaritsky
  • 1,429
  • 8
  • 19
3
votes
1 answer

BPF verifier says program exceeds 1M instruction

For the following program I get an error from the verifier saying that it exceeds 1M instructions, even though it shouldn't. The program finds the hostname of a HTTP packet. #include #include struct server_name { …
user2233706
  • 6,148
  • 5
  • 44
  • 86
3
votes
1 answer

BPF verification error when trying to extract SNI from TLS packet

I am trying to get the server name from the SNI extension of a TLS hello packet in a XDP program. When I try to load it, I get the following error from the BPF verifier: math between pkt pointer and register with unbounded min value is not…
user2233706
  • 6,148
  • 5
  • 44
  • 86
3
votes
1 answer

eBPF: raw_tracepoint arguments

I am getting into eBPF programming and want to use raw tracepoints, but I do not really understand, how to use them and how to access the arguments correctly. I would appreciate any help and hints to documantation. My questions: How do I get the…
Dennis
  • 150
  • 1
  • 11
3
votes
2 answers

Linux BTF: bpftool: Failed to get EHDR from /sys/kernel/btf/vmlinux

I am trying to start with BPF CO:RE Development. Using Ubuntu 20.04 LTS in a VM, I needed to recompile the kernel and install pahole (from apt install dwarves) so that BTF is enabled (I set CONFIG_DEBUG_FS=y and CONFIG_DEBUG_INFO_BTF=y). So my setup…
Dennis
  • 150
  • 1
  • 11
3
votes
1 answer

bpf_prog_test_run() causes unexpected packet data

I try to perform a test run for an XDP BPF program. The BPF program uses the bpf_xdp_adjust_meta() helper, to adjust the meta data. I tried: to run bpf_prog_test_run() to run bpf_prog_test_run_xattr() 1. bpf_prog_test_run() (The first time I…
n1kb3rt
  • 111
  • 1
  • 8
3
votes
0 answers

eBPF program in Android

How do I compile eBPF program in Android? Do I need to use adeb and bcc to compile the bpf program? I'm very confused from the Android documentation on eBPF Android documentation. Thank you!
jalee0606
  • 31
  • 1
3
votes
0 answers

Syscall argument in kprobe with wrong value libbpf

I'm trying to use libbpf to trace calls to the kill syscall. Here is my eBPF program: SEC("kprobe/__x64_sys_kill") int BPF_KPROBE(__x64_sys_kill, pid_t pid, int sig) { bpf_printk("Pid = %i\n", pid); return 0; } But for some reason, when I…
Skallwar
  • 73
  • 2
  • 5
3
votes
2 answers

eBPF - Cannot read argv and envp from tracepoint sys_enter_execve

I am learning BPF for my own fun, and I am having a hard time figuring out how to read argv and envp from the context passed to my eBPF program for sys_enter_execve I will show my BPF program here and then explain in more details later what I am…
ocampeau
  • 157
  • 1
  • 8
3
votes
1 answer

Low throughput with XDP_TX in comparison with XDP_DROP/REDIRECT

I have developed a XDP program that filters packets based on some specific rules and then either drops them (XDP_DROP) or redirects them (xdp_redirect_map) to another interface. This program was well able to process a synthetic load of ~11Mpps…
Marcus Wichelmann
  • 762
  • 1
  • 6
  • 18
3
votes
1 answer

Unable to run bpf program as non root

I am trying to run a simple bpf program that I wrote. But I am not able to run it as non root user. Below is the program I am trying to load, It basically gets the pointer to my map whose fd is map_fd (I am not showing the code where I create the…
user40061
  • 85
  • 2
  • 5
3
votes
1 answer

How to share a ebpf map between interfaces

Is it possible to share an ebpf Map between two network interfaces. I want to write an XDP program and hook it on two devices namely eth0 and eth1. The implementation requires that they both use the same map. Is it possible to load the same program,…
WIOUW
  • 113
  • 1
  • 2
  • 7
3
votes
2 answers

bcc: ImportError cannot import name BPF

I am getting the following error when trying run the example hello_world.py. Traceback (most recent call last): File "/usr/share/bcc/examples/hello_world.py", line 9, in from bcc import BPF ImportError: cannot import name BPF I…
Sagar Rakshe
  • 2,682
  • 1
  • 20
  • 25