πŸ”¬ eBPF β€” Revolusi Observability & Security dari Dalam Kernel

Satu kalimat: eBPF memungkinkan kamu menjalankan program sandboxed di dalam kernel Linux tanpa mengubah kode kernel dan tanpa kernel module β€” performa setara kernel module, keamanan setara user space.

Prasyarat

Pastikan sudah paham OS Internals (CPU Ring, kernel module, syscall) dan Hierarki OS (Level 0–8). eBPF beroperasi di Ring 0, bahkan bisa menyentuh Ring -1 (hypervisor) lewat ekstensi modern.


Daftar Isi


Analogi Sebelum Teknis

Kernel = ruang server super ketat.
Akses masuk biasanya hanya untuk:

Karyawan tetap (Kernel Module)
β†’ Akses penuh
β†’ Kalau error = server crash (kernel panic / BSOD)
β†’ Susah diaudit, perlu recompile tiap versi kernel

eBPF = drone kecil yang bisa terbang di dalam ruangan
β†’ Bisa observe dan bahkan beri perintah
β†’ Sudah di-sandbox oleh Verifier
β†’ Kalau error = drone mati sendiri, ruangan aman
β†’ Tidak perlu izin "karyawan tetap"

Arsitektur eBPF β€” Cara Kerjanya

[Kode eBPF ditulis dalam C]
        β”‚
        β–Ό
[LLVM/Clang compile β†’ Bytecode eBPF]
        β”‚
        β–Ό
[VERIFIER KERNEL] ←── Gatekeeper utama
        β”‚
   β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
   β”‚         β”‚
  AMAN     TIDAK AMAN
   β”‚         β”‚
   β–Ό         β–Ό
[JIT Compiler]  [Ditolak, tidak pernah jalan]
   β”‚
   β–Ό
[Kode Native β€” performa mendekati kernel asli]
   β”‚
   β–Ό
[HOOKS β€” titik di mana eBPF dipasang]
   β”œβ”€β”€ kprobe    : hook fungsi kernel apapun
   β”œβ”€β”€ uprobe    : hook fungsi user space (misal: OpenSSL)
   β”œβ”€β”€ tracepoint: event yang sudah didefinisikan kernel
   β”œβ”€β”€ XDP       : di level NIC driver, sebelum stack network
   β”œβ”€β”€ TC        : traffic control, setelah XDP
   └── socket    : filter socket per-proses
   β”‚
   β–Ό
[MAPS β€” shared memory antara kernel dan user space]
        β”‚
        β–Ό
[User Space Tools: bpftool, libbpf, Cilium, Falco, Pixie...]

4 Komponen Kunci

KomponenFungsiKenapa Penting
VerifierPastikan program tidak infinite loop, tidak akses memori sembarangan, selalu terminateIni yang membuat eBPF aman β€” program yang tidak lolos verifier tidak akan pernah jalan di kernel
JIT CompilerUbah bytecode eBPF ke instruksi mesin nativePerforma mendekati kode kernel asli, jauh lebih cepat dari interpreter
HooksTitik di kernel tempat eBPF dipasang β€” syscall, fungsi jaringan, scheduler, dllFleksibilitas penuh: bisa observe hampir semua yang terjadi di kernel
MapsStruktur data bersama kernel ↔ user space (hash map, array, ring buffer, dsb)Cara eBPF program β€œbicara” ke luar β€” kirim data ke user space tanpa overhead besar

Mengapa eBPF Lebih Optimal

Perbandingan dengan Pendekatan Tradisional

PendekatanKelebihanKelemahanPerformaKeamanan
Kernel ModuleAkses penuh, sangat fleksibelCrash kernel jika ada bug, perlu recompile per versi kernel, susah diaudit⚑ Sangat tinggiπŸ’€ Sangat rendah (satu bug β†’ kernel panic)
Sidecar Proxy (Istio, Envoy)Mudah deploy, language agnosticResource overhead besar (CPU+RAM), latency tambahan, kompleksitas operasional🟑 Sedang (overhead 5–15%)🟑 Sedang
Traditional Monitoring Agent (node exporter, telegraf)Sederhana, banyak supportBanyak proses, sampling loss β€” tidak capture per-event🟠 Rendah-Sedang🟑 Sedang
eBPFAman, overhead sangat rendah, per-event, satu agenKurva belajar curam, butuh kernel modern (4.9+ basic, 5.7+ full feature)⚑ Sangat tinggi (JIT native)βœ… Sangat tinggi (sandbox + verifier)

