Home
%3CLINGO-SUB%20id%3D%22lingo-sub-376294%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-376294%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20Windows%201809%20(RS5%2FServer%202019)%2C%20retpoline%20and%20import%20optimization%20are%20disabled%20if%20HVCI%20(DeviceGuard)%20is%20enabled.%20This%20restriction%20is%20eliminated%20in%2019H1%20(Spring%202019)%20release%20where%20retpoline%2Fimport%20optimization%20can%20coexist%20with%20DeviceGuard.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-369358%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369358%22%20slang%3D%22en-US%22%3E%3CP%3Eit%20seems%20retpoline%20and%20import%20optimizations%20are%20not%20compatible%20with%20virtualization%20based%20security(vbs)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-364630%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-364630%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F67014%22%20target%3D%22_blank%22%3E%40Inari%20Okami%3C%2FA%3E%26nbsp%3BI%20also%20had%20this%20issue%20testing%20CPUs%20Sandybridge%20-%20Haswell%26nbsp%3B%20so%20you're%20not%20alone%2C%20even%20March%20CU%20doesn't%20seem%20to%20address%20the%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20it%20does%20seem%20to%20work%20for%20the%20most%20part%20in%2019H1%2C%2019H2%20or%2020H1.%20It's%20likely%20they%20are%20still%20working%20on%20ironing%20out%20issues%20before%20releasing%20it%20to%20everyone.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-363454%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-363454%22%20slang%3D%22en-US%22%3EIt%20looks%20like%20Retpoline%20and%20Import%20Optimization%20are%20completely%20incompatible%20with%20Hyper-V%2C%20even%20when%20forced.%20Is%20this%20intentional%3F%20Will%20Windows%2010%2019H1%20have%20the%20same%20massive%20limitation%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-361323%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361323%22%20slang%3D%22en-US%22%3E%3CP%3ERetpoline%20is%20a%20way%20of%20optimising%20variant%202%20mitigation%E2%80%99s.%20SSBD%20is%20a%20different%20Spectre%20class%20vulnerability.%20Mitigation%20for%20SSBD%20is%20not%20enabled%20by%20default.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-361319%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361319%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294307%22%20target%3D%22_blank%22%3E%40rebootit%3C%2FA%3E%3C%2FP%3E%3CP%3EI'm%20confused%2C%20Do%20I%20need%20to%20enable%26nbsp%3BSSBD%3F%20Or%20is%20it%20disabled%20by%20default%3F%3C%2FP%3E%3CP%3EI%20don't%20remember%20what%20was%20the%20original%20entries%20in%20the%20registry%20because%20I%20changed%20them%20to%20disable%20the%20original%20patch%208%20months%20ago.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-361065%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361065%22%20slang%3D%22en-US%22%3E%3CP%3EPlease%20note%20that%20the%20Intel%20whitepaper%20%22Retpoline%3A%20A%20Branch%20Target%20Injection%20Mitigation%22%20%3CA%20href%3D%22https%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Fapi-app%2Fsites%2Fdefault%2Ffiles%2FRetpoline-A-Branch-Target-Injection-Mitigation.pdf%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Fapi-app%2Fsites%2Fdefault%2Ffiles%2FRetpoline-A-Branch-Target-Injection-Mitigation.pdf%3C%2FA%3E%26nbsp%3Bhas%20been%20superseded%20by%20%22Deep%20Dive%3A%20Retpoline%3A%20A%20Branch%20Target%20Injection%20Mitigation%22%20%3CA%20href%3D%22https%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Finsights%2Fdeep-dive-retpoline-branch-target-injection-mitigation%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Finsights%2Fdeep-dive-retpoline-branch-target-injection-mitigation%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-361010%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361010%22%20slang%3D%22en-US%22%3Ethanks%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294307%22%20target%3D%22_blank%22%3E%40rebootit%3C%2FA%3E%2C%20it%20all%20went%20well%20%3A)%3C%2Fimg%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360943%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360943%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F295862%22%20target%3D%22_blank%22%3E%40groviglio%3C%2FA%3E%26nbsp%3BThis%20has%20been%20answered%20%3CA%20href%3D%22https%3A%2F%2Fwww.bleepingcomputer.com%2Fnews%2Fsecurity%2Fboost-windows-10-performance-with-retpoline-spectre-mitigation%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20If%20you%20require%20additional%20protections%20then%20bitwise%20add%20the%20previous%20values%20for%20enable%20SSBD%2C%20Spectre%20v2%20and%20Meltdown%20(8)%2C%20disable%20Spectre%20v2%20and%20Meltdown%20(3)%2C%20disable%20Spectre%20v2%20only%20(2)%20and%20disable%20Meltdown%20only%20(1).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20can%20confirm%20as%20I%20had%20registry%20settings%20of%208%20(and%20a%20mask%20of%203)%20when%20upgrading%20to%2018346%20(via%2018343)%20I%20have%20the%20retpoline%20enabled%20according%20to%20the%20PowerShell%20script%20without%20having%20to%20modify%20the%20registry.%20FWIW%20I%20have%20hardware%20uCode%20and%20a%20Broadwell%20i7-5500U.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20registry%20has%20remained%20unchanged%20but%20all%20protections%20and%20optimisations%20are%20present.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360910%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360910%22%20slang%3D%22en-US%22%3E%3CP%3E%40jessecook%20My%2018845%20has%20this%20enabled%20already%2C%20according%20to%20the%20PS%20module.%20I%20didn't%20touch%20the%20Registry.%20Unclear%20if%20it's%20all%2020H1%20or%20phased.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360832%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360832%22%20slang%3D%22en-US%22%3Ei%20have%20a%20intel%20broadwell(NUC).%20i%20am%2C%20till%20now%2C%20fully%20patched%20(firmware%2BOS(W10%201809)).%20powershell%20script%20outputs%2C%20smooth%20as%20silk%2C%20all%20%22trues%22%20(in%20the%20right%20places)%20i%20was%20waiting%2C%20with%20anxiety%2C%20for%20these%20new%20settings%20for%20retpoline%3A%20well%2C%20i%20applied%20those%20and...they%20destroy%20the%20protection%20for%20SSB(CVE-2018-3639).%20because%20retpoline%20and%20SSB%20keys%20in%20the%20registry%20are%20the%20same%3A%20FeatureSettingsOverride%20and%20FeatureSettingsOverrideMask%20these%20two%20keys%20are%20set%20to%20%228%22%20and%20%223%22%20to%20have%20all%20%22trues%22%20at%20SSB%20section%20of%20powershell%20script%20output%20if%20you%20set%20both%20keys%20to%20%22400%22%20%2Cas%20you%20need%20to%20cover%20retpoline%2C%20you%20disrupt%20protection%20for%20SSB%20(that%20is%20not%20%22true%22%20anymore%20in%20powershell%20script)%20how%20to%20solve%3F%20these%20are%20two%20screenshots%20with%20the%20output%20of%20powershell%20script%2C%20the%20first%20with%20%228%22%20and%20%223%22%20inside%20%22FeatureSettingsOverride%22%20and%20%22FeatureSettingsOverrideMask%22%20keys.%20the%20second%20with%20%22400%22%20and%20%22400%22%20note%20the%20variations%20of%20%22true%22%20and%20%22false%22%20across%20the%20sections%20of%20powershell%20script%20outputs%20%3CA%20href%3D%22https%3A%2F%2Fimgur.com%2Fa%2FfWB9Hzj%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fimgur.com%2Fa%2FfWB9Hzj%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359505%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359505%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294307%22%20target%3D%22_blank%22%3E%40rebootit%3C%2FA%3E%26nbsp%3BIt%20comes%20disabled%2C%20even%20though%20support%20was%20added%20indeed.%20It%20specifically%20says%20that%20it%20will%20be%20enabled%20via%20%22cloud%20configuration%22%20over%20the%20next%20months.%20For%20the%20next%20feature%20update%20it%20should%20come%20as%20enabled%20by%20default.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359462%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359462%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F233284%22%20target%3D%22_blank%22%3E%40Brok3n%20Cogniti0n%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294001%22%20target%3D%22_blank%22%3E%40boktai1000%3C%2FA%3E%26nbsp%3Bwith%2017763.348%20you%20should%20have%20retpoline%20enabled%2C%20it%20specifically%20adds%20support%20to%201809.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20cannot%20verify%20as%20I%20am%20running%2019H1%20but%20perhaps%20Retpoline%20is%20only%20enabled%20with%20Spectre%20protections%20enabled%2C%20you%20should%20check%20out%20how%20to%20enable%20them%20on%20client%20systems%20(you%20may%20need%20KB4465065%20and%20registry%20settings%20changes%20as%20outlined%20in%20MS%20ADV18002)%20if%20your%20machine%20does%20not%20have%20hardware%20microcode.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKB4465065%20is%20a%20standalone%20update%20and%20not%20delivered%20by%20WU.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359428%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359428%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294001%22%20target%3D%22_blank%22%3E%40boktai1000%3C%2FA%3E%26nbsp%3BSame%20output%20for%20me.%20I%20guess%20we%20gonna%20have%20to%20wait%20and%20see%20how%20those%20Microsoft%20could%20config%20works.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359427%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359427%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F233284%22%20target%3D%22_blank%22%3E%40Brok3n%20Cogniti0n%3C%2FA%3E-%20I%20do%20see%20that%20you're%20absolutely%20right!%20I%20completely%20overlooked%20that%2C%20so%20my%20apologies%20for%20potentially%20confusing%20people%20by%20my%20comment.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20see%20BTIKernelRetpolineEnabled%20in%20the%20output%2C%20which%20for%20me%20listed%20as%20False%20-%20which%20lines%20up%20with%20what%20you're%20saying.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20taking%20the%20time%20to%20reply%20to%20me%20on%20this!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359424%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359424%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294001%22%20target%3D%22_blank%22%3E%40boktai1000%3C%2FA%3E%26nbsp%3BThe%20PS%20script%20does%20include%20Retpoline%2C%20if%20updated%20to%20the%20last%20version.%20I%20don't%20think%20it's%20Enabled%20yet%3A%3C%2FP%3E%3CP%3E%22%3CSPAN%3EOver%20the%20coming%20months%2C%20we%20will%20enable%20Retpoline%20as%20part%20of%20phased%20rollout%20via%20cloud%20configuration.%3C%2FSPAN%3E%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359290%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359290%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20wondering%20about%20Retpoline%20as%20well.%20I'm%20currently%20running%20Windows%2010%201809%20with%20March%201%2C%202019%E2%80%94KB4482887%20(OS%20Build%2017763.348)%20installed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20then%20went%20and%20installed%20the%20latest%20version%20of%26nbsp%3BGet-SpeculationControlSettings%20at%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4074629%2Funderstanding-the-output-of-get-speculationcontrolsettings-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4074629%2Funderstanding-the-output-of-get-speculationcontrolsettings-powershell%3C%2FA%3E%20as%20per%20the%20article%20here%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FWindows-Kernel-Internals%2FMitigating-Spectre-variant-2-with-Retpoline-on-Windows%2Fba-p%2F295618%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FWindows-Kernel-Internals%2FMitigating-Spectre-variant-2-with-Retpoline-on-Windows%2Fba-p%2F295618%3C%2FA%3E%20which%20states%20%22To%20check%20if%20retpoline%20and%20import%20optimizations%20are%20enabled%2C%20you%20can%20use%20the%20PowerShell%20cmdlet%20Get-SpeculationControlSettings.%20You%20can%20also%20use%20NtQuerySystemInformation%20to%20programmatically%20query%20retpoline%20status.%22%3CBR%20%2F%3E%3CBR%20%2F%3EUnfortuantely%20I%20do%20not%20know%20how%20to%20programmatically%20query%20the%20retpoline%20status%2C%20but%20I%20would%20do%20so%20if%20I%20knew%20how.%20I%20have%20run%20the%20Get-SpeculationControlSettings%20in%20the%20past%20though%2C%20and%20it%20seems%20that%20expected%20behavior%20is%20supposed%20to%20include%20checking%20for%20Retpoline%20status.%20Maybe%20the%20Powershell%20cmdlet%20has%20not%20been%20updated%20to%20reflect%20this%2C%20but%20that%20isn't%20entirely%20clear.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20running%20on%20an%20i7-4790K%20so%20I%20believe%20to%20be%20impacted%20by%20Retpoline%20and%20am%20curious%20to%20understand%20more.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359261%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359261%22%20slang%3D%22en-US%22%3E%3CP%3ECould%20you%20please%20explain%20how%20to%20tell%20if%20retpoline%20is%20enabled%3F%20You%20mentioned%20the%20powershell%20command%2C%20but%20I%20don't%20see%20anything%20in%20the%20results%20related%20to%20retpoline%20or%20it%20is%20not%20obvious%20to%20me%20which%20of%20the%20results%20relate%20to%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*EDIT*%20Nevermind%2C%20apparently%20the%20Skip%20Ahead%2020H1%20builds%20do%20not%20include%20it%20yet%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-298022%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-298022%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22js-tweet-text-container%22%3E%3CP%20class%3D%22TweetTextSize%20TweetTextSize--jumbo%20js-tweet-text%20tweet-text%22%3EThanks.%20Will%20this%20be%20back-ported%20to%20Windows%20Server%202019%20at%20some%20point%20in%202019%3F%20and%20if%20not%2C%20should%20we%20just%20accept%20to%20be%20running%20a%20none-optimized%20OS%20for%20a%20few%20years%20if%20we%20want%20a%20server%20OS%20with%20desktop%20experience%20installed%3F%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22js-tweet-details-fixer%20tweet-details-fixer%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-296972%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-296972%22%20slang%3D%22en-US%22%3E%3CP%3EAny%20chance%20we%20see%20this%20in%201809%3F%20If%20not%2C%20when%20do%20you%20expect%2019H1%20to%20ship%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-458243%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-458243%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F249033%22%20target%3D%22_blank%22%3E%40Mehmet_Iyigun%3C%2FA%3E10.0.18362.53%2C%20Import%20Optimization%20is%20still%20off%20whenever%20HVCI%20is%20on.%20Retpoline%20says%20it's%20working%2C%20though.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295618%22%20slang%3D%22en-US%22%3EMitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295618%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EUpdated%20May%2014%2C%202019%3A%3C%2FSTRONG%3E%20%26nbsp%3BWe're%20happy%20to%20announce%20that%20today%20we've%20updated%20Retpoline%20cloud%20configuration%20to%20enable%20it%20for%20all%20supported%20devices!*%20In%20addition%2C%20with%20the%20May%2014%20Patch%20Tuesday%20update%2C%20we've%20removed%20the%20dependence%20on%20cloud%20configuration%20such%20that%20even%20those%20customers%20who%20may%20not%20be%20receiving%20cloud%20configuration%20updates%20can%20experience%20Retpoline%20performance%20gains.%20%3CBR%20%2F%3E%3CBR%20%2F%3E*Note%3A%20Retpoline%20is%20enabled%20by%20default%20on%20devices%20running%20Windows%2010%2C%20version%201809%20and%20Windows%20Server%202019%20or%20newer%20%3CI%3Eand%3C%2FI%3E%20which%20meet%20the%20following%20conditions%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESpectre%2C%20Variant%202%20(%3CA%20href%3D%22https%3A%2F%2Fportal.msrc.microsoft.com%2Fen-us%2Fsecurity-guidance%2Fadvisory%2Fadv180002%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECVE-2017-5715%3C%2FA%3E)%20mitigation%20is%20enabled.%3CUL%3E%0A%3CLI%3EFor%20Client%20SKUs%2C%20Spectre%20Variant%202%20mitigation%20is%20%3CU%3Eenabled%3C%2FU%3E%20by%20default%3C%2FLI%3E%0A%3CLI%3EFor%20Server%20SKUs%2C%20Spectre%20Variant%202%20mitigation%20is%20%3CU%3Edisabled%3C%2FU%3E%20by%20default.%20To%20realize%20the%20benefits%20of%20Retpoline%2C%20IT%20Admins%20can%20enable%20it%20on%20servers%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4072698%2Fwindows-server-speculative-execution-side-channel-vulnerabilities-prot%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Efollowing%20this%20guidance%3C%2FA%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3ESupported%20microcode%2Ffirmware%20updates%20are%20applied%20to%20the%20machine.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EUpdated%20March%201%2C%202019%3A%3C%2FSTRONG%3E%20%26nbsp%3BThe%20post%20below%20outlines%20the%20performance%20benefits%20of%20using%20Retpoline%20against%20the%20Spectre%20variant%202%20(CVE-2017-5715)%20attack%E2%80%94as%20observed%20with%2064-bit%20Windows%20Insider%20Preview%20Builds%2018272%20and%20later.%20%3CDEL%3EWhile%20Retpoline%20is%20currently%20disabled%20by%20default%20on%20production%20Windows%2010%20client%20devices%3C%2FDEL%3E%2C%20we%20have%20backported%20the%20OS%20modifications%20needed%20to%20support%20Retpoline%20so%20that%20it%20can%20be%20used%20with%20Windows%2010%2C%20version%201809%20and%20have%20those%20modifications%20in%20the%20March%201%2C%202019%20update%20(%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4482887%2Fwindows-10-update-kb4482887%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EKB4482887%3C%2FA%3E).%3CBR%20%2F%3E%3CBR%20%2F%3E%3CDEL%3EOver%20the%20coming%20months%2C%20we%20will%20enable%20Retpoline%20as%20part%20of%20phased%20rollout%20via%20cloud%20configuration.%3C%2FDEL%3E%20Due%20to%20the%20complexity%20of%20the%20implementation%20and%20changes%20involved%2C%20we%20are%20only%20enabling%20Retpoline%20performance%20benefits%20for%20Windows%2010%2C%20version%201809%20and%20later%20releases.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EUpdated%20March%205%2C%202019%3A%3C%2FSTRONG%3E%20%26nbsp%3B%20%3CDEL%3EWhile%20the%20phased%20rollout%20is%20in%20progress%2C%20customers%20who%20would%20like%20to%20manually%20enable%20Retpoline%20on%20their%20machines%20can%20do%20so%20with%20the%20following%20registry%20configuration%20updates%3A%3C%2FDEL%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOn%20Client%20SKUs%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3Ereg%20add%20%22HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CMemory%20Management%22%20%2Fv%20FeatureSettingsOverride%20%2Ft%20REG_DWORD%20%2Fd%200x400%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereg%20add%20%22HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CMemory%20Management%22%20%2Fv%20FeatureSettingsOverrideMask%20%2Ft%20REG_DWORD%20%2Fd%200x400%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3EReboot%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EOn%20Server%20SKUs%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3Ereg%20add%20%22HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CMemory%20Management%22%20%2Fv%20FeatureSettingsOverride%20%2Ft%20REG_DWORD%20%2Fd%200x400%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereg%20add%20%22HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CSession%20Manager%5CMemory%20Management%22%20%2Fv%20FeatureSettingsOverrideMask%20%2Ft%20REG_DWORD%20%2Fd%200x401%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3EReboot%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%3A%20The%20above%20registry%20configurations%20are%20for%20customers%20running%20with%20default%20mitigation%20settings.%20In%20particular%2C%20for%20Server%20SKUs%2C%20these%20settings%20will%20enable%20Spectre%20variant%202%20mitigations%20(which%20are%20enabled%20by%20default%20on%20Client%20SKUs).%20If%20it's%20desirable%20to%20enable%20additional%20security%20mitigations%20on%20top%20of%20Retpoline%2C%20then%20the%20feature%20settings%20values%20for%20those%20features%20need%20to%20be%20bitwise%20OR'd%20into%20FeatureSettingsOverride%20and%20FeatureSettingsOverrideMask.%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3EExample%3A%20%3C%2FSTRONG%3EFeature%20settings%20values%20for%20enabling%20SSBD%20(speculative%20store%20bypass)%20system%20wide%3A%3CBR%20%2F%3EFeatureSettingsOverride%20%3D%200x8%20and%20FeatureSettingsOverrideMask%20%3D%200%3CBR%20%2F%3ETo%20add%20Retpoline%2C%20feature%20settings%20value%20for%20Retpoline%20(0x400)%20should%20be%20bitwise%20OR'd%3A%3CBR%20%2F%3EFeatureSettingsOverride%20%3D%200x408%20and%20FeatureSettings%20OverrideMask%20%3D%200x400%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2FSpeculationControl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet-SpeculationControlSettings%20PowerShell%20cmdlet%3C%2FA%3E%20can%20be%20used%20to%20verify%20Retpoline%20status.%20Here%E2%80%99s%20an%20example%20output%20showing%20Retpoline%20and%20import%20optimization%20enabled%3A%3C%2FP%3E%0A%3CPRE%3ESpeculation%20control%20settings%20for%20CVE-2017-5715%20%5Bbranch%20target%20injection%5D%20%0A%E2%80%AF%0AHardware%20support%20for%20branch%20target%20injection%20mitigation%20is%20present%3A%20True%20%20%0AWindows%20OS%20support%20for%20branch%20target%20injection%20mitigation%20is%20present%3A%20True%20%0AWindows%20OS%20support%20for%20branch%20target%20injection%20mitigation%20is%20enabled%3A%20True%20%0A%E2%80%A6%20%0ABTIKernelRetpolineEnabled%20%20%20%20%20%20%20%20%20%20%20%3A%20True%20%0ABTIKernelImportOptimizationEnabled%20%20%3A%20True%20%0A...%0A%3C%2FPRE%3E%0A%3CP%3ESince%20Retpoline%20is%20a%20performance%20optimization%20for%20Spectre%20Variant%202%2C%20it%20requires%20that%20hardware%20and%20OS%20support%20for%20branch%20target%20injection%20to%20be%20present%20and%20enabled.%20Skylake%20and%20later%20generations%20of%20Intel%20processors%20%3CA%20href%3D%22https%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Finsights%2Fdeep-dive-retpoline-branch-target-injection-mitigation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eare%20not%20compatible%20with%20Retpoline%3C%2FA%3E%2C%20so%20only%20Import%20Optimization%20will%20be%20enabled%20on%20these%20processors.%3C%2FP%3E%0A%3CHR%20%2F%3E%0A%3CP%3EIn%20January%202018%2C%20Microsoft%20released%20%3CA%20href%3D%22https%3A%2F%2Fportal.msrc.microsoft.com%2Fen-US%2Fsecurity-guidance%2Fadvisory%2FADV180002%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ean%20advisory%20and%20security%20updates%3C%2FA%3E%20related%20to%20a%20newly%20discovered%20class%20of%20hardware%20vulnerabilities%20involving%20speculative%20execution%20side%20channels%20(known%20as%20Spectre%20and%20Meltdown)%20that%20affect%20AMD%2C%20ARM%2C%20and%20Intel%20CPUs%20to%20varying%20degrees.%20If%20you%20haven%E2%80%99t%20had%20a%20chance%20to%20learn%20about%20these%20issues%2C%20we%20recommend%20watching%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_4O0zMW-Zu4%26amp%3Bfeature%3Dyoutu.be%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EThe%20Case%20of%20Spectre%20and%20Meltdown%3C%2FA%3E%20by%20the%20team%20at%20TU%20Graz%20from%20%3CA%20href%3D%22http%3A%2F%2Fwww.bluehatil.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EBlueHat%20Israel%3C%2FA%3E%2C%20reading%20the%20%3CA%20href%3D%22https%3A%2F%2Fgoogleprojectzero.blogspot.com%2F2018%2F01%2Freading-privileged-memory-with-side.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eblog%20post%3C%2FA%3E%20by%20Jann%20Horn%20(%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Ftehjh%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%40tehjh%3C%2FA%3E)%20of%20Google%20Project%20Zero.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20have%20also%20had%20multiple%20posts%20detailing%20the%20internals%20of%20our%20implementation%20to%20handle%20these%20side-channel%20attacks.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsrd%2F2018%2F03%2F15%2Fmitigating-speculative-execution-side-channel-hardware-vulnerabilities%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMitigating%20speculative%20execution%20side%20channel%20hardware%20vulnerabilities%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsrd%2F2018%2F03%2F23%2Fkva-shadow-mitigating-meltdown-on-windows%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EKVA%20Shadow%3A%20Mitigating%20Meltdown%20on%20Windows%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsrd%2F2018%2F08%2F14%2Fanalysis-and-mitigation-of-l1-terminal-fault-l1tf%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAnalysis%20and%20mitigation%20of%20L1%20Terminal%20Fault%20(L1TF)%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EFor%20today%E2%80%99s%20post%2C%20we%20have%20kernel%20developers%20%3CSTRONG%3EAndrea%20Allievi%3C%2FSTRONG%3E%20and%20%3CSTRONG%3EChris%20Kleynhans%3C%2FSTRONG%3E%20describing%20our%20design%20and%20implementation%20of%20%3CSTRONG%3Eretpoline%20for%20Windows%20%3C%2FSTRONG%3Ewhich%20improves%20performance%20of%20Spectre%20variant%202%20mitigations%20(CVE-2017-5715)%20to%20noise-level%20for%20most%20scenarios.%20These%20improvements%20are%20available%20today%20in%20%3CSTRONG%3EWindows%20Insider%20Builds%20%3C%2FSTRONG%3E(builds%2018272%20or%20newer%2C%20x64-only).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1703754733%22%20id%3D%22toc-hId-1703754733%22%20id%3D%22toc-hId-1703754733%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EAt%20a%20high%20level%2C%20the%20Spectre%20variant%202%20attack%20exploits%20indirect%20branches%20to%20steal%20secrets%20located%20in%20higher%20privilege%20contexts%20(e.g.%20kernel-mode%20vs%20user-mode).%20Indirect%20branches%20are%20instructions%20where%20the%20target%20of%20the%20branch%20is%20not%20contained%20in%20the%20instruction%20itself%2C%20such%20as%20when%20the%20destination%20address%20is%20stored%20in%20a%20CPU%20register.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDescribing%20the%20full%20Spectre%20attack%20is%20outside%20the%20scope%20of%20this%20article.%20Details%20are%20in%20the%20links%20above%20or%20in%20this%20%3CA%20href%3D%22https%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Fapi-app%2Fsites%2Fdefault%2Ffiles%2FRetpoline-A-Branch-Target-Injection-Mitigation.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewhitepaper%3C%2FA%3E%20from%20Intel.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOur%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fsrd%2F2018%2F03%2F15%2Fmitigating-speculative-execution-side-channel-hardware-vulnerabilities%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eoriginal%20mitigations%3C%2FA%3E%20for%20Spectre%20variant%202%20made%20use%20of%20new%20capabilities%20exposed%20by%20CPU%20microcode%20updates%20to%20restrict%20indirect%20branch%20speculation%20when%20executing%20within%20kernel%20mode%20(IBRS%20and%20IBPB).%20While%20this%20was%20an%20effective%20mitigation%20from%20a%20security%20standpoint%2C%20it%20resulted%20in%20a%20larger%20performance%20degradation%20than%20we%E2%80%99d%20like%20on%20certain%20processors%20and%20workloads.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20reason%2C%20starting%20in%20early%202018%2C%20we%20investigated%20alternatives%20and%20found%20promise%20in%20an%20approach%20developed%20by%20Google%20called%20retpoline.%20A%20full%20description%20of%20retpoline%20can%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fsupport.google.com%2Ffaqs%2Fanswer%2F7625886%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%2C%20but%20in%20short%2C%20retpoline%20works%20by%20replacing%20all%20indirect%20call%20or%20jumps%20in%20kernel-mode%20binaries%20with%20an%20indirect%20branch%20sequence%20that%20has%20safe%20speculation%20behavior.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20sequence%2C%20shown%20below%20in%20Figure%201%2C%20effects%20a%20safe%20control%20transfer%20to%20the%20target%20address%20by%20performing%20a%20function%20call%2C%20modifying%20the%20return%20address%20and%20then%20returning.%3C%2FP%3E%0A%3CPRE%3ERP0%3A%20%20call%20RP2%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20push%20address%20of%20RP1%20onto%20the%20stack%20and%20jump%20to%20RP2%0ARP1%3A%20%20int%203%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20breakpoint%20to%20capture%20speculation%0ARP2%3A%20%20mov%20%5Brsp%5D%2C%20%26lt%3BJump%20Target%26gt%3B%20%3B%20overwrite%20return%20address%20on%20the%20stack%20to%20desired%20target%0ARP3%3A%20%20ret%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20return%3C%2FPRE%3E%0A%3CP%3EWhile%20this%20construct%20is%20not%20as%20fast%20as%20a%20regular%20indirect%20call%20or%20jump%2C%20it%20has%20the%20side%20effect%20of%20preventing%20the%20processor%20from%20unsafe%20speculative%20execution.%20This%20proves%20to%20be%20much%20faster%20than%20running%20all%20of%20kernel%20mode%20code%20with%20branch%20speculation%20restricted%20(IBRS%20set%20to%201).%20However%2C%20this%20construct%20is%20only%20safe%20to%20use%20on%20processors%20where%20the%20RET%20instruction%20does%20not%20speculate%20based%20on%20the%20contents%20of%20the%20indirect%20branch%20predictor.%20Those%20processors%20are%20all%20AMD%20processors%20as%20well%20as%20Intel%20processors%20codenamed%20Broadwell%20and%20earlier%20according%20to%20Intel%E2%80%99s%20%3CA%20href%3D%22https%3A%2F%2Fsoftware.intel.com%2Fsecurity-software-guidance%2Fapi-app%2Fsites%2Fdefault%2Ffiles%2FRetpoline-A-Branch-Target-Injection-Mitigation.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewhitepaper%3C%2FA%3E.%20Retpoline%20is%20not%20applicable%20to%20Skylake%20and%20later%20processors%20from%20Intel.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1044915733%22%20id%3D%22toc-hId--1044915733%22%20id%3D%22toc-hId--1044915733%22%3EWindows%20requirements%20for%20Retpoline%3C%2FH3%3E%0A%3CP%3ETraditionally%20the%20transformation%20of%20indirect%20calls%20and%20jumps%20into%20retpolines%20is%20performed%20when%20a%20binary%20is%20built%20by%20the%20compiler.%20However%2C%20there%20are%20several%20functional%20requirements%20in%20Windows%20that%20make%20a%20purely%20compile-time%20implementation%20insufficient.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20key%20requirements%20are%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ESingle%20binary%3C%2FSTRONG%3E%3A%20Windows%20releases%20are%20long-lived%20and%20must%20support%20a%20wide%20variety%20of%20hardware%20with%20a%20single%20set%20of%20binaries.%20On%20some%20hardware%20retpoline%20is%20not%20a%20complete%20mitigation%20because%20of%20alternate%20behavior%20of%20the%20ret%20instruction%20and%20retpoline%20must%20not%20be%20used.%20Further%2C%20future%20hardware%20may%20eliminate%20the%20need%20for%20retpoline%20entirely.%20Therefore%2C%20a%20Windows%20implementation%20of%20retpoline%20must%20allow%20the%20feature%20to%20be%20enabled%20and%20disabled%20at%20boot%20time%20using%20a%20single%20set%20of%20binaries%2C%20based%20on%20whether%20the%20underlying%20hardware%20is%20vulnerable%2C%20compatible%20and%20whether%20Spectre%20variant%202%20mitigations%20are%20enabled%20on%20the%20system.%20Further%2C%20the%20runtime%20overhead%20of%20retpoline%20support%20should%20be%20minimal%20when%20the%20feature%20is%20disabled.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E3rd%20party%20device%20drivers%3C%2FSTRONG%3E%3A%20A%20lot%20of%20the%20code%20that%20runs%20in%20kernel%20mode%20is%20not%20part%20of%20Windows%20and%20consists%20of%203rd%20party%20device%20driver%20code.%20Traditional%20retpoline%20would%20only%20be%20secure%20if%20all%20these%20drivers%20were%20recompiled%20with%20a%20new%20version%20of%20the%20compiler.%20Given%20the%20breadth%20of%20Windows%203rd%20party%20driver%20ecosystem%2C%20it%20is%20not%20realistic%20to%20expect%20all%20non-inbox%203rd%20party%20drivers%20to%20be%20recompiled%20and%20released%20to%20customers%20at%20the%20same%20time.%20Therefore%2C%20a%20Windows%20implementation%20of%20retpoline%20must%20be%20able%20to%20support%20a%20mixed%20environment%2C%20providing%20high%20performance%20when%20running%20drivers%20that%20have%20been%20updated%2C%20but%20allowing%20for%20graceful%20fallback%20to%20hardware-based%20mitigations%20upon%20entering%20a%20non-retpoline%20driver%20to%20preserve%20security.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EDriver%20portability%3C%2FSTRONG%3E%3A%20Windows%20drivers%20are%20not%20bound%20to%20a%20specific%20release%20of%20Windows%2C%20many%20drivers%20that%20are%20built%20today%20for%20Windows%2010%20will%20also%20support%20older%20versions%20of%20the%20operating%20system.%20Therefore%2C%20a%20Windows%20implementation%20of%20retpoline%20must%20ensure%20that%20drivers%20compiled%20with%20retpoline%20support%20can%20run%20on%20a%20version%20of%20Windows%20that%20does%20not%20support%20retpoline.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-894408107%22%20id%3D%22toc-hId-894408107%22%20id%3D%22toc-hId-894408107%22%3EGeneral%20Architecture%3C%2FH2%3E%0A%3CP%3ETo%20satisfy%20requirement%201%20and%203%2C%20we%20decided%20that%20binaries%20would%20ship%20in%20a%20non-retpolined%20state%20and%20then%20be%20transformed%20into%20a%20retpolined%20state%20by%20rewriting%20the%20code%20sequences%20for%20all%20indirect%20calls.%20This%20ensures%20that%20systems%20that%20do%20not%20use%20retpoline%20can%20use%20the%20binaries%20as%20compiled%20without%20needing%20any%20support%20for%20retpoline%20and%20with%20minimal%20runtime%20cost.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20performing%20the%20transformation%20at%20runtime%20does%20lead%20to%20one%20problem.%20How%20do%20we%20know%20what%20transformations%20need%20to%20be%20applied%3F%20Disassembling%20and%20analyzing%20driver%20machine%20code%20to%20locate%20all%20indirect%20calls%20is%20not%20practical.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1854262359%22%20id%3D%22toc-hId--1854262359%22%20id%3D%22toc-hId--1854262359%22%3EDynamic%20Value%20Relocation%20Table%20(DVRT)%3C%2FH3%3E%0A%3CP%3ETo%20solve%20this%20problem%2C%20we%20collaborated%20with%20the%20compiler%20team%20in%20Visual%20Studio%20to%20develop%20a%20system%20whereby%20the%20compiler%20can%20emit%20a%20new%20type%20of%20metadata%20into%20driver%20binaries%20describing%20each%20indirect%20call%20or%20jump%20in%20the%20system.%20This%20metadata%20takes%20the%20form%20of%20new%20relocation%20entries%20in%20the%20Dynamic%20Value%20Relocation%20Table%20(DVRT).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20DVRT%20was%20originally%20introduced%20back%20in%20the%20Windows%2010%20Creators%20Update%20to%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2FMSRC-Security-Research%2Fblob%2Fmaster%2Fpresentations%2F2016_08_BlackHatUSA%2FBHUSA16_Weston_Miller_Windows_10_Mitigation_Improvements.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eimprove%20kernel%20address%20space%20layout%20randomization%20(KASLR)%3C%2FA%3E.%20It%20allowed%20the%20memory%20manager%E2%80%99s%20page%20frame%20number%20(PFN)%20database%20and%20page%20table%20self-map%20to%20be%20assigned%20dynamic%20addresses%20at%20runtime.%20The%20DVRT%20is%20stored%20directly%20in%20the%20binary%20and%20contains%20a%20series%20of%20relocation%20entries%20for%20each%20symbol%20(i.e.%20address)%20that%20is%20to%20be%20relocated.%20The%20relocation%20entries%20are%20themselves%20arranged%20in%20a%20hierarchical%20fashion%20grouped%20first%20by%20symbol%20and%20then%20by%20containing%20page%20to%20allow%20for%20a%20compact%20description%20of%20all%20locations%20in%20the%20binary%20that%20reference%20a%20relocatable%20symbol.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAt%20build%20time%2C%20the%20compiler%20keeps%20track%20of%20all%20references%20to%20these%20special%20symbols%20and%20fills%20out%20the%20DVRT.%20Then%20at%20runtime%20the%20kernel%20will%20parse%20the%20DVRT%20and%20update%20each%20symbol%20reference%20with%20the%20correct%20dynamically%20assigned%20address.%20Importantly%2C%20the%20kernel%20will%20skip%20over%20any%20DVRT%20entries%20it%20does%20not%20recognize%20(i.e.%20those%20with%20an%20unknown%20symbol)%20so%20adding%20new%20symbols%20to%20the%20DVRT%20does%20not%20break%20older%20versions%20of%20Windows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThese%20properties%20meant%20the%20DVRT%20was%20a%20perfect%20place%20to%20store%20our%20retpoline%20metadata%2C%20however%20the%20existing%20DVRT%20format%20needed%20to%20be%20extended%20to%20support%20retpoline.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBased%20on%20Windows%20requirements%2C%20we%20classified%20indirect%20calls%2Fjumps%20into%20three%20distinct%20forms%20and%20each%20of%20these%20forms%20has%20its%20own%20type%20of%20retpoline%20relocation%20and%20corresponding%20runtime%20fixup.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EImport%20calls%2Fjumps%3C%2FLI%3E%0A%3CLI%3ESwitchtable%20jumps%3C%2FLI%3E%0A%3CLI%3EGeneric%20indirect%20calls%2Fjumps%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3ELet%E2%80%99s%20talk%20a%20little%20about%20each%20of%20these%20types%20of%20calls.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--307965529%22%20id%3D%22toc-hId--307965529%22%20id%3D%22toc-hId--307965529%22%3EImport%20Calls%2FJumps%3C%2FH4%3E%0A%3CP%3EImport%20calls%2Fjumps%20are%2C%20as%20the%20name%20implies%2C%20used%20for%20calls%2Fjumps%20made%20by%20a%20binary%20to%20functions%20that%20have%20been%20imported%20from%20another%20binary.%20When%20compiling%20with%20retpoline%2C%20the%20compiler%20ensures%20that%20all%20such%20calls%20conform%20to%20the%20following%20form%3A%3C%2FP%3E%0A%3CPRE%3E48%20FF%2015%20XX%20XX%20XX%20XX%20%20%20%20%20call%20qword%20ptr%20%5B_imp_%26lt%3Bfunction%26gt%3B%5D%0A0F%201F%2044%2000%2000%20%20%20%20%20%20%20%20%20%20%20nop%3C%2FPRE%3E%0A%3CP%3EThe%20call%20or%20jmp%20instruction%20always%20directly%20references%20the%20import%20address%20table%20(IAT)%20and%20has%205%20bytes%20of%20additional%20padding%20(to%20be%20used%20by%20the%20retpoline%20fixup).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1434844806%22%20id%3D%22toc-hId-1434844806%22%20id%3D%22toc-hId-1434844806%22%3ESwitchtable%20Jumps%3C%2FH4%3E%0A%3CP%3ESwitchtable%20jumps%20are%20used%20for%20jumps%20made%20to%20other%20locations%20within%20the%20same%20function%20and%20are%20so-named%20because%20of%20their%20usage%20in%20implementing%20C%2FC%2B%2B%20switch%20statements.%20When%20compiling%20with%20retpoline%20support%20the%20compiler%20ensures%20that%20such%20calls%20are%20always%20made%20through%20a%20register%20and%20take%20the%20following%20form%3A%3C%2FP%3E%0A%3CPRE%3EFF%20D0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20jmp%20rax%0ACC%20CC%20CC%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%203%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId--1117312155%22%20id%3D%22toc-hId--1117312155%22%20id%3D%22toc-hId--1117312155%22%3EGeneric%20Indirect%20Calls%2FJumps%3C%2FH4%3E%0A%3CP%3EAll%20other%20indirect%20calls%2Fjumps%20fall%20into%20the%20generic%20type.%20To%20simplify%20the%20retpoline%20relocation%20format%20and%20the%20corresponding%20fixup%20logic%2C%20the%20compiler%20ensures%20that%20all%20such%20indirect%20calls%2Fjumps%20provide%20their%20target%20address%20in%20the%20RAX%20register.%20The%20exact%20format%20of%20the%20call%2Fjump%20instruction%20however%20differs%20depending%20on%20whether%20it%20is%20protected%20by%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2FSecBP%2Fcontrol-flow-guard%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Econtrol%20flow%20guard%3C%2FA%3E%20(CFG).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1018525190%22%20id%3D%22toc-hId-1018525190%22%20id%3D%22toc-hId-1018525190%22%3ELoading%20binaries%20at%20runtime%3C%2FH2%3E%0A%3CP%3ENow%20that%20we%20have%20a%20way%20to%20identify%20all%20the%20indirect%20calls%2Fjumps%20in%20the%20binary%2C%20we%20need%20to%20apply%20the%20fixups.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20NT%20memory%20manager%20has%20long%20had%20infrastructure%20to%20apply%20fixups%20to%20binaries%20at%20runtime.%20This%20infrastructure%20was%20extended%20to%20understand%20retpoline%20relocations%20and%20their%20corresponding%20fixups.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20what%20exactly%20do%20these%20fixups%20look%20like%3F%20As%20mentioned%20earlier%2C%20the%20Windows%20implementation%20needs%20to%20support%20mixed%20environments%20in%20which%20some%20drivers%20are%20not%20compiled%20with%20retpoline%20support.%20This%20means%20that%20we%20cannot%20simply%20replace%20every%20indirect%20call%20with%20a%20retpoline%20sequence%20like%20the%20example%20shown%20in%20the%20introduction.%20We%20need%20to%20ensure%20that%20the%20kernel%20gets%20the%20opportunity%20to%20inspect%20the%20target%20of%20the%20call%20or%20jump%20so%20that%20it%20can%20apply%20appropriate%20mitigations%20if%20the%20target%20does%20not%20support%20retpoline.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20reason%2C%20we%20transform%20every%20indirect%20call%20or%20jump%20into%20a%20direct%20call%20or%20jump%20to%20a%20kernel%20provided%20%E2%80%9Cretpoline%20stub%20function%E2%80%9D.%20For%20example%2C%20an%20indirect%20call%20to%20an%20imported%20function%20that%20looks%20like%20this%3A%3C%2FP%3E%0A%3CPRE%3Ecall%20qword%20ptr%20%5B_imp_ExAllocatePoolWithTag%5D%20%20%20%20%20%3B%20Target%20address%20located%20at%20a%20REL32%20offset%0Anop%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20Padding%3C%2FPRE%3E%0A%3CP%3EWill%20be%20replaced%20at%20runtime%20with%20a%20direct%20call%20to%20the%20retpoline%20import%20stub%3A%3C%2FP%3E%0A%3CPRE%3Emov%20r10%2C%20qword%20ptr%20%5B_imp_ExAllocatePoolWithTag%5D%20%3B%20R10%20%3D%20target%20address%0Acall%20_guard_retpoline_import_r10%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20Direct%20REL32%20call%20to%20the%20stub%20function%3C%2FPRE%3E%0A%3CP%3EThere%20are%20several%20retpoline%20stub%20functions%20each%20of%20which%20is%20specialized%20to%20the%20type%20of%20call%2Fjump%20it%20handles.%20However%2C%20each%20function%20generally%20performs%20the%20following%20steps%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20target%20binary%20supports%20retpoline%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CUL%3E%0A%3CLI%3EPrior%20to%20transferring%20control%20to%20the%20target%20address%2C%20the%20function%20must%20determine%20whether%20the%20target%20address%20belongs%20to%20a%20driver%20that%20supports%20retpoline.%20To%20determine%20this%2C%20the%20kernel%20maintains%20a%20sparse%20bitmap%20of%20the%20entire%20kernel-mode%20address%20space%20with%20each%20bit%20describing%20a%2064%20KB%20region%20of%20the%20address%20space.%20Bits%20in%20this%20bitmap%20are%20set%20to%201%20if%20and%20only%20if%20their%20corresponding%20region%20of%20address%20space%20belongs%20to%20a%20kernel-mode%20binary%20that%20fully%20supports%20retpoline.%3C%2FLI%3E%0A%3CLI%3EIf%20the%20bitmap%20check%20determines%20that%20the%20target%20address%20does%20not%20belong%20to%20a%20retpolined%20binary%2C%20the%20stub%20function%20has%20to%20fall%20back%20to%20the%20hardware-based%20Spectre%20variant%202%20mitigation%20(by%20setting%20IBRS%20to%20restrict%20branch%20speculation)%20and%20then%20perform%20a%20regular%20indirect%20call%2Fjmp.%20Otherwise%2C%20the%20kernel%20does%20not%20need%20to%20set%20IBRS.%20On%20processors%20that%20do%20not%20support%20IBRS%2C%20retpoline%20will%2C%20instead%2C%20perform%20IBPB%20if%20user-to-kernel%20protection%20is%20enabled%20as%20described%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4072698%2Fwindows-server-speculative-execution-side-channel-vulnerabilities-prot%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3ESince%20the%20target%20of%20a%20switch%20table%20jump%20is%20always%20in%20the%20same%20binary%20as%20the%20source%20(and%20therefore%20the%20target%20is%20guaranteed%20to%20support%20retpoline)%2C%20this%20bitmap%20check%20is%20omitted%20from%20the%20switchtable%20jump%20stub%20functions.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CLI%3E%3CSTRONG%3ECheck%20if%20the%20target%20address%20is%20a%20valid%20CFG%20target%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CUL%3E%0A%3CLI%3EFor%20CFG%20instrumented%20indirect%20calls%2Fjumps%20the%20retpoline%20stub%20function%20is%20responsible%20for%20checking%20the%20kernel-mode%20CFG%20bitmap%20to%20verify%20that%20the%20target%20address%20given%20is%20a%20valid%20CFG%20call%20target.%20If%20this%20check%20fails%2C%20then%20the%20stub%20function%20will%20bugcheck%20the%20system%20to%20prevent%20any%20exploit%20that%20attempts%20an%20indirect%20control%20transfer%20to%20an%20invalid%20address.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CLI%3E%3CSTRONG%3ETransfer%20control%20to%20the%20target%20using%20a%20retpoline%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThe%20usage%20of%20these%20stub%20functions%20ensures%20that%20we%20can%20satisfy%20the%20requirement%20to%20support%20mixed%20environments%2C%20however%20they%20do%20introduce%20one%20additional%20problem.%20The%20x64%20direct%20call%2Fjump%20instruction%20can%20only%20encode%20a%20target%20address%20within%202%20GB%20of%20the%20call-site%20(since%20the%20target%20is%20specified%20by%20a%20signed%2016-%20or%2032-bit%20offset).%20Since%20the%20retpoline%20stub%20functions%20are%20implemented%20in%20the%20NT%20kernel%20binary%20this%20would%20generally%20mean%20that%20drivers%20would%20have%20to%20be%20loaded%20within%202%20GB%20of%20the%20kernel%20binary.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20work%20around%20this%20requirement%2C%20all%20retpoline%20stub%20functions%20are%20contained%20within%20a%20single%20section%20of%20the%20NT%20kernel%20binary%20and%20have%20been%20carefully%20written%20to%20take%20no%20dependencies%20on%20their%20position%20relative%20to%20the%20rest%20of%20the%20binary.%20This%20allows%20us%20to%20map%20the%20physical%20memory%20pages%20backing%20the%20retpoline%20stub%20functions%20immediately%20after%20every%20driver%20in%20the%20system%2C%20giving%20each%20driver%20its%20own%20%E2%80%9Ccopy%E2%80%9D%20of%20the%20retpoline%20stub%20functions%20that%20is%20%3CSTRONG%3Eguaranteed%20to%20be%20within%202%20GB%3C%2FSTRONG%3E%20of%20every%20indirect%20call%2Fjump.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1926658781%22%20id%3D%22toc-hId--1926658781%22%20id%3D%22toc-hId--1926658781%22%3EImport%20optimization%3C%2FH4%3E%0A%3CP%3EIndirect%20calls%20due%20to%20imported%20functions%20are%20by%20far%20the%20most%20common%20form%20of%20indirect%20control%20transfers%20in%20kernel-mode.%20The%20import%20call%20targets%20are%20determined%20at%20driver%20load%20time%20by%20processing%20the%20import%20address%20table%20(IAT)%20and%20remain%20constant%20throughout%20the%20driver%E2%80%99s%20lifetime.%20This%20means%20that%20most%20of%20the%20work%20provided%20by%20the%20retpoline%20import%20stub%20is%20unnecessary%20because%20we%20know%20at%20driver%20load%20time%20exactly%20where%20each%20of%20these%20calls%20will%20end%20up%20going%20and%20we%20know%20whether%20the%20target%20binary%20supports%20retpoline%20or%20not.%20Hence%2C%20we%20can%20use%20a%20much%20faster%20calling%20sequence.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20import%20optimization%2C%20we%20use%20the%20retpoline%20fixup%20infrastructure%20to%20replace%20eligible%20import%20calls%20with%20direct%20calls%20to%20the%20imported%20function.%20This%20eliminates%20the%20overhead%20of%20the%20retpoline%20import%20call%20stub%20as%20well%20as%20the%20guaranteed%20branch%20prediction%20miss%20due%20to%20retpoline%20itself.%20To%20be%20eligible%20for%20import%20optimization%2C%20a%20call%20must%20meet%20the%20following%20requirements%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EThe%20call%2Fjump%20must%20be%20from%20a%20retpolined%20binary%20to%20%3CSTRONG%3Eanother%20retpolined%20binary%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CUL%3E%0A%3CLI%3EThis%20is%20necessary%20to%20maintain%20the%20security%20guarantees%20of%20retpoline%20because%20once%20we%E2%80%99ve%20rewritten%20the%20indirect%20call%20into%20a%20direct%20call%20the%20kernel%20no%20longer%20gets%20a%20chance%20to%20observe%20the%20target%20address%20and%20enable%20IBRS.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CLI%3EThe%20target%20of%20the%20call%20must%20be%20%3CSTRONG%3Ewithin%202%20GB%3C%2FSTRONG%3E%20of%20the%20call%20site.%3C%2FLI%3E%0A%3CUL%3E%0A%3CLI%3EThis%20is%20because%20as%20mentioned%20above%20direct%20call%2Fjump%20instructions%20on%20x64%20can%20only%20encode%20a%2032-bit%20offset.%3C%2FLI%3E%0A%3CLI%3EIn%20order%20to%20virtually%20guarantee%20that%20import%20optimization%20can%20be%20applied%20all%20retpolined%20modules%2C%20the%20OS%20loader%20and%20kernel%20make%20sure%20that%20all%20kernel-mode%20modules%20are%20packed%20tightly%20in%20the%20address%20space%20while%20maintaining%20address%20space%20layout%20randomizations%20(ASLR).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FOL%3E%0A%3CP%3EHere%20is%20an%20example%20of%20how%20the%20code%20generation%20for%20the%20call%20is%20modified.%3C%2FP%3E%0A%3CP%3E%3CEM%3EOriginal%20code%20sequence%3C%2FEM%3E%3C%2FP%3E%0A%3CPRE%3Ecall%20%5B__imp_%26lt%3BFunction%26gt%3B%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20Call%20to%20an%20imported%20function%0Anop%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%205-byte%20nop%3C%2FPRE%3E%0A%3CP%3E%3CEM%3EImport%20Optimized%20code%20sequence%3C%2FEM%3E%3C%2FP%3E%0A%3CPRE%3Emov%20r10%2C%20%5B__imp_%26lt%3BFunction%26gt%3B%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20R10%20%3D%20target%20address%20(normal%20transformation)%0Acall%20%26lt%3BFunction%26gt%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3B%20Direct%20REL32%20call%20to%20target%3C%2FPRE%3E%0A%3CP%3EImport%20optimization%20turned%20out%20to%20be%20a%20%3CSTRONG%3Ebig%20performance%20win%3C%2FSTRONG%3E!%20Hence%2C%20even%20on%20processors%20where%20retpoline%20cannot%20be%20used%20due%20to%20alternate%20return%20instruction%20behavior%2C%20we%20still%20use%20import%20optimization.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-209178564%22%20id%3D%22toc-hId-209178564%22%20id%3D%22toc-hId-209178564%22%3EConclusion%3C%2FH2%3E%0A%3CP%3ERetpoline%20has%20significantly%20improved%20the%20performance%20of%20the%20Spectre%20variant%202%20mitigations%20on%20Windows.%20When%20all%20relevant%20kernel-mode%20binaries%20are%20compiled%20with%20retpoline%2C%20we%E2%80%99ve%20measured%20~25%25%20speedup%20in%20Office%20app%20launch%20times%20and%20up%20to%201.5-2x%20improved%20throughput%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fdiskspd%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDiskspd%3C%2FA%3E%20(storage)%20and%20%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2FNTttcp-Version-528-Now-f8b12769%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ENTttcp%3C%2FA%3E%20(networking)%20benchmarks%20on%20Broadwell%20CPUs%20in%20our%20lab.%20It%20is%20%3CSTRONG%3Eenabled%20by%20default%3C%2FSTRONG%3E%20in%20the%20latest%20Windows%20Client%20Insider%20Fast%20builds%20(for%20%3CSTRONG%3Ebuilds%2018272%3C%2FSTRONG%3E%20and%20higher%20on%20machines%20exposing%20compatible%20speculation%20control%20capabilities)%20and%20is%20targeted%20to%20ship%20with%2019H1.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20check%20if%20retpoline%20and%20import%20optimizations%20are%20enabled%2C%20you%20can%20use%20the%20PowerShell%20cmdlet%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4074629%2Funderstanding-the-output-of-get-speculationcontrolsettings-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet-SpeculationControlSettings%3C%2FA%3E.%20You%20can%20also%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2Fapi%2Fwinternl%2Fnf-winternl-ntquerysysteminformation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ENtQuerySystemInformation%3C%2FA%3E%20to%20programmatically%20query%20retpoline%20status.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20a%20more%20in-depth%20look%2C%20here%20is%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZfxXjDQRpsU%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Etalk%3C%2FA%3E%20by%20Andrea%20Allievi%20at%20BlueHat%202018%20talking%20about%20retpoline%20on%20Windows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGive%20the%20latest%20builds%20a%20try%20and%20let%20us%20know%20your%20experience!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-295618%22%20slang%3D%22en-US%22%3E%3CP%3ERead%20about%20how%20the%20Windows%20Kernel%20team%20adapted%20retpoline%20for%20Windows%20to%20deliver%20a%20high-performance%20mitigation%26nbsp%3Bfor%20Spectre%20variant%202.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20960px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F62068i80764101748728D5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Spectre_blog.png%22%20title%3D%22Spectre_blog.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-295618%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESecurity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ewindows%2010%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-786253%22%20slang%3D%22en-US%22%3ERe%3A%20Mitigating%20Spectre%20variant%202%20with%20Retpoline%20on%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-786253%22%20slang%3D%22en-US%22%3E%3CP%3ESo%2C%20I%20understand%20that%20for%20Windows%2010%201809%20and%20Windows%20Server%202019%20that%20updates%20will%20automatically%20enable%20retpoline%20when%26nbsp%3B%3CSPAN%3ESpectre%20Variant%202%20is%20enabled.%20What%20I%20can't%20understand%20through%20the%20multiple%20updates%20is%20whether%20or%20not%20retpoline%20can%20be%20used%20on%20Server%202016%20by%20using%20the%20reg%20keys%20or%20if%20it's%20not%20available%20at%20all%20for%20the%20OS.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Updated May 14, 2019:  We're happy to announce that today we've updated Retpoline cloud configuration to enable it for all supported devices!* In addition, with the May 14 Patch Tuesday update, we've removed the dependence on cloud configuration such that even those customers who may not be receiving cloud configuration updates can experience Retpoline performance gains.

