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
390
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
110
仕様と実装で学ぶOpenTelemetry
drumato
2
2.9k
Activities about Kubernetes operation improvements as an SRE
drumato
3
720
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
AIで効率化できた業務・日常
ochtum
0
140
さぁV100、メモリをお食べ・・・
nilpe
0
140
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
160
New "Type" system on PicoRuby
pocke
1
950
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
240
The NotImplementedError Problem in Ruby
koic
1
800
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
700
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
130
OSもどきOS
arkw
0
570
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Technical Leadership for Architectural Decision Making
baasie
3
410
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Writing Fast Ruby
sferik
630
63k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Producing Creativity
orderedlist
PRO
348
40k
Building an army of robots
kneath
306
46k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Navigating Team Friction
lara
192
16k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
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!