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
1
vote
0 answers

how to get go func argument value and set value by ebpf?

env: go 1.18.1, I have two programs, tracee.go package main import ( "fmt" ) //go:noinline func simpleFunction(val int) { fmt.Println("item value:", val) } func main() { simpleFunction(100) } the other tracer.go package main import…
wuqinqiang
  • 77
  • 4
1
vote
0 answers

Linux TCP-packet-Sniffing with eBPF-KProbe, reading package-content from iov_iter not working

I'm trying to evaluate the content of in and outgoing tcp packages with eBPF kprobes using libbpf. Therefore I attached a Kprobe to tcp_sendmsg and tcp_recvmsg. As of my knowledge, the package payload is in the second parameter struct msghdr *msg…
1
vote
1 answer

BPF: sock_ops equivalent for UDP sockets

BPF_PROG_TYPE_SOCK_OPS is a BPF program type which is called when a set of actions is performed on a TCP socket. Right now, I am using it to mark TCP sockets that are trying to connect with an fwmark. I want to do the same for UDP sockets, but…
1
vote
1 answer

eBPF program execution context

I'm experimenting with writing eBPF using libbpf but the documentation is very sparse and I'm having troubles understanding even some basic things related to eBPF program execution. I'm mostly interested in BPF_PROG_TYPE_PERF_EVENT program type, in…
Eyjafl
  • 1,046
  • 6
  • 14
1
vote
0 answers

How to determine safely if an arm64 machine supports attaching BPF uprobes

EDIT: this bug seems resolved on Microsoft Azure as of 21.07.2023. ARM64 linux machines on Microsoft Azure seem to have a bug where attaching uprobes or gdb breakpoints on most (but not all) binaries will result in SIGILL or SIGSEGV being delivered…
patraulea
  • 652
  • 2
  • 5
  • 26
1
vote
1 answer

Continuously increasing map ids in eBPF

I am running eBPF sockops program. During testing, I need to load and reload the programs several times. Here is the userspace program I use to load and attach the BPF program: static const char *__doc__ = "User space program to load the sockops bpf…
diviquery
  • 569
  • 5
  • 19
1
vote
0 answers

Attaching an eBPF program to a container cgroup

I would like to attach an eBPF program to a cgroup associated with an envoy container (running on host namespace, --net=host) in order to monitor and mark its packets: // bpf.c SEC("cgroup_skb/egress") int mark_egress_packets(struct __sk_buff *skb)…
Nimrodshn
  • 859
  • 3
  • 13
  • 29
1
vote
1 answer

Extract packet data using BPF from struct msghr

I am trying to hook to sock_sendmsg and print the packet data. Here is my code. #include "vmlinux.h" #include #include #include #define IP_169_254_169_254 0xFEA9FEA #define TASK_COMM_LEN…
ayushman999
  • 511
  • 3
  • 6
  • 16
1
vote
1 answer

Access ingress packet data on BPF_CGROUP_INET_INGRESS hook

I want to inspect the packet data for incoming packets on a specific cgroup. I found the BPF_PROG_TYPE_CGROUP_SKB program type for the BPF_CGROUP_INET_INGRESS attach type can be used to operate over the __sk_buff struct. However, it seems that the…
diviquery
  • 569
  • 5
  • 19
1
vote
1 answer

Difference between BPF_PROG_TYPE_SOCK_OPS and BPF_PROG_TYPE_CGROUP_SOCK

The BPF_PROG_TYPE_SOCK_OPS and BPF_PROG_TYPE_CGROUP_SOCK programs seen to be very similar. According to the kernel source, the following are the definitions of the two program types: BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCK, cg_sock, struct…
diviquery
  • 569
  • 5
  • 19
1
vote
1 answer

bpf_skb_load_bytes - array loading when len could be 0 - invalid access to memory, min value is outside of the allowed memory range

I'm rewrting my code for tc program to csgroup_sbb/xxx and I've noticed direct access to skb data is not possible here (skb-data), so bpf_skb_load_bytes[_relative] is the only way(?) to get skb data. It worked until I reached the wall. Verifier at…
Maciek Leks
  • 1,288
  • 11
  • 21
1
vote
0 answers

Concurrent system calls handling by kprobes

I have written an eBPF program which captures HTTP requests and responses using kprobes on system calls like accept4, accept, read, write, close(both entry & exit) and sending these as a captured event to userspace using ringbuf. I have few…
Gourav Kumar
  • 205
  • 1
  • 7
1
vote
1 answer

invalid access to memory, R3 min value is outside of the allowed memory range

I am trying to write a BPF TC program to filter network packets based on its payload. I extract first few bytes of the payload into a buffer and try to do a substring search in that buffer. However my BPF program fails verification with…
1
vote
0 answers

How to remove a eBPF function attached by BCC toolkit?

Using bpftool prog show, I can see a list of eBPF programs. 3: cgroup_skb tag 6deef7357e7b4530 gpl loaded_at 2023-04-20T05:19:04-0400 uid 0 xlated 64B jited 54B memlock 4096B 4: cgroup_skb tag 6deef7357e7b4530 gpl …
akastack
  • 75
  • 7
1
vote
1 answer

Can a tracepoint in eBPF get both parameters and return values?

I'm using Linux Kernel 4.19.90, can I get both parameters and return values within one bpf program is called. Or I could only save the parameters into maps, and extract it from maps during "sys_exit_". I just want to get both the parameters and…
Azerrroth
  • 13
  • 2