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
Drumato
July 24, 2021
Programming
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Writing an experimental eBPF disassembler
適当にLTネタになるかな,と思って作った話.
https://github.com/Drumato/ebpf-disasm
Drumato
July 24, 2021
More Decks by Drumato
See All by Drumato
Composable Platform Shift ~AWS全面移設におけるプラットフォームエンジニアリングの実践~
drumato
0
130
仕様と実装で学ぶOpenTelemetry
drumato
2
3k
Activities about Kubernetes operation improvements as an SRE
drumato
3
730
DEMO Apps recently implemented
drumato
0
130
An incremental approach to implement an admission controller
drumato
0
290
Components of Kubernetes Cluster
drumato
0
410
cybozu-labs-youth-10th
drumato
1
1.2k
Other Decks in Programming
See All in Programming
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
140
Android CLI
fornewid
0
230
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
510
今さら聞けない .NET CLI
htkym
0
210
Dockerfile CMD for Node.js
grazie1999
0
120
リアルな遅延を測る仕様
kota_yata
1
120
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
100
プロポーザルを書いてもらう
pvcresin
0
570
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.5k
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
500
Flow は今どうなっているか
mizdra
PRO
0
680
Featured
See All Featured
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
RailsConf 2023
tenderlove
30
1.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Technical Leadership for Architectural Decision Making
baasie
3
520
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Ruling the World: When Life Gets Gamed
codingconduct
0
310
Making the Leap to Tech Lead
cromwellryan
135
10k
Darren the Foodie - Storyboard
khoart
PRO
3
3.7k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
800
Leo the Paperboy
mayatellez
8
2.2k
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!