Data Kuantitatif

Overhead CPU:
  eBPF network observability  : < 1% pada throughput 10Gbps
  Sidecar Envoy               : 10–20% overhead

Packet Processing (XDP):
  eBPF XDP                   : 10+ Mpps per core
  DPDK (user space)           : 50+ Mpps tapi butuh dedicated core
  iptables                    : ~1-2 Mpps, lewat seluruh stack kernel

Memory footprint:
  eBPF program                : maks 1MB per program
  Sidecar (Envoy/Istio)       : 100–500MB per instance

Event capture:
  eBPF                        : setiap syscall, 1M+ events/detik tanpa sampling
  auditd tradisional           : sampling + overhead CPU signifikan

eBPF vs Kernel Module β€” Langsung

AspekKernel ModuleeBPF
Crash riskTinggi β€” satu bug β†’ seluruh kernel panicNol β€” program ditolak verifier jika tidak aman
Upgrade kernelWajib recompile module tiap versiCO-RE (Compile Once, Run Everywhere) β€” satu binary jalan di berbagai versi kernel
AuditabilityManual review source codeVerifier otomatis + bisa dibatasi via cap_bpf capability
Deploymentinsmod/rmmod + kernel signingbpftool prog load atau auto-load via systemd
Use case observabilityBisa, tapi overkill berbahayaDirancang untuk ini β€” ini use case utama eBPF

Kesimpulan Tegas

Tidak ada alasan menulis kernel module baru untuk observability atau security monitoring di era eBPF. eBPF mencapai performa yang sama dengan keamanan dan kemudahan deployment yang jauh lebih tinggi.


eBPF di Hierarki OS Level 0–8

Level OSStatus eBPFUse Case Relevan
Level 0–2 (Consumer β€” Privacy OS)βœ… Tersedia di kernel Linux 4.9+, tapi tidak dipakai aplikasi biasaBelajar eBPF di Linux Mint / Ubuntu. bpftrace untuk debug one-liner, opensnoop untuk lihat file yang dibuka proses
Level 3–4 (Security Research β€” Hardened OS)βœ… Medan perang eBPFFalco untuk runtime security, Pixie untuk observability microservice, Hubble untuk network visibility. Qubes OS: eBPF di dom0 untuk monitor semua VM
Level 5–6 (Enterprise β€” Certified OS)βœ… RHEL / AlmaLinux / Rocky dengan kernel 5.7+DISA STIG RHEL sudah cover konfigurasi eBPF aman. FIPS 140-2: eBPF bisa panggil modul crypto FIPS-certified via helper
Level 6 β€” Militerβœ… Justru sangat ideal”No code change” adalah persyaratan keamanan di sistem classified. eBPF memberi visibility tanpa modifikasi kernel
Level 7–8 (Compartmented β€” Air-Gapped)⚠️ SebagianGreen Hills INTEGRITY & VxWorks belum support (RTOS proprietary). Tapi eBPF for Windows dan eBPF for macOS sudah ada

Plot Twist Militer

NSA punya proyek internal β€œBPF for Trusted Computing” β€” menggabungkan eBPF dengan TPM (Trusted Platform Module). Hasilnya: attestasi jarak jauh bahwa kernel berjalan dengan program eBPF tertentu β€” bisa verifikasi β€œtidak ada rootkit” dari remote server tanpa fisik mengakses mesin.


Studi Kasus Nyata

A β€” Observability Tanpa Instrumentasi (Pixie)

Masalah:
Ingin lihat request HTTP antara microservices
tanpa menambah kode atau sidecar ke aplikasi

