Mitigating Spectre variant 2 with Retpoline on Windows

The new Retpoline and Import Optimization features should give your system performance back

Prerequisites: Windows 10/Server 2019, version 1809 with KB4482887

Note: Skylake and later generations of Intel processors are not compatible with Retpoline, so only Import Optimization will be enabled on these processors.



On Client SKUs:

1
2
3
 
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 0x400
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 0x400
Reboot
 


On Server SKUs:

1
2
3
 
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 0x400
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 0x401
Reboot
 


More info:
https://techcommunity.microsoft.com/t5/W...ows/ba-p/295618

SpeculationControl PowerShell Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 

For more information about the output below, please refer to https://support.microsoft.com/en-in/help/4074629
 
Speculation control settings for CVE-2017-5715 [branch target injection]
 
Hardware support for branch target injection mitigation is present: True
Windows OS support for branch target injection mitigation is present: True
Windows OS support for branch target injection mitigation is enabled: True
 
Speculation control settings for CVE-2017-5754 [rogue data cache load]
 
Hardware requires kernel VA shadowing: True
Windows OS support for kernel VA shadow is present: True
Windows OS support for kernel VA shadow is enabled: True
Windows OS support for PCID performance optimization is enabled: True [not required for security]
 
Speculation control settings for CVE-2018-3639 [speculative store bypass]
 
Hardware is vulnerable to speculative store bypass: True
Hardware support for speculative store bypass disable is present: True
Windows OS support for speculative store bypass disable is present: True
Windows OS support for speculative store bypass disable is enabled system-wide: False
 
Speculation control settings for CVE-2018-3620 [L1 terminal fault]
 
Hardware is vulnerable to L1 terminal fault: True
Windows OS support for L1 terminal fault mitigation is present: True
Windows OS support for L1 terminal fault mitigation is enabled: True
 

BTIHardwarePresent : True
BTIWindowsSupportPresent : True
BTIWindowsSupportEnabled : True
BTIDisabledBySystemPolicy : False
BTIDisabledByNoHardwareSupport : False
BTIKernelRetpolineEnabled : True
BTIKernelImportOptimizationEnabled : True
KVAShadowRequired : True
KVAShadowWindowsSupportPresent : True
KVAShadowWindowsSupportEnabled : True
KVAShadowPcidEnabled : True
SSBDWindowsSupportPresent : True
SSBDHardwareVulnerable : True
SSBDHardwarePresent : True
SSBDWindowsSupportEnabledSystemWide : False
L1TFHardwareVulnerable : True
L1TFWindowsSupportPresent : True
L1TFWindowsSupportEnabled : True
L1TFInvalidPteBit : 45
L1DFlushSupported : True
 
 

Retpoline can be activated at least for Sandy Bridge, Ivy Bridge and Haswell- possibly for more, but these are the only platforms I can check.
Haswell-E core i5-4460, built in graphics.

haswell all deactivated.jpg

haswell retpoline not active.jpg

haswell retpoline active2.jpg

A little disappointing, but maybe it is not the right benchmark. Just curious and had too much time
Maybe I'll try Sandy Bridge and Ivy Bridge later...

And:
"If it's desirable to enable additional security mitigations on top of Retpoline, then the feature settings values for those features need to be bitwise OR'd into FeatureSettingsOverride and FeatureSettingsOverrideMask" [source] That would mean that you'd have to add the former values for the registry keys to the values named in the post above.