*Note: Retpoline is enabled by default on devices running Windows 10, version 1809 and Windows Server 2019 or newer and which meet the following conditions:

  • Spectre, Variant 2 (CVE-2017-5715) mitigation is enabled.
    • For Client SKUs, Spectre Variant 2 mitigation is enabled by default
    • For Server SKUs, Spectre Variant 2 mitigation is disabled by default. To realize the benefits of Retpoline, IT Admins can enable it on servers following this guidance.
  • Supported microcode/firmware updates are applied to the machine.

 

Updated March 1, 2019:  The post below outlines the performance benefits of using Retpoline against the Spectre variant 2 (CVE-2017-5715) attack—as observed with 64-bit Windows Insider Preview Builds 18272 and later. While Retpoline is currently disabled by default on production Windows 10 client devices, we have backported the OS modifications needed to support Retpoline so that it can be used with Windows 10, version 1809 and have those modifications in the March 1, 2019 update (KB4482887).

Over the coming months, we will enable Retpoline as part of phased rollout via cloud configuration. Due to the complexity of the implementation and changes involved, we are only enabling Retpoline performance benefits for Windows 10, version 1809 and later releases.

 

Updated March 5, 2019:   While the phased rollout is in progress, customers who would like to manually enable Retpoline on their machines can do so with the following registry configuration updates:

 

