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
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.9k
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
380
cybozu-labs-youth-10th
drumato
1
1.2k
Other Decks in Programming
See All in Programming
20260315 AWSなんもわからん🥲
chiilog
2
140
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
200
SourceGeneratorのマーカー属性問題について
htkym
0
190
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
230
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
「抽象に依存せよ」が分からなかった新卒1年目の私が Goのインターフェースと和解するまで
kurogenki
0
110
文字コードの話
qnighy
44
17k
Ruby and LLM Ecosystem 2nd
koic
1
670
TipKitTips
ktcryomm
0
160
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
150
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
1.9k
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
160
Featured
See All Featured
Claude Code のすすめ
schroneko
67
220k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Why Our Code Smells
bkeepers
PRO
340
58k
Ethics towards AI in product and experience design
skipperchong
2
220
Into the Great Unknown - MozCon
thekraken
40
2.3k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
130
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
250
The Limits of Empathy - UXLibs8
cassininazir
1
260
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
470
What does AI have to do with Human Rights?
axbom
PRO
1
2k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
200
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
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!