Cara lama (Traditional):
β†’ Tambah OpenTelemetry SDK ke setiap service
β†’ Tambah exporter
β†’ Rebuild dan redeploy semua image
β†’ Butuh koordinasi dengan semua tim

Cara eBPF (Pixie):
β†’ Deploy satu agen per node
β†’ Pixie hook uprobe pada ssl_read/ssl_write di OpenSSL
β†’ Hook kprobe pada fungsi TCP kernel
β†’ Dapat: flamegraph, service map, latency per endpoint
β†’ Tanpa mengubah satu baris kode aplikasi

B β€” Runtime Security (Falco)

Masalah:
Deteksi reverse shell atau container escape real-time

Cara lama:
β†’ Kernel module (risiko crash kernel)
β†’ auditd (overhead CPU besar, lambat)

Cara eBPF (Falco modern probe):
β†’ Hook syscall: execve, open, connect, dll
β†’ Ketika container lakukan:
   execve("/bin/sh") β†’ connect(attacker_ip:4444)
β†’ Falco trigger alert dalam < 1ms
β†’ Zero crash risk, overhead minimal

C β€” DDoS Mitigation (Cilium + XDP)

Masalah:
Layanan publik kena DDoS 1 juta paket per detik

Cara lama (iptables):
β†’ Paket masih lewat seluruh stack kernel Linux
β†’ Overhead signifikan, throughput terbatas
β†’ ~1-2 Mpps kemampuan maksimal

Cara eBPF XDP:
β†’ Program eBPF ditempel di driver NIC
β†’ Inspect dan drop paket SEBELUM masuk stack kernel
β†’ Di level hardware, bukan software
β†’ 10+ Mpps per core
β†’ Latency sub-mikrodetik

Masa Depan β€” eBPF + RISC-V + Post-Quantum

eBPF on RISC-V

Status:
Kernel Linux 6.1 sudah support penuh eBPF untuk RISC-V

Mengapa penting:
RISC-V diprediksi 25% pasar IoT dan embedded pada 2030
Open instruction set β€” tidak ada vendor lock-in (beda dari ARM/x86)

Peluang konkret:
Firmware untuk device RISC-V bisa menyertakan eBPF VM
β†’ Remote debugging dan security patching
β†’ Tanpa perlu full OTA update
β†’ Sangat relevan untuk embedded + IoT security

Hardware entry point:
Sipeed Lichee RV (~$20) β†’ install kernel 6.1+ β†’ bisa compile + load eBPF

eBPF + Post-Quantum Cryptography

Konsep:
eBPF bisa memverifikasi tanda tangan PQC (ML-DSA / SLH-DSA)
di dalam kernel sebelum mengizinkan load program eBPF

Artinya:
Hanya program eBPF yang ditandatangani dengan kunci post-quantum
yang bisa jalan di kernel

Kenapa relevan:
Quantum computer di masa depan bisa memalsukan tanda tangan RSA/ECC
Dengan PQC signing β†’ program eBPF tetap terverifikasi bahkan di era quantum

Status:
Masih eksperimental β€” belum ada implementasi production
Ini adalah area riset yang belum ada yang fully explore

eBPF for UEFI (Pre-Boot Security)

Konsep:
Program eBPF berjalan di pre-boot environment (UEFI)

Use case:
Deteksi UEFI rootkit (seperti LoJax, MoonBounce, CosmicStrand)
SEBELUM OS boot β†’ sebelum rootkit sempat aktif

Status:
Proyek eksperimental β€” belum production ready
Tapi arahnya jelas: eBPF turun ke Ring -2 / Pre-Boot level

Roadmap Belajar & Praktik

Fase 1 β€” Hello eBPF (Hari Ini, 10 Menit)

# Install bpftrace (Linux Mint / Ubuntu)
sudo apt install bpftrace
 
# One-liner 1: lihat setiap file yang dibuka oleh setiap proses
sudo bpftrace -e 'tracepoint:syscalls:sys_enter_open {
  printf("%s membuka %s\n", comm, str(args->filename));
}'
 