On Client SKUs:

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

On Server SKUs:

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

 

Note: The above registry configurations are for customers running with default mitigation settings. In particular, for Server SKUs, these settings will enable Spectre variant 2 mitigations (which are enabled by default on Client SKUs). 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.

Example: Feature settings values for enabling SSBD (speculative store bypass) system wide:
FeatureSettingsOverride = 0x8 and FeatureSettingsOverrideMask = 0
To add Retpoline, feature settings value for Retpoline (0x400) should be bitwise OR'd:
FeatureSettingsOverride = 0x408 and FeatureSettings OverrideMask = 0x400

Get-SpeculationControlSettings PowerShell cmdlet can be used to verify Retpoline status. Here’s an example output showing Retpoline and import optimization enabled:

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 
… 
BTIKernelRetpolineEnabled           : True 
BTIKernelImportOptimizationEnabled  : True 
...

Since Retpoline is a performance optimization for Spectre Variant 2, it requires that hardware and OS support for branch target injection to be present and enabled. Skylake and later generations of Intel processors are not compatible with Retpoline, so only Import Optimization will be enabled on these processors.


In January 2018, Microsoft released an advisory and security updates related to a newly discovered class of hardware vulnerabilities involving speculative execution side channels (known as Spectre and Meltdown) that affect AMD, ARM, and Intel CPUs to varying degrees. If you haven’t had a chance to learn about these issues, we recommend watching The Case of Spectre and Meltdown by the team at TU Graz from BlueHat Israel, reading the blog post by Jann Horn (@tehjh) of Google Project Zero.

 

