Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
eBPF
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoru Takeuchi
PRO
December 08, 2025
Technology
190
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
eBPF
以下動画のスライドです。
https://youtu.be/XdZEmdphJG4
Satoru Takeuchi
PRO
December 08, 2025
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
82
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
110
あなたの知らないバージョン命名規則
sat
PRO
3
930
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
82
Machine Check Exception
sat
PRO
2
73
バイナリダンプの模様を読む
sat
PRO
0
120
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
120
114-ファイルのshallow_copy.pdf
sat
PRO
2
70
113-Btrfsのスナップショット.pdf
sat
PRO
0
50
Other Decks in Technology
See All in Technology
1週間、Opus封印でお願いします
kintotechdev
1
460
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
590
AIエージェント統制はAPIから——押さえるべき5つの要素
nagix
0
120
Microsoft Entra Kerberos で実現するクラウド デバイス管理
tamaiyutaro
0
190
The future of architectural work
ufried
0
150
リアクションエンジニア ― 小さなリアクションから、話しかけやすい組織をつくる ―
ryuguyana
1
120
reInvent2026stby LT00 "Change your life!"
shinichirokawano
1
570
eBPF 簡介 2026 版
shunghsiyu
0
170
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
170
これだけは抑えておきたい!後悔しない re:Invent の過ごし方 / AWS re:Invent 2026 prestudy
kinunori
2
700
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
630
企画からFlutter実装まで、1つの機能を一貫して開発したプロセスと成果物
khiroyuki1003
1
150
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
600
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
Rails Girls Zürich Keynote
gr2m
96
14k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.7k
The SEO Collaboration Effect
kristinabergwall1
1
610
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Producing Creativity
orderedlist
PRO
348
41k
The Cult of Friendly URLs
andyhume
79
7.1k
Transcript
eBPF Dec. 8th, 2025 Satoru Takeuchi X: satoru_takeuchi
eBPF • Linuxカーネルの機能 • カーネル本体に手を入れず、カーネル空間で安全にプログラムを動かせる • うまくプログラムを書けば… ◦ ビルド済みバイナリを複数カーネルバージョンで動かせる ◦
同、別アーキテクチャの CPUで動かせる • 適用範囲: ◦ トレース(例: bpftrace) ◦ パケット処理(例: Cilium) ◦ 不正動作検出&禁止(例: Falco)
プログラムをカーネルにロードするまでの流れ ソースコード (eBPF C, Rust) eBPF bytecode (アーキテクチャ 非依存) eBPFサブシステム
clang + LLVM BPF backend 変換 eBPFのツール、ライブラリ (libbpf, cilium agent) bpf() syscall呼び出しによりロード verifier(後述) eBPF bytecode 安全性チェック ユーザ空間 カーネル空間
ロード後に実行する流れ eBPFサブシステム eBPF bytecode 何らかのイベント発生 ! カーネル 様々なサブシステム (1) 検出
(2) イベントに対応した ebpfプログラム呼び出し eBPF VM (3) 実行 (JITコンパイル有り)
イベントの例 • システムコール呼び出し、復帰時 • 特定のコード実行時(関数呼び出し時、特定の命令実行時、復帰時など) ◦ カーネルのコードだけでなくプロセスのコードの実行にも使える • パケット送受信時 •
ファイルシステムI/O時 • タイマー起動時
eBPFプログラムの例
実験環境 • CPU architecture: x86_64 • OS: Ubuntu 24.04.3 •
kernel: 6.8.0-88-generic
プログラム実行時にメッセージを表示 #include <linux/bpf.h> #include <bpf/bpf_helpers.h> char LICENSE[] SEC("license") = "GPL";
struct sys_enter_execve_args { unsigned long long unused; long syscall_nr; const char *filename; const char *const *argv; const char *const *envp; }; SEC("tracepoint/syscalls/sys_enter_execve") int trace_exec(struct sys_enter_execve_args *ctx) { bpf_printk("execve is called: %s\n", ctx->filename); return 0; }
実行すると… $ clang -O2 -g -target bpf \ -I/usr/include \
-I/usr/include/x86_64-linux-gnu \ -c test.c -o test.o $ sudo bpftool prog load test.o /sys/fs/bpf/waruibpf autoattach $ sudo cat /sys/kernel/debug/tracing/trace_pipe
execve()が呼び出されるたびにログが出る $ clang -O2 -g -target bpf \ -I/usr/include \
-I/usr/include/x86_64-linux-gnu \ -c test.c -o test.o $ sudo bpftool prog load test.o /sys/fs/bpf/waruibpf autoattach $ sudo cat /sys/kernel/debug/tracing/trace_pipe … (kubelet)-2944 [000] ...21 773.184329: bpf_trace_printk: execve is called: /usr/bin/kubelet ...
ethernetフレーム受信時にL3のプロトコルを表示 #include "vmlinux.h" #include <bpf/bpf_helpers.h> #include <bpf/bpf_endian.h> char LICENSE[] SEC("license")
= "GPL"; SEC("xdp") int xdp_print_eth_proto(struct xdp_md *ctx) { void *data = (void *)(long)ctx->data; void *data_end = (void *)(long)ctx->data_end; if (data + sizeof(struct ethhdr) > data_end) return XDP_PASS; struct ethhdr *eth = data; __u16 proto = bpf_ntohs(eth->h_proto); bpf_printk("XDP eth proto = 0x%x\n", proto); return XDP_PASS; }
eth0にアタッチすると… … $ sudo ip link set dev eth0 xdp
obj test.o sec xdp $ sudo cat /sys/kernel/debug/tracing/trace_pipe
protocolが表示された… … $ sudo ip link set dev eth0 xdp
obj test.o sec xdp $ sudo cat /sys/kernel/debug/tracing/trace_pipe … <idle>-0 [002] ..s2. 1667.143565: bpf_trace_printk: XDP eth proto = 0x800 <idle>-0 [000] ..s2. 1667.159162: bpf_trace_printk: XDP eth proto = 0x800 <idle>-0 [002] ..s2. 1667.160285: bpf_trace_printk: XDP eth proto = 0x800 ... 0x800はIPv4
eBPFの安全装置
安全装置1: カーネル内のsandbox上での実行 BPF map 別のeBPFプログラム BPF map BPF map eBPFプログラム
カーネル本体 eBPFヘルパー関数 読み書き 読み書き 発生したイベントのコ ンテキスト 呼び出し 読み書き(ほぼROM) データ、コード アクセス不可 アクセス
安全装置2: verifier • eBPFバイトコードをカーネルにインストールする前に動作 • バイトコードを静的解析 • 危険と判断したプログラムのインストールを失敗させる ◦ 不正なデータにアクセスする可能性がある
◦ read only領域にwriteする ◦ コードが長すぎる
verifierによりロードが失敗する例
実行するコードが長いとき #include <linux/bpf.h> #include <bpf/bpf_helpers.h> … SEC("tracepoint/syscalls/sys_enter_execve") int trace_exec(struct sys_enter_execve_args
*ctx) { volatile int dummy = 0; for (int i = 0; i < 1000000; i++) dummy++; bpf_printk("execve: %d\n", dummy); return 0; }
実行すると… … $ sudo bpftool prog load test.o /sys/fs/bpf/waruibpf autoattach
検証失敗! … $ sudo bpftool prog load test.o /sys/fs/bpf/waruibpf autoattach
… 6: (61) r3 = *(u32 *)(r10 -4) ; R3_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R10=fp0 fp-8=mmmm???? ; for (int i = 0; i < 1000000; i++) 7: (07) r1 += -1 ; R1_w=0xd9039 8: (bf) r2 = r1 ; R1_w=0xd9039 R2_w=0xd9039 9: (67) r2 <<= 32 BPF program is too large. Processed 1000001 insn processed 1000001 insns (limit 1000000) max_states_per_insn 4 total_states 11112 peak_states 11112 mark_read 1 -- END PROG LOAD LOG -- libbpf: prog 'trace_exec': failed to load: -E2BIG libbpf: failed to load object 'test.o' Error: failed to load object file make: *** [Makefile:10: run] Error 255 … 1つのeBPFプログラムは 100万命令を超えてはならない
ethernetフレームだけ受信するだろ?とチェックを外すと #include "vmlinux.h" #include <bpf/bpf_helpers.h> #include <bpf/bpf_endian.h> char LICENSE[] SEC("license")
= "GPL"; SEC("xdp") int xdp_print_eth_proto(struct xdp_md *ctx) { void *data = (void *)(long)ctx->data; void *data_end = (void *)(long)ctx->data_end; //if (data + sizeof(struct ethhdr) > data_end) // return XDP_PASS; struct ethhdr *eth = data; __u16 proto = bpf_ntohs(eth->h_proto); bpf_printk("XDP eth proto = 0x%x\n", proto); return XDP_PASS; }
実行すると… … $ sudo ip link set dev eth0 xdp
obj test.o sec xdp
検証失敗! … $ sudo ip link set dev eth0 xdp
obj test.o sec xdp libbpf: prog 'xdp_print_eth_proto': BPF program load failed: Permission denied libbpf: prog 'xdp_print_eth_proto': -- BEGIN PROG LOAD LOG -- 0: R1=ctx() R10=fp0 ; void *data = (void *)(long)ctx->data; 0: (61) r1 = *(u32 *)(r1 +0) ; R1_w=pkt(r=0) ; __u16 proto = bpf_ntohs(eth->h_proto); 1: (69) r3 = *(u16 *)(r1 +12) invalid access to packet, off=12 size=2, R1(id=0,off=12,r=0) R1 offset is outside of the packet processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 -- END PROG LOAD LOG -- libbpf: prog 'xdp_print_eth_proto': failed to load: -13 libbpf: failed to load object 'test.o' … パケットの長さが14バイト(イーサネット ヘッダのプロトコルを示すフィールドの末 尾)より短い可能性がある
まとめ • いいところ ◦ カーネル空間で安全にプログラムを実行できる ▪ バグってしまっているプログラム、悪意を持ったプログラムは verifierがロードさせない ◦ JITコンパイラのおかげでネイティブコードを実行できる
• 不便なところ ◦ verifierを通す儀式がちょっと面倒 ▪ veristatやChatGPTを使えば、ある程度楽ができる • 参考 ◦ eBPF公式サイト ▪ https://ebpf.io/ ◦ 入門eBPF ▪ https://www.oreilly.co.jp/books/9784814400560/ ◦ 詳解システムパフォーマンス ▪ https://www.oreilly.co.jp/books/9784814400072/