跳到主要內容區塊

ntuccepaper2019

技術論壇

潛藏於CPU的漏洞:Meltdown & Spectre
  • 卷期:v0045
  • 出版日期:2018-06-20

作者:林子南 / 臺灣大學計算機及資訊網路中心作業管理組幹事


旁通道攻擊是針對硬體或物理上的特性來達成滲透,其中Meltdown與Spectre是針對CPU的Cache Attack,分別利用Out-of-order Execution與Branch Prediction來讀取其他程式儲存在記憶體中的資料。 CPU除了用Virtual Address Space區隔每個程式的程式碼與資料,也使用了Address Space Layout Randomization(ASLR)、Kernel Address Space Layout Randomization(KALSR)等技術,來防止駭客從固定記憶體位置(分配給作業系統以外程式的記憶體)找出機敏資料(帳號、密碼等),而Meltdown與Spectre則可以透過針對Cache與記憶體的Flush+Reload攻擊來取得機敏資料。[1]

 

原理

現代的CPU會配合Pipeline的技術來提升單位時間內執行的CPU指令數量,因為不同指令所需的Execution Unit不一樣,讓連續數個CPU指令在執行完成前不佔用同一個Execution Unit,以此來提升單位時間CPU指令執行數量。

 


圖 1, Intel’s Skylake microarchitecture
圖片來源: https://www.securityinfo.it/2018/01/04/intel-spectre-meltdown/


配合圖1解釋以下Meltdown和Spectre的運作原理:
1. Out-of-order Execution
因為不同指令所需的執行時間長度不一樣,當前幾條CPU指令尚未執行完成以前,提前完成的CPU指令就稱為Out-of-order Execution。[2]
Meltdown透過在引起Exception Handker前,CPU先完成從其他程式的記憶體空間載入資料到Cache的Out-of-order Execution,當Out-of-order Execution因Exception Handker被中斷後,雖然Reorder Buffer會清空Out-of-order Execution所使用的Registers,但是載入的資料仍存在Cache中,再透過Flush+Reload就能從最後一層Cache中取得資料。

2. Speculative Execution
跟在CPU的Branch指令後面的數個指令,在Pipline中會因為Branch指令耗時較長,導致後續幾個指令會先執行後將結果存入Reorder Buffer,並等待Branch指令完成。

3. Branch Prediction
在圖1中的Branch predictor會依照之前執行Branch指令的結果,來預測界下來Branch指令的輸出,同時會依照預測的結果執行對應區塊的指令,也就是Speculative Execution,如果發生預測錯誤的情況時,則會由Reorder Buffer來清空Speculative Execution所使用到的Registers。
Spectre就是透過在Reorder Buffer清空Speculative Execution時,因為不會清空已經載入到Cache的值,用Flush+Reload的方式來取得最後一層Cache中的值。

4. Meltdown and Spectre
兩者都是透過Pipeline技術中同時執行多個CPU指令的特性,用不同的方式去阻止指令繼續執行,並改成用Flush+Reload等洩漏Cache值的方式來取得值。
Meltdown是因為作業系統或CPU沒有檢查Out-of-order Execution中是否包含了惡意指令的特性,使用這樣的攻擊手法必須從組合語言上嚴格限制執行順序,因此無法用做遠端攻擊。Spectre是透過Branch Prediction使惡意的Speculative Execution在預測結果以前先執行,因此可以透過高階程式語言來達成,利用高階程式語言(例如網頁前端程式語言)多次執行if-else、for、while等流程控制的程式碼,讓低階程式語言產生對應的Branch Prediction,以此達成從遠端攻擊。

 

表格 1, Meltdown與Spectre比較[2, 3]

 

透過什麼方式將實體記憶體位置注入Cache

Out-of-order execution

Speculative execution from branch prediction

CPU

大部分的Intel CPU
(AMD與ARM的CPU會因為從執行攻擊的速度不夠快而失敗[2])

Intel、AMD、ARM

KASLR是否能防止機敏資料洩漏

O

X

是否能遠端攻擊

X

O
(利用瀏覽器執行Javascript來達成攻擊[3])

 

應對措施

除了CPU廠商應該要發布相關韌體的更新之外,對應的作業系統也應該要更新,以常見的2大作業系統環境來看,Apple和Microsoft已經即時的發布了許多更新,而同樣作為廣泛使用2大Virtual Machine環境(VMware、Hyper V)也發布了相關更新:

1. Apple [4, 5]
Apple在Mac電腦、iPhone、iPad、Apple TV上各自發布了更新,iPhone、iPad 的iOS版本從11.2開始在安全性更新就包含了抵禦Meltdown與Spectre的更新。
Mac電腦在macOS High Sierra 10.13.2與補充更新(Supplemental Update)改善了作業系統、Safari、WebKit的安全性,能夠防止Meltdown與Spectre,而在macOS Sierra、OS X EI Capitan作業系統則提供了對應Meltdown的安全性更新與Spectre的Safari更新。

 

表格 2, Apple各平台的更新

 

iOS

macOS

tvOS

Apple Watch

against Meltdown

11.2

安全性更新 2018-001 Sierra
安全性更新 2018-001 El Capitan
10.13.2 (macOS High Sierra)

11.2

Not affected

against Spectre

11.2.2

10.13.2(macOS High Sierra)
Safari 11.0.2(macOS Sierra and OS X El Capitan)

X

Not affected

 

2. Microsoft
Microsoft目前已經針對不同Windows發布了Meltdown與Spectre等Cache Attack的更新(表格 2),因為這樣的更新會對Cache存取記憶體的速度造成影響,Microsoft也推出了面向IT工程師的服務(Windows Analytics service,支援Windows 10、Windows 10 Mobile、Windows Server、Azure),用來評估更新對安全與效能的影響[6, 7]。

 