# One-liner 2: lihat siapa yang lakukan nanosleep (proses idle)
sudo bpftrace -e 'kprobe:do_nanosleep {
  printf("sleep! PID: %d, nama: %s\n", pid, comm);
}'
 
# One-liner 3: monitor koneksi TCP baru
sudo bpftrace -e 'kprobe:tcp_connect {
  printf("connect: %s (PID %d)\n", comm, pid);
}'

Fase 2 β€” Tools eBPF Production (Minggu Ini)

# Install BCC tools (koleksi tools eBPF siap pakai)
sudo apt install bpfcc-tools linux-headers-$(uname -r)
 
# opensnoop β€” lihat semua file yang dibuka
sudo opensnoop-bpfcc
 
# execsnoop β€” lihat semua proses yang dieksekusi
sudo execsnoop-bpfcc
 
# tcptracer β€” trace semua koneksi TCP
sudo tcptracer-bpfcc
 
# biolatency β€” latency disk I/O histogram
sudo biolatency-bpfcc

Fase 3 β€” Deploy Falco (Security Monitoring)

# Falco dengan eBPF driver (modern probe)
helm repo add falcosecurity https://falcosecurity.github.io/charts
helm install falco falcosecurity/falco \
  --set driver.kind=ebpf \
  --set falcosidekick.enabled=true
 
# Default rule yang sudah ada:
# - Shell di dalam container
# - Modifikasi /etc/passwd
# - Koneksi ke IP mencurigakan
# - Privilege escalation attempt

Fase 4 β€” Cilium (Networking + Security)

# Install Cilium di Kubernetes cluster
cilium install
 
# Hubble β€” network observability di atas Cilium
cilium hubble enable
hubble observe --follow
 
# Lihat semua traffic antar pod secara real-time
# Termasuk yang diblokir oleh NetworkPolicy

Fase 5 β€” Tulis Program eBPF Sendiri (libbpf)

// hello_ebpf.c β€” program eBPF minimal
// Hook ke syscall execve, print setiap proses yang dieksekusi
 
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
 
SEC("tracepoint/syscalls/sys_enter_execve")
int hello(void *ctx) {
    bpf_printk("Program baru dieksekusi! PID: %d\n",
               bpf_get_current_pid_tgid() >> 32);
    return 0;
}
 
char LICENSE[] SEC("license") = "GPL";
 
// Compile:
// clang -O2 -target bpf -c hello_ebpf.c -o hello_ebpf.o
// Load:
// sudo bpftool prog load hello_ebpf.o /sys/fs/bpf/hello

Quick Reference β€” Pilih Tool Berdasarkan Kebutuhan

KebutuhanTool eBPFAlternatif Lama
Security: deteksi anomali runtimeFalcoauditd (lebih berat), kernel module (berbahaya)
Networking: observability microservicePixie, HubbleSidecar Envoy (lebih berat)
Networking: service mesh + security policyCiliumIstio + iptables (overhead tinggi)
Performance: profiling CPU/memoryParca, Pyroscopeperf (lebih susah), dtrace
DDoS mitigation: packet drop cepatXDP (via Cilium)iptables (lebih lambat)
Debug: one-liner investigasibpftracestrace (overhead besar), gdb
Security: monitor semua syscallTracee (Aqua)auditd + plugin

Topik Riset yang Belum Ada yang Garap

β€œPost-Quantum Verified eBPF Programs untuk Firmware Air-Gapped Systems” β€” gabungkan ML-DSA signing (NIST PQC standard 2024) dengan eBPF program verification, deploy di pre-boot UEFI environment.

Ini nyambung langsung ke: Kriptografi Post-Quantum + OS Hierarki Level 7-8 + Computer Architecture Ring -2. Belum ada yang publish paper tentang kombinasi ini.


πŸ”— Lihat Juga


eBPF | Extended Berkeley Packet Filter Β· Ring 0 Sandbox Β· Falco Β· Cilium Β· XDP Β· RISC-V Β· Post-Quantum Β· Masa Kini dan Masa Depan Linux Security