We have also had multiple posts detailing the internals of our implementation to handle these side-channel attacks.

  1. Mitigating speculative execution side channel hardware vulnerabilities
  2. KVA Shadow: Mitigating Meltdown on Windows
  3. Analysis and mitigation of L1 Terminal Fault (L1TF)

For today’s post, we have kernel developers Andrea Allievi and Chris Kleynhans describing our design and implementation of retpoline for Windows which improves performance of Spectre variant 2 mitigations (CVE-2017-5715) to noise-level for most scenarios. These improvements are available today in Windows Insider Builds (builds 18272 or newer, x64-only).

 

Introduction

At a high level, the Spectre variant 2 attack exploits indirect branches to steal secrets located in higher privilege contexts (e.g. kernel-mode vs user-mode). Indirect branches are instructions where the target of the branch is not contained in the instruction itself, such as when the destination address is stored in a CPU register.

 

Describing the full Spectre attack is outside the scope of this article. Details are in the links above or in this whitepaper from Intel.

 

Our original mitigations for Spectre variant 2 made use of new capabilities exposed by CPU microcode updates to restrict indirect branch speculation when executing within kernel mode (IBRS and IBPB). While this was an effective mitigation from a security standpoint, it resulted in a larger performance degradation than we’d like on certain processors and workloads.

 

