Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Stack&Heep
Search
Kotokaze
May 31, 2021
Education
90
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stack&Heep
スタック・ヒープオーバーラン勉強会の資料です
Kotokaze
May 31, 2021
More Decks by Kotokaze
See All by Kotokaze
Introduction to Git & GitHub
kotokaze
0
250
ファイルレスマルウェアの実態と対策
kotokaze
1
540
実は簡単!? AIを攻撃してみよう
kotokaze
0
410
Other Decks in Education
See All in Education
Del ojo entrenado a la visión computacional: evaluación de la severidad de enfermedades
emdelponte
0
130
批判的応用言語学ワークショップ(2026-08-12 お茶の⽔⼥⼦⼤学)
terasawat
0
200
響け!ユーフォニアムと考える「決め方」/Thinking About Decision-Making with Sound! Euphonium
3l4l5
1
190
AIってなぁに?
kenichiota0711
0
840
1人 × AI、1か月でここまで作れる ー 数年前の外注換算3.8〜7.4億円・241〜379人月分の作業を、AI費用 約10万円・31日で
frievea
0
520
Science Tokyo University for International Research Excellence scheme_April 2026
sciencetokyo
PRO
0
230
新しいJavaを学んで・使っていこう! / osd26do
gishi_yama
0
260
Plano urbano de Madrid desde el Ensanche al s. XXI (2ª parte).
juanmartin2026
1
88k
2026年度春学期 統計学 第14回 分布についての仮説を検証する ― 仮説検定(1) (2026. 7. 2)
akiraasano
PRO
0
150
中小規模私大の教学IRを支えるデータマネジメント ― データ基盤構築の取り組みと実務の現在地 ―
terazawa
0
170
AIでアウトプットできる時代だからこそ、自分の言葉で考えることの大切さ / What's Left to Think, When AI Can Write?
masakiokuda
1
330
遊ぶかね欲しさの犯行(ルビ:労働)です
shirayanagiryuji
0
270
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
500
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
580
Design in an AI World
tapps
1
330
The Spectacular Lies of Maps
axbom
PRO
1
1k
sira's awesome portfolio website redesign presentation
elsirapls
0
420
The Cult of Friendly URLs
andyhume
79
7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
430
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Six Lessons from altMBA
skipperchong
29
4.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Transcript
スタックとヒープ Kotokaze
1. メモリとは データの⼀時置き場 ( ⼤きな配列のようなもの) のこと プロセス実⾏時には、プログラムがメモリ上に展開される → 32bit コンピュータであれば、232
分だけ確保* される +----------------------------------------------------- ---------------+ | 0x00000000 | 0x00000001 | 0x00000002 | 0x00000003 | ≈≈≈≈≈ | 0xFFFFFFFF | +----------------------------------------------------- ---------------+ * ほとんどの場合では、必要とする分だけ OS が⽤意してくれる 2
environ argv share bss data text 0 番地 232 番地
heep stack 2. プロセスとメモリ 名称 主な配置データ 備考 text 機械語 Read Only data グローバル変数 初期値有り bss グローバル変数 初期値無し heep 動的なデータ malloc など stack ⾃動変数/ アドレス ⾃動的に拡張 3
data data 3. スタック 積み⽊ように、積み上げてデータ保存 アクセスできるのは最上位のみ スタック領域では、ローカル変数・ リターンアドレスなどを保存 命令語 内容
PUSH スタックの先頭に追加 POP スタック先頭の値を取り出す 4
使⽤中 data1 data0 使⽤中 使⽤中 使⽤中 4. ヒープ 使う分だけ確保して使う 未整列
( 空域に⾃動配置) → 場所指定でアクセス可 ⾃由度は⾼いが、 脆弱になりやすい int* data0 = new int[sizeof(buff)]; int* data1 = malloc(sizeof(buff)); 5
5. バッファ・オーバーラン (CWE-119) 実⾏中プロセスのメモリ内における、 意図したバッファ外の値を読み書きすること C / C++ で発⽣しやすい 名称
対象 スタック破壊攻撃 ローカル( ⾃動) 変数・リターンアドレス ヒープ破壊攻撃 配置したデータ 6
6. プログラム解析 サンプルコードの解析をしてみよう! サンプルコード: Kotokaze/stack-study 7
6. プログラム解析 (2) Key1: Stack のコンストラクタで、 data0 / data1 を初期化
→ ヒープ領域に連続して* 配置されていると考えられる +-----------------------------------------------------------------------+ | data0 | data1 | ≈≈≈≈≈ | +-----------------------------------------------------------------------+ * 複数の初期化を同時に⾏うと、連続して配置される場合が多い 8
6. プログラム解析 (3) Key2: コンストラクタに注⽬ for (int i = 0;
i <= this->tail; i++) this->data1[i] = 3; 名称 \ 位置 0 1 2 3 4 5 6 7 data0 - - - - - - - - data1 3 3 3 3 3 3 3 3 9
6. プログラム解析 (4) Key3: 値の変化に注⽬ → main のループで順に代⼊していくと... for (int
i = 0; i < num; i++) stk.push(i + 1); 名称 \ 位置 0 1 2 3 4 5 6 7 data0 1 2 3 - - - - - data1 3 3 3 3 3 3 3 3 10
7. 動かしてみる data0 に 12 回の値を⼊れ続けるとどうなる??? → README を参考に動かしてみよう ※
脆弱性を含んでいる事に注意しましょう 11
参考情報 https://jvndb.jvn.jp/ja/cwe/CWE-119.html https://www.ipa.go.jp/security/awareness/vendor/programmingv2/ contents/c901.html 12