Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Writing an experimental eBPF disassembler
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Drumato
July 24, 2021
Programming
380
0
Share
Writing an experimental eBPF disassembler
適当にLTネタになるかな,と思って作った話.
https://github.com/Drumato/ebpf-disasm
Drumato
July 24, 2021
More Decks by Drumato
See All by Drumato
Compotable Platform Shift ~AWS全面移設におけるプラットフォームエンジニアリングの実践~
drumato
0
90
仕様と実装で学ぶOpenTelemetry
drumato
2
2.9k
Activities about Kubernetes operation improvements as an SRE
drumato
3
700
DEMO Apps recently implemented
drumato
0
120
An incremental approach to implement an admission controller
drumato
0
280
Components of Kubernetes Cluster
drumato
0
390
cybozu-labs-youth-10th
drumato
1
1.2k
Other Decks in Programming
See All in Programming
JOAI2026 1st solution - heron0519 -
heron0519
0
140
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
120
forteeの改修から振り返るPHPerKaigi 2026
muno92
PRO
3
290
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
340
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
140
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
180
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
1
190
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
1
360
Swift Concurrency Type System
inamiy
0
530
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
770
Measuring & Analyzing Core Web Vitals
bluesmoon
9
810
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
270
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
450
Become a Pro
speakerdeck
PRO
31
5.9k
Abbi's Birthday
coloredviolet
2
7.1k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
99
It's Worth the Effort
3n
188
29k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
140
Information Architects: The Missing Link in Design Systems
soysaucechin
0
890
Transcript
eBPF disassemblerを作る Drumato
Attention! • 完全準拠ではない • torvalds/linux/samples/bpfのkernel side sourceがそれっぽくなればOKまで をやった
背景
なんとなくeBPFについての記事を読んでた
"基本的に命令長は64bit固定" という記述を見る
素敵! disasm書きたい! (x64を想いつつ)
書く
身につける必要があった知識 • Object file上でeBPF functionがどのように表現されているか • Opcode encoding/immediateの形式を知る
あとは頑張って書く
これはassembler自作と大して変わらない
ELF Header
eBPF object file#ELF Header
eBPF object file#ELF Header
E_machine以外は普通のrelocに見える
Section Header Table
eBPF object file#SHT
eBPF object file#SHT .textはあるけど 中身は空
eBPF object file#SHT SEC("socket1")のように 書いたsymbolが sectionに
eBPF object file#SHT eBPF mapsもsectionに Entry sizeは Programで決まっていて, Shdr.sh_entsizeを読んでも わからない
Key + valueのどちらも可変なので entsizeは使えないか(linkとinfoは?)
eBPF object file#SHT これは単に"GPL\0"という文字列が 入っているだけ
Symbol table
eBPF object file#symtab
ぱっと見特に気になる点はなし
eBPF object file#summary • なんとなく以下を満たすsectionをdisasすれば良さそう ◦ Shdr.sh_type == SHT_PROGBITS ◦
Shdr.sh_flags & (SHF_ALLOC | SHF_EXECINSTR) != 0 ◦ Shdr.sh_size > 0
eBPF instruction architecture
eBPF instruction architecture#overview
eBPF instruction architecture#overview OpcodeEncoding head byteをどう解釈するか
eBPF instruction architecture#overview InstructionClass Opcodeをどう解釈するか Ex1. ic=0x04ならopcode=0x00はAdd ic=0x05ならopcode=0x00はJA
eBPF instruction format ArithOrJump Memory
eBPF instruction format ArithOrJump Memory ADD/SUB/MUL/DIV/MOD/LSH etc.. JA/JEQ/JGT/JSLT/ etc...
eBPF instruction format ArithOrJump Memory Use src field as register
If S bit is up
eBPF instruction format ArithOrJump Memory ALU/ALU64/JMP/JMP64
eBPF instruction format ArithOrJump Memory IMM/MEM/IND/ABS etc
eBPF instruction format ArithOrJump Memory Byte/Half word/Word/Double Word
eBPF instruction format ArithOrJump Memory LD/LDX/ST/STX
わかったら書く!書く!
機械語programmingは手動かす!
disasm#tips • Building block的に作ると良い ◦ Opcode type/InstClass typeを作ってEncoding typeを作る ▪
それぞれのdecoderを書く ◦ それら(とsrc/dst/offset/imm)をまとめてInstruction typeを作る ▪ decoderを次々呼ぶだけ • srcは ooooxxxx のようになっているけど,4bit rshすると使いやすい ◦ Register numberに変換する感覚
disasm#summary
disasm#summary
このくらいのしょぼ完成度なら サクッと数時間で作れる
references • Linux Socket Filtering aka Berkeley Packet Filter (BPF)
- www.kernel.org • Drumato/ebpf-disasm … 実装 ◦ 完全じゃないよ(Memory InstClassは適当)
Thanks!