For this reason, starting in early 2018, we investigated alternatives and found promise in an approach developed by Google called retpoline. A full description of retpoline can be found here, but in short, retpoline works by replacing all indirect call or jumps in kernel-mode binaries with an indirect branch sequence that has safe speculation behavior.

 

This sequence, shown below in Figure 1, effects a safe control transfer to the target address by performing a function call, modifying the return address and then returning.

RP0:  call RP2                 ; push address of RP1 onto the stack and jump to RP2
RP1:  int 3                    ; breakpoint to capture speculation
RP2:  mov [rsp], <Jump Target> ; overwrite return address on the stack to desired target
RP3:  ret                      ; return

While this construct is not as fast as a regular indirect call or jump, it has the side effect of preventing the processor from unsafe speculative execution. This proves to be much faster than running all of kernel mode code with branch speculation restricted (IBRS set to 1). However, this construct is only safe to use on processors where the RET instruction does not speculate based on the contents of the indirect branch predictor. Those processors are all AMD processors as well as Intel processors codenamed Broadwell and earlier according to Intel’s whitepaper. Retpoline is not applicable to Skylake and later processors from Intel.

 

Windows requirements for Retpoline

Traditionally the transformation of indirect calls and jumps into retpolines is performed when a binary is built by the compiler. However, there are several functional requirements in Windows that make a purely compile-time implementation insufficient.

 

