Why eBPF?
Traditional approaches to capturing SSL/TLS traffic:| Approach | Pros | Cons |
|---|---|---|
| Proxy (mitmproxy) | Easy setup | Requires certificate trust, config changes |
| SDK instrumentation | Full control | Code changes required, per-language |
| ptrace | No code changes | High overhead, breaks debuggers |
| eBPF | No code changes, low overhead | Linux only, requires kernel 5.8+ |
- Runs in kernel space with minimal overhead
- Requires no application changes
- Works with any language that uses OpenSSL/libssl
- Captures plaintext before encryption
eBPF Program Types
OISP Sensor uses several types of eBPF programs:Uprobes (SSL Capture)
Uprobes attach to userspace functions. We attach to OpenSSL’s SSL_write and SSL_read:- Function entry: pointer to data buffer, length
- Function return: actual bytes written/read
Tracepoints (System Events)
Tracepoints are stable kernel attachment points:| Tracepoint | Captures |
|---|---|
sched/sched_process_exec | Process execution (with parent PID) |
sched/sched_process_exit | Process exit (with exit code) |
syscalls/sys_enter_openat | File open operations |
syscalls/sys_enter_connect | Network connection attempts |
syscalls/sys_exit_connect | Connection results |
Data Structures
SSL Events
Process Events
Ring Buffers
Events are sent from kernel to userspace via eBPF ring buffers:- Support variable-length events
- Have lower overhead
- Don’t lose events on CPU migration
Filtering
OISP Sensor supports kernel-side filtering to reduce overhead:PID Filtering
- Userspace populates
TARGET_PIDSmap - Sets
FLAG_PID_FILTER_ENABLEDinCONFIG_FLAGS - eBPF program checks filter before processing
Process Name Filtering
Socket Correlation
SSL events don’t include destination addresses, so we correlate them with network connections:Building eBPF Programs
The eBPF programs are built with Aya:Capabilities Required
OISP Sensor needs these Linux capabilities:| Capability | Required For |
|---|---|
CAP_BPF | Loading eBPF programs |
CAP_PERFMON | Accessing perf events, ring buffers |
CAP_SYS_ADMIN | Some eBPF operations (fallback) |
CAP_NET_ADMIN | Network-related eBPF |
Performance
Typical overhead measurements:| Metric | Value |
|---|---|
| CPU overhead | < 2% |
| Memory (sensor) | ~50 MB |
| Memory (eBPF maps) | ~5 MB |
| Event latency | < 1ms |
- O(1) map lookups
- Bounded loops (BPF verifier enforced)
- No dynamic memory allocation
Troubleshooting
”eBPF not supported”
Check kernel version:“Failed to attach uprobe”
Verify libssl path:“Permission denied”
Ensure capabilities are set:Further Reading
- Aya Book - Rust eBPF framework
- BPF Performance Tools - Brendan Gregg
- Linux eBPF Documentation