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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Drumato
July 24, 2021
Programming
0
370
Writing an experimental eBPF disassembler
適当にLTネタになるかな,と思って作った話.
https://github.com/Drumato/ebpf-disasm
Drumato
July 24, 2021
Tweet
Share
More Decks by Drumato
See All by Drumato
仕様と実装で学ぶOpenTelemetry
drumato
2
2.8k
Activities about Kubernetes operation improvements as an SRE
drumato
3
680
DEMO Apps recently implemented
drumato
0
110
An incremental approach to implement an admission controller
drumato
0
270
Components of Kubernetes Cluster
drumato
0
370
cybozu-labs-youth-10th
drumato
1
1.2k
Other Decks in Programming
See All in Programming
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜 / Understanding nil in Go Interface Representation and Why nil != nil
kuro_kurorrr
3
1.5k
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
13
7.4k
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
800
JPUG勉強会 OSSデータベースの内部構造を理解しよう
oga5
2
220
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
100
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
2k
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
400
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
370
Beyond the Basics: Signal Forms
manfredsteyer
PRO
0
110
TROCCOで実現するkintone+BigQueryによるオペレーション改善
ssxota
0
110
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.2k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
92
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
360
Discover your Explorer Soul
emna__ayadi
2
1.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
64
A Tale of Four Properties
chriscoyier
162
24k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
110
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
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!