表格 3, Windows更新

Windows 10

Windows 8 and
Windows Server 2012

Windows 7 and
Windows Server 2008

version 1507 — KB4056893 (issued 1/3/18)
version 1511 — KB4056888 (issued 1/3/18)
version 1607 — KB4056890 (issued 1/3/18)
version 1703 — KB4056891 (issued 1/3/18)
version 1709 — KB4056892 (issued 1/3/18)
Update that disables Intel's Spectre variant 2 mitigation (which has caused issues) — KB4078130 (issued 1/27/18)

Windows 8.1 and Server 2012 R2— KB4056898 (issued 1/3/18)
Update that disables Intel's Spectre variant 2 mitigation (which has caused issues) — KB4078130 (issued 1/27/18)
No patches available for Windows Server 2012 non-R2 version
 

Windows 7 SP1 and Server 2008 R2 SP1 — KB4056897 (Security only, issued 1/3/18)
Windows 7 SP1 and Server 2008 R2 SP1 — KB4056894 (Monthly rollup, issued 1/4/18)
Update that disables Intel's Spectre variant 2 mitigation (which has caused issues) — KB4078130 (issued 1/27/18)
No patches available for Windows Server 2008 non-R2 version

 

3. Hyper-V[8]
Hyper-V Host也會因為Meltdown與Spectre攻擊而洩漏資料,對此Microsoft也提出了更新與解決方法,III的資訊仰賴於各家OEM,故在此不提及,在下文中將只提到I、II的資訊:
I. 在Hyper-V Host上佈署相關更新
II. 設定Registry來保護Hyper-V Host
III. 進行韌體更新

I. 在Hyper-V Host上佈署相關更新
因為Windows Server 2012、Windows Server 2008需要廣泛的架構變更,目前沒有提供關於Meltdown與Spectre攻擊的更新。

 

表格 4, Microsoft提供Hyper-V Host的相關更新

OS Version

Update KB (x64)

Windows Server, version 1709
(Server Core Installation)

4056892

Windows Server 2016

4056890

Windows Server 2012 R2

4056898

Windows Server 2012

目前沒有相關更新

Windows Server 2008 R2

4056897

Windows Server 2008

目前沒有相關更新

 

II. 設定Registry來保護Hyper-V Host
在Registry進行以下設定或將以下指令輸入CMD(或PowerShell),在重新開機以後就會生效,因為Microsoft還會更新相關文件,詳細說明請參考[8]:

 

To enable the fix

reg add
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v
FeatureSettingsOverride /t REG_DWORD /d 0 /f
reg add
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v
FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f

reg add
"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization"
/v MinVmVersionForCpuBasedMitigations /t REG_SZ /d "1.0" /f
 

To disable this fix

reg add
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v
FeatureSettingsOverride /t REG_DWORD /d 3 /f

reg add
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v
FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f

 

並用以下指令從PowerShell檢查是否啟用保護,或是從TechNet下載工具檢測:

 

PS> Install-Module SpeculationControl
PS> $SaveExecutionPolicy = Get-ExecutionPolicy
PS> Set-ExecutionPolicy RemoteSigned -Scope Currentuser
PS> Import-Module SpeculationControl
PS> Get-SpeculationControlSettings
PS> Set-ExecutionPolicy $SaveExecutionPolicy -Scope Currentuser

4. VMware[9]
VMware上的VM Guest會受到Meltdown與Spectre的影響而洩漏同一台Host上其他VM Guest上的資料,而VMware Hypervisor則會受到Spectre攻擊的影響,對於上述的問題VMware提出了以下的更新:

 

表格 5, Hypervisor的更新

產品

版本

更新文件

VMware vSphere ESXi

5.5
6.0
6.5
VMC

VMSA-2018-0002

VMware Workstation

12.x
14.x

VMware Fusion

8.x
10.x

 

VMware因為Intel與AMD提供了硬體方面的支援,進而提出VM Guest的更新,除了安裝VMSA-2018-0004之外,詳細操作步驟與指令請參考Hypervisor-Assisted Guest Mitigation for branch target injection (52085)[10]。

 

參考

[1]G. U. o. Technology. (2018). Meltdown and Spectre. Available: https://meltdownattack.com/
[2]M. Lipp et al., "Meltdown," ArXiv e-prints, January 2018.
[3]P. Kocher et al., "Spectre Attacks: Exploiting Speculative Execution," ArXiv e-prints, January 2018.
[4] (2018). Apple 安全性更新. Available: https://support.apple.com/zh-tw/HT201222
[5] (2018). About speculative execution vulnerabilities in ARM-based and Intel CPUs. Available: https://support.apple.com/en-us/HT208394
[6] T. Myerson. (2018). Windows Analytics now helps assess Meltdown and Spectre protections. Available: https://blogs.windows.com/business/2018/02/13/windows-analytics-now-helps-assess-meltdown-and-spectre-protections/#QehWisWZ5sbC6HZy.97
[7] J. D. Brian Lich. (2017). Configure Windows diagnostic data in your organization. Available: https://docs.microsoft.com/zh-tw/windows/configuration/configure-windows-diagnostic-data-in-your-organization
[8] (2018). Windows Server guidance to protect against speculative execution side-channel vulnerabilities. Available: https://support.microsoft.com/en-us/help/4072698/windows-server-guidance-to-protect-against-the-speculative-execution
[9] (2018). VMware Response to Speculative Execution security issues, CVE-2017-5753, CVE-2017-5715, CVE-2017-5754 (aka Spectre and Meltdown) (52245). Available: https://kb.vmware.com/s/article/52245
[10] (2018). Hypervisor-Assisted Guest Mitigation for branch target injection (52085). Available: https://kb.vmware.com/s/article/52085