These key requirements are:

  1. Single binary: Windows releases are long-lived and must support a wide variety of hardware with a single set of binaries. On some hardware retpoline is not a complete mitigation because of alternate behavior of the ret instruction and retpoline must not be used. Further, future hardware may eliminate the need for retpoline entirely. Therefore, a Windows implementation of retpoline must allow the feature to be enabled and disabled at boot time using a single set of binaries, based on whether the underlying hardware is vulnerable, compatible and whether Spectre variant 2 mitigations are enabled on the system. Further, the runtime overhead of retpoline support should be minimal when the feature is disabled.
  2. 3rd party device drivers: A lot of the code that runs in kernel mode is not part of Windows and consists of 3rd party device driver code. Traditional retpoline would only be secure if all these drivers were recompiled with a new version of the compiler. Given the breadth of Windows 3rd party driver ecosystem, it is not realistic to expect all non-inbox 3rd party drivers to be recompiled and released to customers at the same time. Therefore, a Windows implementation of retpoline must be able to support a mixed environment, providing high performance when running drivers that have been updated, but allowing for graceful fallback to hardware-based mitigations upon entering a non-retpoline driver to preserve security.
  3. Driver portability: Windows drivers are not bound to a specific release of Windows, many drivers that are built today for Windows 10 will also support older versions of the operating system. Therefore, a Windows implementation of retpoline must ensure that drivers compiled with retpoline support can run on a version of Windows that does not support retpoline.

