Lesson 2 of 9 · 24m
Program Types, Hooks, and Context: Choose the Right Window
Compare kprobes, tracepoints, uprobes, XDP, tc, and LSM hooks by stability, context, overhead, and operational risk.
Most bad eBPF instrumentation begins with the wrong hook. A team wants "file access," attaches to a convenient syscall, and later discovers half the real accesses came through a different path. Hook selection is not plumbing; it is the evidence model. If you choose the wrong window, no amount of clever filtering downstream will reconstruct what happened.
Tracepoints are the boring default — use boring
Tracepoints are static kernel events with stable fields. They survive compiler optimization better than arbitrary kernel function probes and are usually the first choice for observability:
sudo bpftrace -l 'tracepoint:syscalls:sys_enter_*' | head
sudo cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_openat/formatThe format file is documentation you can read on the host. If a tracepoint exists for your event, prefer it over a kprobe.
Kprobes are powerful and brittle
A kprobe attaches to almost any kernel function. That gives enormous reach, but kernel functions are not a stable API. Names, arguments, and inline behavior change across kernel versions:
sudo bpftrace -e 'kprobe:vfs_open { printf("%s pid=%d\n", comm, pid); }'Useful? Yes. Portable across every production kernel? Not necessarily. Treat kprobe programs as kernel-version-specific engineering unless CO-RE and field analysis prove otherwise.
Uprobes observe userland
Uprobes attach to instructions in user-space binaries and libraries. They are excellent for language runtimes, TLS libraries, and application-specific boundaries:
sudo bpftrace -e 'uprobe:/usr/lib/x86_64-linux-gnu/libssl.so.3:SSL_write {
printf("SSL_write pid=%d len=%d\n", pid, arg2);
}'The trap is symbol availability. Stripped binaries, static linking, and hand-written assembly can turn a nice demo into a forensic archaeology exercise.
Network hooks are about placement
XDP runs before normal packet processing and is ideal for early dropping, measurement, or redirection. It has limited context because it runs so early. Traffic control (tc) runs later and can see socket-layer metadata in many cases. Neither automatically understands application semantics.
NIC/driver -> XDP -> qdisc/tc -> netfilter -> socket -> processIf you need L7 identity, raw packet hooks alone will not give it to you. If you need microsecond-level drop decisions, userspace policy arrives too late. Placement is the feature.
Security hooks differ from tracing hooks
BPF LSM programs can enforce or audit security decisions at LSM hooks, while tracepoints and kprobes are primarily observation-oriented. Observability tells you what happened; enforcement changes what may happen. That difference controls blast radius, testing requirements, and how paranoid your rollout plan should be.
Field notes
bpftrace -land/sys/kernel/debug/tracing/eventstell you what this kernel exposes; do not trust documentation from a different kernel blindly.- Kprobe argument positions are ABI details, not friendly typed fields. Validate against kernel source or BTF.
- Mount debugfs/tracefs before debugging tracepoint metadata; some minimal systems do not mount it by default.
- Choosing the lowest-level hook does not make data more truthful. It often makes it less interpretable.
Was this lesson helpful?