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

eBPF - difference between loading, attaching, and linking?

I'm very confused on eBPF terminology that is used in the bpf syscall and libbpf functions. Could someone break down where my understanding of loading/attaching a process using bpf is wrong? My understanding: I've been looking at code for cgroups…
wxz
  • 2,254
  • 1
  • 10
  • 31
5
votes
1 answer

What is variable attribute SEC means?

Currently, I'm tracing a bpf program and found something I can't understand. There're several declaration like: struct bpf_map_def SEC("maps") map_parsing_context = { ... }; struct { ... } map_keys SEC(".maps"); My question are: What did this…
Steven
  • 811
  • 4
  • 23
5
votes
0 answers

maximum number of uprobe using bcc/bpf

I use bcc to trace userspace program with uprobe. However, I cannot attach more than 500 uprobe. I am wondering is there a limit of how many uprobe can be attached at the same time? Or is there a kernel config that I can change?
戴均維
  • 101
  • 5
5
votes
1 answer

Getting BPF programs working with USDT probes (Dtrace) in Linux

So I'm following this link to attach a BPF program to user space probes, Dtrace format (see section User Statically Defined Tracepoints). C program: #include int main() { DTRACE_PROBE("hello-usdt", "probe-main"); } The checks to…
mdaniel
  • 191
  • 1
  • 12
5
votes
1 answer

BPF verifier rejects code: "invalid bpf_context access"

I'm trying to write a simple socket filter eBPF program that can access the socket buffer data. #include #include #define SEC(NAME) __attribute__((section(NAME), used)) SEC("socket_filter") int myprog(struct…
Tom Hadlaw
  • 123
  • 6
5
votes
1 answer

bpf_trace_printk format pointer

How is "%p" implemented in bpf_trace_printk? It seems very different with printf. #include int print_args(struct pt_regs *ctx) { void *ptr = (void*)PT_REGS_PARM1(ctx); bpf_trace_printk("args: %lx %p %ld\n", ptr, ptr,…
libo
  • 102
  • 5
5
votes
1 answer

bounded loops in ebpf. Does now the verifier check if the program is a DAG?

Since bounded loop are now allowed in ebpf programs https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git/commit/?id=2589726d12a1b12eaaa93c7f1ea64287e383c7a5 does the verifier still check in the first pass if the program control flow is…
Maicake
  • 1,046
  • 10
  • 34
4
votes
0 answers

Concurrent modification of Linux BPF hashtab map, how to make it safe without resorting to BPF_F_NO_PREALLOC flag

A BPF map preallocates memory for items by default. BPF_F_NO_PREALLOC flag turns preallocation off. A preallocated map is faster. Sleepable programs could only work with preallocated maps until recently. When it comes to concurrency, there's a…
Nick Zavaritsky
  • 1,429
  • 8
  • 19
4
votes
1 answer

"invalid bpf_context access" when trying to read `regs` parameter

Depending on how the syscall is defined in /sys/kernel/btf/vmlinux, reading struct pt_regs *regs parameter for fentry/fexit traces causes invalid bpf_context access error: SEC("fentry/__x64_sys_recvfrom") int BPF_PROG(fentry_syscall, struct pt_regs…
Akihiro HARAI
  • 574
  • 1
  • 8
  • 17
4
votes
1 answer

"Program too large" threshold greater than actual instruction count

I've written a couple production BPF agents, but my approach is very iterative until I please the verifier and can move on. I've reached my limit again. Here's a program that works if I have one fewer && condition -- and breaks otherwise. The…
coxley
  • 339
  • 2
  • 12
4
votes
0 answers

Is it possible to do it using eBPF? I.e., Can I capture the event before the file is deleted. And take back up

I am trying to track deletion of files using ebpf and wanted to take back up even before the deletion of file happens and then delete the file . To track deletion of files I was told to use three methods by other community members To trace…
4
votes
0 answers

How to share BPF maps between two kernel space BPF programs?

Before I present my matter; I have read this Map sharing between different ebpf program types previously asked question which does not seem to answer my question. Now, what I am doing is, I have two BPF programs, one for XDP and other for TC (No…
Zarrar
  • 63
  • 3
4
votes
1 answer

bpf_xdp_adjust_meta() returns errcode -13 (permission denied)

Problem: bpf_xdp_adjust_meta(ctx, -delta); is returning error code -13 (permission denied) when delta > 32. But BPF and XDP Reference Guide states that there are 256 bytes headroom for metadata. So did I misunderstand something or how can I use 256…
n1kb3rt
  • 111
  • 1
  • 8
4
votes
0 answers

full path for open / openat relative filenames

Using the opensnoop.py from iovisor/bcc, I'm trying to extend the ebpf code to handle extraction of full paths from a relative one. For example, running opensnoop.py and in another terminal running cat anything.txt, the output in opensnoop will show…
Chris White
  • 29,949
  • 4
  • 71
  • 93
4
votes
1 answer

Reading sk_buff with ebpf inside dev_queue_xmit yields questionable data

I'm trying to capture outgoing ethernet frames on the local host before they are sent by inserting a kprobe into __dev_queue_xmit(). However, the bytes I extract from the sk_buff structure do not match the subsequently captured packets. I only…
Jolly
  • 199
  • 6
1
2
3
42 43