General Architecture

To satisfy requirement 1 and 3, we decided that binaries would ship in a non-retpolined state and then be transformed into a retpolined state by rewriting the code sequences for all indirect calls. This ensures that systems that do not use retpoline can use the binaries as compiled without needing any support for retpoline and with minimal runtime cost.

 

However, performing the transformation at runtime does lead to one problem. How do we know what transformations need to be applied? Disassembling and analyzing driver machine code to locate all indirect calls is not practical.

 

Dynamic Value Relocation Table (DVRT)

To solve this problem, we collaborated with the compiler team in Visual Studio to develop a system whereby the compiler can emit a new type of metadata into driver binaries describing each indirect call or jump in the system. This metadata takes the form of new relocation entries in the Dynamic Value Relocation Table (DVRT).

 

The DVRT was originally introduced back in the Windows 10 Creators Update to improve kernel address space layout randomization (KASLR). It allowed the memory manager’s page frame number (PFN) database and page table self-map to be assigned dynamic addresses at runtime. The DVRT is stored directly in the binary and contains a series of relocation entries for each symbol (i.e. address) that is to be relocated. The relocation entries are themselves arranged in a hierarchical fashion grouped first by symbol and then by containing page to allow for a compact description of all locations in the binary that reference a relocatable symbol.

 

At build time, the compiler keeps track of all references to these special symbols and fills out the DVRT. Then at runtime the kernel will parse the DVRT and update each symbol reference with the correct dynamically assigned address. Importantly, the kernel will skip over any DVRT entries it does not recognize (i.e. those with an unknown symbol) so adding new symbols to the DVRT does not break older versions of Windows.

 

These properties meant the DVRT was a perfect place to store our retpoline metadata, however the existing DVRT format needed to be extended to support retpoline.

 

Based on Windows requirements, we classified indirect calls/jumps into three distinct forms and each of these forms has its own type of retpoline relocation and corresponding runtime fixup.

  1. Import calls/jumps
  2. Switchtable jumps
  3. Generic indirect calls/jumps

Let’s talk a little about each of these types of calls.

 

Import Calls/Jumps

Import calls/jumps are, as the name implies, used for calls/jumps made by a binary to functions that have been imported from another binary. When compiling with retpoline, the compiler ensures that all such calls conform to the following form:

48 FF 15 XX XX XX XX     call qword ptr [_imp_<function>]
0F 1F 44 00 00           nop

The call or jmp instruction always directly references the import address table (IAT) and has 5 bytes of additional padding (to be used by the retpoline fixup).

 

Switchtable Jumps

Switchtable jumps are used for jumps made to other locations within the same function and are so-named because of their usage in implementing C/C++ switch statements. When compiling with retpoline support the compiler ensures that such calls are always made through a register and take the following form:

FF D0                    jmp rax
CC CC CC                 int 3

Generic Indirect Calls/Jumps

All other indirect calls/jumps fall into the generic type. To simplify the retpoline relocation format and the corresponding fixup logic, the compiler ensures that all such indirect calls/jumps provide their target address in the RAX register. The exact format of the call/jump instruction however differs depending on whether it is protected by control flow guard (CFG).

 

Loading binaries at runtime

Now that we have a way to identify all the indirect calls/jumps in the binary, we need to apply the fixups.

 

The NT memory manager has long had infrastructure to apply fixups to binaries at runtime. This infrastructure was extended to understand retpoline relocations and their corresponding fixups.

 

But what exactly do these fixups look like? As mentioned earlier, the Windows implementation needs to support mixed environments in which some drivers are not compiled with retpoline support. This means that we cannot simply replace every indirect call with a retpoline sequence like the example shown in the introduction. We need to ensure that the kernel gets the opportunity to inspect the target of the call or jump so that it can apply appropriate mitigations if the target does not support retpoline.

 

For this reason, we transform every indirect call or jump into a direct call or jump to a kernel provided “retpoline stub function”. For example, an indirect call to an imported function that looks like this:

call qword ptr [_imp_ExAllocatePoolWithTag]     ; Target address located at a REL32 offset
nop                                             ; Padding

Will be replaced at runtime with a direct call to the retpoline import stub:

mov r10, qword ptr [_imp_ExAllocatePoolWithTag] ; R10 = target address
call _guard_retpoline_import_r10                ; Direct REL32 call to the stub function

There are several retpoline stub functions each of which is specialized to the type of call/jump it handles. However, each function generally performs the following steps:

  1. Check if the target binary supports retpoline
    • Prior to transferring control to the target address, the function must determine whether the target address belongs to a driver that supports retpoline. To determine this, the kernel maintains a sparse bitmap of the entire kernel-mode address space with each bit describing a 64 KB region of the address space. Bits in this bitmap are set to 1 if and only if their corresponding region of address space belongs to a kernel-mode binary that fully supports retpoline.
    • If the bitmap check determines that the target address does not belong to a retpolined binary, the stub function has to fall back to the hardware-based Spectre variant 2 mitigation (by setting IBRS to restrict branch speculation) and then perform a regular indirect call/jmp. Otherwise, the kernel does not need to set IBRS. On processors that do not support IBRS, retpoline will, instead, perform IBPB if user-to-kernel protection is enabled as described here.
    • Since the target of a switch table jump is always in the same binary as the source (and therefore the target is guaranteed to support retpoline), this bitmap check is omitted from the switchtable jump stub functions.
  2. Check if the target address is a valid CFG target
    • For CFG instrumented indirect calls/jumps the retpoline stub function is responsible for checking the kernel-mode CFG bitmap to verify that the target address given is a valid CFG call target. If this check fails, then the stub function will bugcheck the system to prevent any exploit that attempts an indirect control transfer to an invalid address.
  3. Transfer control to the target using a retpoline.

