More Related Content
Similar to あなたの知らないnopたち@ラボユース合宿
Similar to あなたの知らないnopたち@ラボユース合宿 (6)
More from MITSUNARI Shigeo
More from MITSUNARI Shigeo (20)
あなたの知らないnopたち@ラボユース合宿
- 4. • 何もしない2byte命令(32bit)
• lea eax, [eax]
• 1byte nopを2個実行するより効率がよい(よかった)
• 89 c0h
• 別の何もしない2byte命令
• mov eax, eax
• 8d 04 05 00 00 00 00h
• 何もしない7byte命令
• lea eax, [eax * 1 + 0x00000000]
• ...
8d 00h
4 / 10
- 6. • 90hは本当のnopになった
• xchg eax, eaxではない
• それではxchg eax, eaxはどうなった?
• 87, c0h ; xchgの冗長表現
• xchg rax, raxは48 90h
• 意味的には32bitのnopに対応するが内部的にはnopではない
64bitでのnop
6 / 10
- 7. • いつからnopが拡張された
• nop r/m
• nopがレジスタやメモリアドレッシングを引数に取る
• 32/64bit両対応で同一コード
multi byte nop
66 nop 66 90h
nop dword ptr [eax] 0f 1f 00h
nop dword ptr [eax + 00h] 0f 1f 40 00h
nop dword ptr [eax + eax*1 + 00h] 0f 1f 44 00 00h
66 nop dword ptr [eax + eax*1 + 00h] 66 0f 1f 44 00 00h
nop dword ptr [eax + 00000000h] 0f 1f 80 00 00 00 00h
nop dword ptr [eax + eax*1 + 00000000h] 0f 1f 84 00 00 00 00 00h
66 nop dword ptr [eax + eax*1 + 00000000h] 66 0f 1f 84 00 00 00 00 00h
7 / 10
- 8. • multi byte nopはeax以外の引数も取れる
• nop ecx, eax ; 0f 1f c1h
• nop esp, [rax + rax] ; 0f 1a 04 00h
• Intelはこの余ってるnopを拡張した
multi byte nopの拡張
8 / 10
- 9. • バッファオーバーフローをOS/libレベルでチェック
• 4個の128bit boundレジスタbnd0, bnd1, bnd2, bnd3
• 上位64bitは境界の上限, 下位64bitは境界の下限の値が入る
• bndmk bnd, mem
• memの値をbndレジスタに設定する
• bndcl bnd, r/m
• r/mの値がbndの下限より大きいかを確認
• bndcu bnd, r/m
• r/mの値がbndの上限より小さいかを確認
• 範囲外ならbounds violationが発生
MPX(Memory Protection Extensions)
9 / 10
- 10. • MPX非対応CPU/OSで影響が出ないように拡張
• 対応していないとこう見える
MPXエンコーディング
bndmk bnd0, [rax] ; f3 0f 1b 00h
bndcl bnd0, rax ; f3 0f 1a c0h
bndcu bnd0, rax ; f2 0f 1a c0h
bndldx bnd0, [rax+rax] ; 0f 1a 04 00h
bndstx [rax+rax], bnd0 ; 0f 1b 04 00h
nop eax, [rax]
nop eax, eax
nop eax, eax
nop esp, [rax+rax]
nop esp, [rax+rax]
10 / 10
[rax*2]と等しくない
省略可能な3引数オペランド
の一部としてSIBを利用