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
74
仕様と実装で学ぶOpenTelemetry
drumato
2
2.9k
Activities about Kubernetes operation improvements as an SRE
drumato
3
690
DEMO Apps recently implemented
drumato
0
110
An incremental approach to implement an admission controller
drumato
0
270
Components of Kubernetes Cluster
drumato
0
380
cybozu-labs-youth-10th
drumato
1
1.2k
Other Decks in Programming
See All in Programming
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
720
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
520
Claude Code Skill入門
mayahoney
0
450
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
310
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
200
20260320登壇資料
pharct
0
140
Claude Codeログ基盤の構築
giginet
PRO
7
3.8k
ロボットのための工場に灯りは要らない
watany
12
3.2k
テレメトリーシグナルが導くパフォーマンス最適化 / Performance Optimization Driven by Telemetry Signals
seike460
PRO
2
200
The free-lunch guide to idea circularity
hollycummins
0
390
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
470
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3k
AI: The stuff that nobody shows you
jnunemaker
PRO
4
500
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
92
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
780
Facilitating Awesome Meetings
lara
57
6.8k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Leo the Paperboy
mayatellez
5
1.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Ethics towards AI in product and experience design
skipperchong
2
240
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!