The usage of these stub functions ensures that we can satisfy the requirement to support mixed environments, however they do introduce one additional problem. The x64 direct call/jump instruction can only encode a target address within 2 GB of the call-site (since the target is specified by a signed 16- or 32-bit offset). Since the retpoline stub functions are implemented in the NT kernel binary this would generally mean that drivers would have to be loaded within 2 GB of the kernel binary.

 

To work around this requirement, all retpoline stub functions are contained within a single section of the NT kernel binary and have been carefully written to take no dependencies on their position relative to the rest of the binary. This allows us to map the physical memory pages backing the retpoline stub functions immediately after every driver in the system, giving each driver its own “copy” of the retpoline stub functions that is guaranteed to be within 2 GB of every indirect call/jump.

 

Import optimization

Indirect calls due to imported functions are by far the most common form of indirect control transfers in kernel-mode. The import call targets are determined at driver load time by processing the import address table (IAT) and remain constant throughout the driver’s lifetime. This means that most of the work provided by the retpoline import stub is unnecessary because we know at driver load time exactly where each of these calls will end up going and we know whether the target binary supports retpoline or not. Hence, we can use a much faster calling sequence.

 

With import optimization, we use the retpoline fixup infrastructure to replace eligible import calls with direct calls to the imported function. This eliminates the overhead of the retpoline import call stub as well as the guaranteed branch prediction miss due to retpoline itself. To be eligible for import optimization, a call must meet the following requirements:

  1. The call/jump must be from a retpolined binary to another retpolined binary.
    • This is necessary to maintain the security guarantees of retpoline because once we’ve rewritten the indirect call into a direct call the kernel no longer gets a chance to observe the target address and enable IBRS.
  2. The target of the call must be within 2 GB of the call site.
    • This is because as mentioned above direct call/jump instructions on x64 can only encode a 32-bit offset.
    • In order to virtually guarantee that import optimization can be applied all retpolined modules, the OS loader and kernel make sure that all kernel-mode modules are packed tightly in the address space while maintaining address space layout randomizations (ASLR).

Here is an example of how the code generation for the call is modified.

Original code sequence

call [__imp_<Function>]                   ; Call to an imported function
nop                                       ; 5-byte nop

Import Optimized code sequence

mov r10, [__imp_<Function>]               ; R10 = target address (normal transformation)
call <Function>                           ; Direct REL32 call to target

Import optimization turned out to be a big performance win! Hence, even on processors where retpoline cannot be used due to alternate return instruction behavior, we still use import optimization.

 

Conclusion

Retpoline has significantly improved the performance of the Spectre variant 2 mitigations on Windows. When all relevant kernel-mode binaries are compiled with retpoline, we’ve measured ~25% speedup in Office app launch times and up to 1.5-2x improved throughput in the Diskspd (storage) and NTttcp (networking) benchmarks on Broadwell CPUs in our lab. It is enabled by default in the latest Windows Client Insider Fast builds (for builds 18272 and higher on machines exposing compatible speculation control capabilities) and is targeted to ship with 19H1.

 

To check if retpoline and import optimizations are enabled, you can use the PowerShell cmdlet Get-SpeculationControlSettings. You can also use NtQuerySystemInformation to programmatically query retpoline status.

 

For a more in-depth look, here is a talk by Andrea Allievi at BlueHat 2018 talking about retpoline on Windows.

 

Give the latest builds a try and let us know your experience!

 

22 Comments
Occasional Visitor

Any chance we see this in 1809? If not, when do you expect 19H1 to ship?

Occasional Visitor

Thanks. Will this be back-ported to Windows Server 2019 at some point in 2019? and if not, should we just accept to be running a none-optimized OS for a few years if we want a server OS with desktop experience installed?

 
New Contributor

Could you please explain how to tell if retpoline is enabled? You mentioned the powershell command, but I don't see anything in the results related to retpoline or it is not obvious to me which of the results relate to it.

 

*EDIT* Nevermind, apparently the Skip Ahead 20H1 builds do not include it yet

Visitor

I am wondering about Retpoline as well. I'm currently running Windows 10 1809 with March 1, 2019—KB4482887 (OS Build 17763.348) installed.

 

I then went and installed the latest version of Get-SpeculationControlSettings at https://support.microsoft.com/en-us/help/4074629/understanding-the-output-of-get-speculationcontrols... as per the article here https://techcommunity.microsoft.com/t5/Windows-Kernel-Internals/Mitigating-Spectre-variant-2-with-Re... which states "To check if retpoline and import optimizations are enabled, you can use the PowerShell cmdlet Get-SpeculationControlSettings. You can also use NtQuerySystemInformation to programmatically query retpoline status."

Unfortuantely I do not know how to programmatically query the retpoline status, but I would do so if I knew how. I have run the Get-SpeculationControlSettings in the past though, and it seems that expected behavior is supposed to include checking for Retpoline status. Maybe the Powershell cmdlet has not been updated to reflect this, but that isn't entirely clear.

 

I am running on an i7-4790K so I believe to be impacted by Retpoline and am curious to understand more.

Regular Visitor

@boktai1000 The PS script does include Retpoline, if updated to the last version. I don't think it's Enabled yet:

"Over the coming months, we will enable Retpoline as part of phased rollout via cloud configuration."

Visitor

@Brok3n Cogniti0n- I do see that you're absolutely right! I completely overlooked that, so my apologies for potentially confusing people by my comment.

 

I do see BTIKernelRetpolineEnabled in the output, which for me listed as False - which lines up with what you're saying.

 

Thank you for taking the time to reply to me on this!

Regular Visitor

@boktai1000 Same output for me. I guess we gonna have to wait and see how those Microsoft could config works.

Occasional Visitor

@Brok3n Cogniti0n @boktai1000 with 17763.348 you should have retpoline enabled, it specifically adds support to 1809.

 

I cannot verify as I am running 19H1 but perhaps Retpoline is only enabled with Spectre protections enabled, you should check out how to enable them on client systems (you may need KB4465065 and registry settings changes as outlined in MS ADV18002) if your machine does not have hardware microcode.

 

KB4465065 is a standalone update and not delivered by WU.

Regular Visitor

@rebootit It comes disabled, even though support was added indeed. It specifically says that it will be enabled via "cloud configuration" over the next months. For the next feature update it should come as enabled by default.

Occasional Visitor
i have a intel broadwell(NUC). i am, till now, fully patched (firmware+OS(W10 1809)). powershell script outputs, smooth as silk, all "trues" (in the right places) i was waiting, with anxiety, for these new settings for retpoline: well, i applied those and...they destroy the protection for SSB(CVE-2018-3639). because retpoline and SSB keys in the registry are the same: FeatureSettingsOverride and FeatureSettingsOverrideMask these two keys are set to "8" and "3" to have all "trues" at SSB section of powershell script output if you set both keys to "400" ,as you need to cover retpoline, you disrupt protection for SSB (that is not "true" anymore in powershell script) how to solve? these are two screenshots with the output of powershell script, the first with "8" and "3" inside "FeatureSettingsOverride" and "FeatureSettingsOverrideMask" keys. the second with "400" and "400" note the variations of "true" and "false" across the sections of powershell script outputs https://imgur.com/a/fWB9Hzj
Contributor

@jessecook My 18845 has this enabled already, according to the PS module. I didn't touch the Registry. Unclear if it's all 20H1 or phased.

Occasional Visitor

@groviglio This has been answered here. If you require additional protections then bitwise add the previous values for enable SSBD, Spectre v2 and Meltdown (8), disable Spectre v2 and Meltdown (3), disable Spectre v2 only (2) and disable Meltdown only (1).

 

But I can confirm as I had registry settings of 8 (and a mask of 3) when upgrading to 18346 (via 18343) I have the retpoline enabled according to the PowerShell script without having to modify the registry. FWIW I have hardware uCode and a Broadwell i7-5500U.

 

The registry has remained unchanged but all protections and optimisations are present.

Occasional Visitor
thanks @rebootit, it all went well :)
Regular Visitor

Please note that the Intel whitepaper "Retpoline: A Branch Target Injection Mitigation" https://software.intel.com/security-software-guidance/api-app/sites/default/files/Retpoline-A-Branch... has been superseded by "Deep Dive: Retpoline: A Branch Target Injection Mitigation" https://software.intel.com/security-software-guidance/insights/deep-dive-retpoline-branch-target-inj...

Occasional Visitor

@rebootit

I'm confused, Do I need to enable SSBD? Or is it disabled by default?

I don't remember what was the original entries in the registry because I changed them to disable the original patch 8 months ago.

Occasional Visitor

Retpoline is a way of optimising variant 2 mitigation’s. SSBD is a different Spectre class vulnerability. Mitigation for SSBD is not enabled by default.

New Contributor
It looks like Retpoline and Import Optimization are completely incompatible with Hyper-V, even when forced. Is this intentional? Will Windows 10 19H1 have the same massive limitation?
Occasional Contributor

@Inari Okami I also had this issue testing CPUs Sandybridge - Haswell  so you're not alone, even March CU doesn't seem to address the issue.

 

However it does seem to work for the most part in 19H1, 19H2 or 20H1. It's likely they are still working on ironing out issues before releasing it to everyone. 

Occasional Visitor

it seems retpoline and import optimizations are not compatible with virtualization based security(vbs)

 

Microsoft

In Windows 1809 (RS5/Server 2019), retpoline and import optimization are disabled if HVCI (DeviceGuard) is enabled. This restriction is eliminated in 19H1 (Spring 2019) release where retpoline/import optimization can coexist with DeviceGuard.

 

 

New Contributor

@Mehmet_Iyigun10.0.18362.53, Import Optimization is still off whenever HVCI is on. Retpoline says it's working, though.

Occasional Visitor

So, I understand that for Windows 10 1809 and Windows Server 2019 that updates will automatically enable retpoline when Spectre Variant 2 is enabled. What I can't understand through the multiple updates is whether or not retpoline can be used on Server 2016 by using the reg keys or if it's not available at all for the OS.