Questions tagged [bpf]

The Berkeley Packet Filter (BPF, or cBPF) was initially introduced to provide a raw interface to data link layers in a protocol independent fashion, on BSD systems and then on Linux. More recently, it has been reworked on Linux to give birth to the extended BPF, or eBPF. The latter can be used for network processing at several levels, as well as for security applications, or even tracing and monitoring use cases. This tag is for all cBPF/eBPF questions.

The Berkeley Packet Filter was initially introduced to provide a raw interface to data link layers in a protocol independent fashion, first on BSD systems in the early 90s, then on Linux a few years later. All packets on the network, even those destined for other hosts, would be accessible through this mechanism.

Since 2013, the older BPF subsystem (or cBPF, for classic BPF) has led to the creation to an extended BPF version, or eBPF, on Linux. eBPF has a different architecture. It is more efficient, more flexible, introduces new features (maps, tail calls, helper functions from kernel, etc.). And programs can be attached to a variety of hooks in the kernel, for networking (sockets, as before, but also TC (traffic control) interface, XDP…), for security (cgroups) or for tracing and monitoring the kernel (kprobes, tracepoints, …).

449 questions
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
1 answer

Getting "Bad System Call" working with seccomp filters

I have just started learning about seccomp filters and I am using libseccomp v2.4.4. I tried to write a basic whitelisting filter that will only allow writing to the file named file1 but I am getting a "Bad system call" message in STDOUT. Here is my…
4
votes
1 answer

BPF verifier rejects when try to access __sk_buff member

I'm trying to write a sample eBPF program which can access __sk_buff member and dump it into /sys/kernel/debug/tracing/trace. #include #include #include SEC("dump_skb_member") int…
lcl1996
  • 53
  • 4
4
votes
1 answer

What is the real address of `%fs:0xfffffffffffffff8`?

I want to trace the goid of go programs using ebpf. After reading for some posts and blogs, I know that %fs:0xfffffffffffffff8 points to the g struct of go and mov %fs:0xfffffffffffffff8,%rcx instruction always appear at the start of a go…
jl0x61
  • 407
  • 3
  • 12
4
votes
1 answer

libbpf: Error loading ELF section .BTF: 0

I got this error message on ubuntu 19.04 when I try to execute sudo ./mineonlyret which is the user space program which loads an ebpf program and it is described after. I tried the same configuration on ubuntu 18.04 and it worked without errors.…
Maicake
  • 1,046
  • 10
  • 34
4
votes
1 answer

Why are the first 8 bytes of cpumap_enqueue_ctx not accessible by bpf code?

Reading some ebpf examples which are attached to tracepoints I've noticed that every struct is build starting with a padding like this (from samples/bpf/xdp_redirect_cpu_kern.c) /* Tracepoint:…
Maicake
  • 1,046
  • 10
  • 34
4
votes
2 answers

What is not allowed in restricted C for ebpf?

From bpf man page: eBPF programs can be written in a restricted C that is compiled (using the clang compiler) into eBPF bytecode. Various features are omitted from this restricted C, such as loops, global variables, …
Maicake
  • 1,046
  • 10
  • 34
4
votes
1 answer

How to get the return code of the syscall using SECCOMP_RET_DATA and PTRACE_GETEVENTMSG

I'm a little bit confused trying to obtaining syscall's return value using ptrace + seccomp. man 4 bpf says: FILTER MACHINE A filter program is an array of instructions, with all branches forwardly directed, terminated by a return…
Sam Toliman
  • 123
  • 1
  • 5
4
votes
1 answer

while installing bcc, can't find package bpfcc

I am trying to install bcc module on my Linux machine so I can code BPF programs. I've been following up with the page https://github.com/iovisor/bcc/blob/master/INSTALL.md#kernel-configuration to build a kernel and install bcc module. However,…
Rosè
  • 345
  • 2
  • 13
4
votes
1 answer

How to list all bpf program which is loaded into kernel ? (e.g. tc-bpf)

I know that bpf program can be load into kernel in different ways, tc/kprobe/socket ... And I want to know is there a interface or something, through which I can get all the bpf program I loaded? If no such thing, is it dangerous that if I left…
Pilo
  • 53
  • 1
  • 5
4
votes
1 answer

eBPF: understand two macros in verifier code

I'm looking in the ebpf verifier code, and I can't get my head around the following macros: #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) #define offsetofend(TYPE, MEMBER) \ (offsetof(TYPE, MEMBER) + sizeof(((TYPE…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

ebpf - sections names

Is it mandatory to have unique names for every program section in bpf program? For instance, this program compiles fine with llvm-5.0 : ... SEC("sockops") int bpf1(struct bpf_sock_ops *sk_ops) { return 1; } SEC("sockops") int bpf2(struct…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

Simple eBPF action not taking effect with tc

I compiled BPF example from samples/bpf/pare_simple.c (from the Linux kernel tree) with very simple change: SEC("simple") int handle_ingress(struct __sk_buff *skb) { return TC_ACT_SHOT; } So I want ANY packets to be dropped. I install it as…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

Is it possible to use eBPF or perf to calculate time spent in individual traced functions?

Currently, I can tell trace-cmd (an ftrace front-end) to use ftrace's function graph infrastructure to trace a specified workload. Using some trace data processing tools, I can look at the frequency with which functions were called and the…
buratino
  • 1,408
  • 2
  • 17
  • 40
4
votes
0 answers

How to watch CPU time of raw sockets using BPF filtering

Lets say I have a linux machine that has an infinite amount of packets coming in in one interface. I've opened a raw socket and set a bpf filter that none of the packets go through. Now for every packet the kernel receives it runs the bpf bytecode…
Birdy John
  • 41
  • 2
1 2
3
29 30