Developer Guidance for Hardware-enforced Stack Protection

Published Feb 24 2021 12:47 PM 17.6K Views
Microsoft

In March 2020, we shared some preliminary information about a new security feature in Windows called Hardware-enforced Stack Protection based on Intel’s Control-flow Enforcement Technology (CET). Today, we are excited to share the next level of details with our developer community around protecting user-mode applications with this feature. Please see requirements section for hardware and OS requirements to take advantage of Hardware-enforced Stack Protection.

 

Starting from the 11C latest cumulative update for 20H1 (19041) and 20H2 (19042) versions of Windows 10, we’ve enabled user mode Hardware-enforced Stack Protection for supported hardware. This exploit mitigation will protect the return address, and work with other Windows mitigations to prevent exploit techniques that aim to achieve arbitrary code execution. When attackers find a vulnerability that allows them to overwrite values on the stack, a common exploit technique is to overwrite return addresses into attacker-defined locations to build a malicious payload. This technique is known as return-oriented programming (ROP). More details on ROP and hardware shadow stacks is in this kernel blog.

 

For user mode applications, this mitigation is opt-in, and the following details are intended to aid developers in understanding how to build protected applications. We will describe in detail the two policies in Hardware-enforced Stack Protection: 1) shadow stack 2) instruction pointer validation. Shadow stack hardens the return address and instruction pointer validation protects exception handling targets.

 

Shadow Stack

Shadow stack is a hardware-enforced read-only memory region that helps keep record of the intended control-flow of the program. On supported hardware, call instructions push the return address on both stacks and return instructions compare the values and issues a CPU exception if there is a return address mismatch. Due to these required hardware capabilities only newer processors will have this feature.

 

To enable shadow stack enforcement on an application, you only need to recompile the application with the /CETCOMPAT linker flag (available in Visual Studio 2019 16.7 Preview 4).

 

CETCOMPAT Property Pages.png

 

Generally, code changes are not needed and the only modification to the binary is a bit in the PE header. However, if your code behavior includes modifying the return addresses on the stack (which results in mismatch with the shadow stack), then the hijacking code must be removed.

 

Applications can also choose to dynamically enable shadow stack enforcement, by using the PROC_THREAD_ATTIBUTE_MITIGATION_POLICY attribute in CreateProcess. This allows programs with multiple executables with the same name to specify specific processes to enable enforcement.

 

Shadow stack enforcement by default is in compatibility mode. Compatibility mode provides a more flexible enforcement of shadow stacks, at module granularity. When a return address mismatch occurs in this mode, it is checked to see if 1) it is not in an image binary (from dynamic code) or 2) in a module that is not compiled for /CETCOMPAT. If either hold true, the execution is allowed to continue. This way, you can slowly increase the coverage of the mitigation, by compiling more modules with /CETCOMPAT at your own pace. To protect dynamic code in compatibility mode, there is a new API, SetProcessDynamicEnforcedCetCompatibleRanges, to allow you to specify a range of virtual addresses to enforce this mitigation. Note that by default this API can only be called from outside the target process for security purposes.

 

Note that all native 64-bit Windows DLLs are compiled with /CETCOMPAT.

 

Strict mode, by definition, strictly enforces shadow stack protections and will terminate the process if the intended return address is also not on the shadow stack.

 

Today, it is recommended to enable your application in compatibility mode, as third-party DLLs may be injected into your process, and subsequently perform return address hijacking. We are working with our ecosystem developers to clean up any of this behavior. At the current time, we recommend beginning by enabling compatibility mode enforcement for your application.

 

The following diagram illustrates how the system behaves under shadow stack. When a return address mismatch occurs, the CPU raises a #CP exception:

 

Compatibility Mode Diagram.PNG

 

Strict Mode Diagram.png

 

As you can see, return address mismatches cause a trap to the kernel, which comes with a performance hit even if the mismatch is forgiven and execution is allowed to continue.

 

Instruction Pointer Validation

With the presence of shadow stacks, one of the next exploit techniques attackers may use to hijack control flow is corrupting the instruction pointer value inside the CONTEXT structure passed into system calls that redirect the execution of a thread, such as NtContinue and SetThreadContext. To provide a comprehensive control-flow integrity mitigation, Hardware-enforced Stack Protection includes an additional mitigation to validate the instruction pointer during exception handling. It is important to keep this mitigation in mind as well when testing for compatibility.

 

When shadow stacks are enabled for an application, SetThreadContext is enlightened to validate the user-supplied instruction pointer. Calls are allowed to proceed only if the value is found on the shadow stack (otherwise the call will fail).

 

For structured exception handling, RtlRestoreContext/NtContinue is hardened by a parallel mitigation, EH Continuation Metadata (EHCONT), by using the /guard:ehcont flag.

 

EHCONT Property Pages.png

 

When this flag is specified, the compiler will include metadata in the binary that has a table of valid exception handling continuation targets. The list of continuation targets is generated by the linker for compiled code. For dynamic code, continuation targets should be specified using SetProcessDynamicEHContinuationTargets (similarly can only be called from outside the target process by default). With this feature enabled, the user-supplied instruction pointer will be checked to see if it is 1) on the shadow stack or 2) in the EH continuation data, before allowing the call to proceed (otherwise the call will fail). Note that if the binary does not contain EHCONT data (legacy binary), then the call is allowed to proceed.

 

Additionally, an application can be compiled for EHCONT even without shadow stack protection, in which the user-supplied instruction pointer must be present in the EH continuation data.

 

Common Violations

To properly build your application for Hardware-enforced Stack Protection, ensure there is a good understanding of how these security mitigations are enforced. Since shadow stacks are present throughout the lifetime of the process, the test matrix is enabling the above mitigations and ensure all code paths do not violate the security guarantees. The goal is to ensure present application code does not perform any behavior deemed unsecure under these mitigations.

 

Here are some examples of behaviors that violate shadow stacks:

 

Certain code obfuscation techniques will not automatically work with shadow stacks. As mentioned above, CALL and RET are enlightened to push onto the shadow stack and perform return address comparisons. Instruction combinations like PUSH/RET will not work with shadow stacks, as the corresponding return address is not present on the shadow stack when RET is performed. One recommendation here is instead using a (Control flow guard protected) JMP instruction.

 

Additionally, techniques that manually return to a previous call frame that is not the preceding call frame will also need to be shadow stack aware. In this case, it is recommended to use the _incsspq intrinsic to pop return addresses off the shadow stack so that it is in sync with the call stack.

 

User Interfaces

There are some user interfaces to help you understand the state of enforcement of processes on the machine. In task manager, adding the “Hardware-enforced Stack Protection” column in the “Details” tab will indicate processes are shadow stack protected, and whether they are in compatibility (compatible modules only) or strict (all modules) mode.

 

TaskMgr.png

 

Additionally, this mitigation can be controlled similar to other exploit protections, including toggling the enforcement using the Windows Defender UI, Group Policy, PowerShell, and other facilities. Use UserShadowStack and UserShadowStackStrictMode as the parameter keyword to manually toggle enforcement in compatibility and strict mode, respectively. Use AuditUserShadowStack to enable audit mode.

 

Defender.png

 

Requirements

You can begin building and testing your application to support Hardware-enforced Stack Protection today, by ensuring you have the following:

 

Hardware: 11th Gen Intel Core Mobile processors and AMD Zen 3 Core (and newer)

Hardware-enforced Stack Protection capable OS: 19041.622 or 19042.622 and newer versions

 

Conclusion

We will continue to strive towards investing in exploit mitigations to make Windows 10 the most secure operating system. These mitigations will help proactively prohibit an attacker’s ability to hijack your program in the event a vulnerability is discovered. Note in the current release, this mitigation is only supported in 64-bit code. There is no support for 32-bit code, WoW64, or in Guest Virtual Machines at the moment.

 

In the latest canary builds of Edge (version 90), Hardware-enforced Stack Protection is enabled in compatibility mode on the browser and a few non-sandboxed processes. In upcoming releases, there will be continued investments in expanding the list of processes protected by this mitigation. Please try it out and provide your feedback. You can send related questions to CETQuestions@microsoft.com.

 

 

Kernel Protection team - Jin Lin, Jason Lin, Matthew Woolman

 

 

 

3 Comments

Thank you for Sharing with the Community !

Occasional Visitor

Hi, @Jin_Lin 

  • Does HSP must to be supported in Win11? because in the driver HLK test, we cannot pass without selected "Y".
  • EthanHunag_0-1628041556027.png
  • EthanHunag_1-1628041584245.png

     

  • If I want to support HSP, do I must to use Visual Studio 2019 16.7 Preview 4 or later to build binary (.sys, .dll, .exe)?
Occasional Visitor

Hi @Jin_Lin,

I could succesfully override (disable) HSP of a x64 process which was build with VS19 and /CETCOMPAT=YES. But when I try to override (disable) HSP for the system-process svchost.exe the mitigation-settings do not change and HSP keeps active with the default "Compatible modules only". Is there a special protection for system processes? Is there a way to change the HSP for svchost.exe or change the system default for all processes? 

I would be very grateful for any advice!

%3CLINGO-SUB%20id%3D%22lingo-sub-2165440%22%20slang%3D%22en-US%22%3ERe%3A%20Developer%20Guidance%20for%20Hardware-enforced%20Stack%20Protection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2165440%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20for%20Sharing%20with%20the%20Community%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2163340%22%20slang%3D%22en-US%22%3EDeveloper%20Guidance%20for%20Hardware-enforced%20Stack%20Protection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2163340%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20March%202020%2C%20we%20share%3CSPAN%3Ed%3C%2FSPAN%3E%20some%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fwindows-kernel-internals%2Funderstanding-hardware-enforced-stack-protection%2Fba-p%2F1247815%22%20target%3D%22_blank%22%3Epreliminary%20information%3C%2FA%3E%20about%20a%20new%20security%20feature%20in%20Windows%20called%20Hardware-enforced%20Stack%20Protection%20based%20on%20Intel%E2%80%99s%20Control-flow%20Enforcement%20Technology%20(CET).%20Today%2C%20we%20are%20excited%20to%20share%20the%20next%20level%20of%20details%20with%20our%20developer%20community%20around%20protecting%20user-mode%20applications%20with%20this%20feature.%20Please%20see%20requirements%20section%20for%20hardware%20and%20OS%20requirements%20to%20take%20advantage%20of%20Hardware-enforced%20Stack%20Protection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStarting%20from%20the%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4586853%2Fwindows-10-update-kb4586853%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E11C%20latest%20cumulative%20update%3C%2FA%3E%20for%2020H1%20(19041)%20and%2020H2%20(19042)%20versions%20of%20Windows%2010%2C%20we%E2%80%99ve%20enabled%20user%20mode%20Hardware-enforced%20Stack%20Protection%20for%20supported%20hardware.%20This%20exploit%20mitigation%20will%20protect%20the%20return%20address%2C%20and%20work%20with%20other%20Windows%20mitigations%20to%20prevent%20exploit%20techniques%20that%20aim%20to%20achieve%20arbitrary%20code%20execution.%20When%20attackers%20find%20a%20vulnerability%20that%20allows%20them%20to%20overwrite%20values%20on%20the%20stack%2C%20a%20common%20exploit%20technique%20is%20to%20overwrite%20return%20addresses%20into%20attacker-defined%20locations%20to%20build%20a%20malicious%20payload.%20This%20technique%20is%20known%20as%20return-oriented%20programming%20(ROP).%20More%20details%20on%20ROP%20and%20hardware%20shadow%20stacks%20is%20in%20this%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fwindows-kernel-internals%2Funderstanding-hardware-enforced-stack-protection%2Fba-p%2F1247815%22%20target%3D%22_blank%22%3Ekernel%20blog%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20user%20mode%20applications%2C%20this%20mitigation%20is%20opt-in%2C%20and%20the%20following%20details%20are%20intended%20to%20aid%20developers%20in%20understanding%20how%20to%20build%20protected%20applications.%20We%20will%20describe%20in%20detail%20the%20two%20policies%20in%20Hardware-enforced%20Stack%20Protection%3A%201)%20shadow%20stack%202)%20instruction%20pointer%20validation.%20Shadow%20stack%20hardens%20the%20return%20address%20and%20instruction%20pointer%20validation%20protects%20exception%20handling%20targets.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--523327117%22%20id%3D%22toc-hId--523327117%22%20id%3D%22toc-hId--523327117%22%20id%3D%22toc-hId--523327117%22%3EShadow%20Stack%3C%2FH2%3E%0A%3CP%3EShadow%20stack%20is%20a%20hardware-enforced%20read-only%20memory%20region%20that%20helps%20keep%20record%20of%20the%20intended%20control-flow%20of%20the%20program.%20On%20supported%20hardware%2C%20call%20instructions%20push%20the%20return%20address%20on%20both%20stacks%20and%20return%20instructions%20compare%20the%20values%20and%20issues%20a%20CPU%20exception%20if%20there%20is%20a%20return%20address%20mismatch.%20Due%20to%20these%20required%20hardware%20capabilities%20only%20newer%20processors%20will%20have%20this%20feature.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20enable%20shadow%20stack%20enforcement%20on%20an%20application%2C%20you%20only%20need%20to%20recompile%20the%20application%20with%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcpp%2Fbuild%2Freference%2Fcetcompat%3Fview%3Dmsvc-160%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%2FCETCOMPAT%20linker%20flag%3C%2FA%3E%20(available%20in%20Visual%20Studio%202019%2016.7%20Preview%204).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22CETCOMPAT%20Property%20Pages.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257461iEC7DA167E7FA79DB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CETCOMPAT%20Property%20Pages.png%22%20alt%3D%22CETCOMPAT%20Property%20Pages.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGenerally%2C%20code%20changes%20are%20not%20needed%20and%20the%20only%20modification%20to%20the%20binary%20is%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2Fdebug%2Fpe-format%23extended-dll-characteristics%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ea%20bit%20in%20the%20PE%20header%3C%2FA%3E.%20However%2C%20if%20your%20code%20behavior%20includes%20modifying%20the%20return%20addresses%20on%20the%20stack%20(which%20results%20in%20mismatch%20with%20the%20shadow%20stack)%2C%20then%20the%20hijacking%20code%20must%20be%20removed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EApplications%20can%20also%20choose%20to%20dynamically%20enable%20shadow%20stack%20enforcement%2C%20by%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fapi%2Fprocessthreadsapi%2Fnf-processthreadsapi-updateprocthreadattribute%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EPROC_THREAD_ATTIBUTE_MITIGATION_POLICY%3C%2FA%3E%20attribute%20in%20CreateProcess.%20This%20allows%20programs%20with%20multiple%20executables%20with%20the%20same%20name%20to%20specify%20specific%20processes%20to%20enable%20enforcement.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EShadow%20stack%20enforcement%20by%20default%20is%20in%20%3CEM%3Ecompatibility%20mode%3CSTRONG%3E.%3C%2FSTRONG%3E%3C%2FEM%3E%20Compatibility%20mode%20provides%20a%20more%20flexible%20enforcement%20of%20shadow%20stacks%2C%20at%20module%20granularity.%20When%20a%20return%20address%20mismatch%20occurs%20in%20this%20mode%2C%20it%20is%20checked%20to%20see%20if%201)%20it%20is%20not%20in%20an%20image%20binary%20(from%20dynamic%20code)%20or%202)%20in%20a%20module%20that%20is%20not%20compiled%20for%20%2FCETCOMPAT.%20If%20either%20hold%20true%2C%20the%20execution%20is%20allowed%20to%20continue.%20This%20way%2C%20you%20can%20slowly%20increase%20the%20coverage%20of%20the%20mitigation%2C%20by%20compiling%20more%20modules%20with%20%2FCETCOMPAT%20at%20your%20own%20pace.%20To%20protect%20dynamic%20code%20in%20compatibility%20mode%2C%20there%20is%20a%20new%20API%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fapi%2Fprocessthreadsapi%2Fnf-processthreadsapi-setprocessdynamicenforcedcetcompatibleranges%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESetProcessDynamicEnforcedCetCompatibleRanges%3C%2FA%3E%2C%20to%20allow%20you%20to%20specify%20a%20range%20of%20virtual%20addresses%20to%20enforce%20this%20mitigation.%20Note%20that%20by%20default%20this%20API%20can%20only%20be%20called%20from%20outside%20the%20target%20process%20for%20security%20purposes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20all%20native%2064-bit%20Windows%20DLLs%20are%20compiled%20with%20%2FCETCOMPAT.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStrict%20mode%3CSPAN%3E%2C%3C%2FSPAN%3E%20by%20definition%2C%20strictly%20enforces%20shadow%20stack%20protections%20and%20will%20terminate%20the%20process%20if%20the%20intended%20return%20address%20is%20also%20not%20on%20the%20shadow%20stack.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EToday%2C%20it%20is%20recommended%20to%20enable%20your%20application%20in%20compatibility%20mode%2C%20as%20third-party%20DLLs%20may%20be%20injected%20into%20your%20process%2C%20and%20subsequently%20perform%20return%20address%20hijacking.%20We%20are%20working%20with%20our%20ecosystem%20developers%20to%20clean%20up%20any%20of%20this%20behavior.%20At%20the%20current%20time%2C%20we%20recommend%20beginning%20by%20enabling%20compatibility%20mode%20enforcement%20for%20your%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20following%20diagram%20illustrates%20how%20the%20system%20behaves%20under%20shadow%20stack.%20When%20a%20return%20address%20mismatch%20occurs%2C%20the%20CPU%20raises%20a%20%23CP%20exception%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Compatibility%20Mode%20Diagram.PNG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257462i06B8C3F9D875E37D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Compatibility%20Mode%20Diagram.PNG%22%20alt%3D%22Compatibility%20Mode%20Diagram.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Strict%20Mode%20Diagram.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257463i34E2E5B77A4711C9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Strict%20Mode%20Diagram.png%22%20alt%3D%22Strict%20Mode%20Diagram.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%2C%20return%20address%20mismatches%20cause%20a%20trap%20to%20the%20kernel%2C%20which%20comes%20with%20a%20performance%20hit%20even%20if%20the%20mismatch%20is%20forgiven%20and%20execution%20is%20allowed%20to%20continue.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1964185716%22%20id%3D%22toc-hId-1964185716%22%20id%3D%22toc-hId-1964185716%22%20id%3D%22toc-hId-1964185716%22%3EInstruction%20Pointer%20Validation%3C%2FH2%3E%0A%3CP%3EWith%20the%20presence%20of%20shadow%20stacks%2C%20one%20of%20the%20next%20exploit%20techniques%20attackers%20may%20use%20to%20hijack%20control%20flow%20is%20corrupting%20the%20instruction%20pointer%20value%20inside%20the%20CONTEXT%20structure%20passed%20into%20system%20calls%20that%20redirect%20the%20execution%20of%20a%20thread%2C%20such%20as%20NtContinue%20and%20SetThreadContext.%20To%20provide%20a%20comprehensive%20control-flow%20integrity%20mitigation%2C%20Hardware-enforced%20Stack%20Protection%20includes%20an%20additional%20mitigation%20to%20validate%20the%20instruction%20pointer%20during%20exception%20handling.%20It%20is%20important%20to%20keep%20this%20mitigation%20in%20mind%20as%20well%20when%20testing%20for%20compatibility.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20shadow%20stacks%20are%20enabled%20for%20an%20application%2C%20SetThreadContext%20is%20enlightened%20to%20validate%20the%20user-supplied%20instruction%20pointer.%20Calls%20are%20allowed%20to%20proceed%20only%20if%20the%20value%20is%20found%20on%20the%20shadow%20stack%20(otherwise%20the%20call%20will%20fail).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20structured%20exception%20handling%2C%20RtlRestoreContext%2FNtContinue%20is%20hardened%20by%20a%20parallel%20mitigation%2C%20EH%20Continuation%20Metadata%20(EHCONT)%2C%20by%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcpp%2Fbuild%2Freference%2Fguard-enable-eh-continuation-metadata%3Fview%3Dmsvc-160%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%2Fguard%3Aehcont%3C%2FA%3E%20flag.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EHCONT%20Property%20Pages.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257464iA62DA98DDB2B6ADB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22EHCONT%20Property%20Pages.png%22%20alt%3D%22EHCONT%20Property%20Pages.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20this%20flag%20is%20specified%2C%20the%20compiler%20will%20include%20metadata%20in%20the%20binary%20that%20has%20a%20table%20of%20valid%20exception%20handling%20continuation%20targets.%20The%20list%20of%20continuation%20targets%20is%20generated%20by%20the%20linker%20for%20compiled%20code.%20For%20dynamic%20code%2C%20continuation%20targets%20should%20be%20specified%20using%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fapi%2Fprocessthreadsapi%2Fnf-processthreadsapi-setprocessdynamicehcontinuationtargets%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESetProcessDynamicEHContinuationTargets%3C%2FA%3E%20(similarly%20can%20only%20be%20called%20from%20outside%20the%20target%20process%20by%20default).%20With%20this%20feature%20enabled%2C%20the%20user-supplied%20instruction%20pointer%20will%20be%20checked%20to%20see%20if%20it%20is%201)%20on%20the%20shadow%20stack%20or%202)%20in%20the%20EH%20continuation%20data%2C%20before%20allowing%20the%20call%20to%20proceed%20(otherwise%20the%20call%20will%20fail).%20Note%20that%20if%20the%20binary%20does%20not%20contain%20EHCONT%20data%20(legacy%20binary)%2C%20then%20the%20call%20is%20allowed%20to%20proceed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20an%20application%20can%20be%20compiled%20for%20EHCONT%20even%20without%20shadow%20stack%20protection%2C%20in%20which%20the%20user-supplied%20instruction%20pointer%20must%20be%20present%20in%20the%20EH%20continuation%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-156731253%22%20id%3D%22toc-hId-156731253%22%20id%3D%22toc-hId-156731253%22%20id%3D%22toc-hId-156731253%22%3ECommon%20Violations%3C%2FH2%3E%0A%3CP%3ETo%20properly%20build%20your%20application%20for%20Hardware-enforced%20Stack%20Protection%2C%20ensure%20there%20is%20a%20good%20understanding%20of%20how%20these%20security%20mitigations%20are%20enforced.%20Since%20shadow%20stacks%20are%20present%20throughout%20the%20lifetime%20of%20the%20process%2C%20the%20test%20matrix%20is%20enabling%20the%20above%20mitigations%20and%20ensure%20all%20code%20paths%20do%20not%20violate%20the%20security%20guarantees.%20The%20goal%20is%20to%20ensure%20present%20application%20code%20does%20not%20perform%20any%20behavior%20deemed%20unsecure%20under%20these%20mitigations.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20are%20some%20examples%20of%20behaviors%20that%20violate%20shadow%20stacks%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECertain%20code%20obfuscation%20techniques%20will%20not%20automatically%20work%20with%20shadow%20stacks.%20As%20mentioned%20above%2C%20CALL%20and%20RET%20are%20enlightened%20to%20push%20onto%20the%20shadow%20stack%20and%20perform%20return%20address%20comparisons.%20Instruction%20combinations%20like%20PUSH%2FRET%20will%20not%20work%20with%20shadow%20stacks%2C%20as%20the%20corresponding%20return%20address%20is%20not%20present%20on%20the%20shadow%20stack%20when%20RET%20is%20performed.%20One%20recommendation%20here%20is%20instead%20using%20a%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fsecbp%2Fcontrol-flow-guard%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EControl%20flow%20guard%20protected%3C%2FA%3E)%20JMP%20instruction.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20techniques%20that%20manually%20return%20to%20a%20previous%20call%20frame%20that%20is%20not%20the%20preceding%20call%20frame%20will%20also%20need%20to%20be%20shadow%20stack%20aware.%20In%20this%20case%2C%20it%20is%20recommended%20to%20use%20the%20_incsspq%20intrinsic%20to%20pop%20return%20addresses%20off%20the%20shadow%20stack%20so%20that%20it%20is%20in%20sync%20with%20the%20call%20stack.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1650723210%22%20id%3D%22toc-hId--1650723210%22%20id%3D%22toc-hId--1650723210%22%20id%3D%22toc-hId--1650723210%22%3EUser%20Interfaces%3C%2FH2%3E%0A%3CP%3EThere%20are%20some%20user%20interfaces%20to%20help%20you%20understand%20the%20state%20of%20enforcement%20of%20processes%20on%20the%20machine.%20In%20task%20manager%2C%20adding%20the%20%E2%80%9CHardware-enforced%20Stack%20Protection%E2%80%9D%20column%20in%20the%20%E2%80%9CDetails%E2%80%9D%20tab%20will%20indicate%20processes%20are%20shadow%20stack%20protected%2C%20and%20whether%20they%20are%20in%20compatibility%20(compatible%20modules%20only)%20or%20strict%20(all%20modules)%20mode.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22TaskMgr.png%22%20style%3D%22width%3A%20611px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257465iC3F558E0B3ADE6FD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22TaskMgr.png%22%20alt%3D%22TaskMgr.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20this%20mitigation%20can%20be%20controlled%20similar%20to%20other%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Fmicrosoft-defender-atp%2Fenable-exploit-protection%23%3A~%3Atext%3DExploit%2520protection%2520helps%2520protect%2520against%2Coperating%2520system%2520or%2520individual%2520apps.%26amp%3Btext%3Dof%2520these%2520methods%253A-%2CWindows%2CMicrosoft%2520Intune%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eexploit%20protections%3C%2FA%3E%2C%20including%20toggling%20the%20enforcement%20using%20the%20Windows%20Defender%20UI%2C%20Group%20Policy%2C%20PowerShell%2C%20and%20other%20facilities.%20Use%26nbsp%3BUserShadowStack%20and%26nbsp%3BUserShadowStackStrictMode%20as%20the%20parameter%20keyword%20to%20manually%20toggle%20enforcement%20in%20compatibility%20and%20strict%20mode%2C%20respectively.%20Use%26nbsp%3BAuditUserShadowStack%20to%20enable%20audit%20mode.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Defender.png%22%20style%3D%22width%3A%20474px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F257466i291F6030236DC302%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Defender.png%22%20alt%3D%22Defender.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-836789623%22%20id%3D%22toc-hId-836789623%22%20id%3D%22toc-hId-836789623%22%20id%3D%22toc-hId-836789623%22%3ERequirements%3C%2FH2%3E%0A%3CP%3EYou%20can%20begin%20building%20and%20testing%20your%20application%20to%20support%20Hardware-enforced%20Stack%20Protection%20today%2C%20by%20ensuring%20you%20have%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHardware%3A%3C%2FSTRONG%3E%2011%3CSUP%3Eth%3C%2FSUP%3E%20Gen%20Intel%20Core%20Mobile%20processors%20and%20AMD%20Zen%203%20Core%20(and%20newer)%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHardware-enforced%20Stack%20Protection%20capable%20OS%3A%3C%2FSTRONG%3E%2019041.622%20or%2019042.622%20and%20newer%20versions%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--970664840%22%20id%3D%22toc-hId--970664840%22%20id%3D%22toc-hId--970664840%22%20id%3D%22toc-hId--970664840%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EWe%20will%20continue%20to%20strive%20towards%20investing%20in%20exploit%20mitigations%20to%20make%20Windows%2010%20the%20most%20secure%20operating%20system.%20These%20mitigations%20will%20help%20proactively%20prohibit%20%3CSPAN%3Ean%20%3C%2FSPAN%3Eattacker%E2%80%99s%20ability%20to%20hijack%20your%20program%20in%20the%20event%20a%20vulnerability%20is%20discovered.%20Note%20in%20the%20current%20release%2C%20this%20mitigation%20is%20only%20supported%20in%2064-bit%20code.%20There%20is%20no%20support%20for%2032-bit%20code%2C%20WoW64%2C%20or%20in%20Guest%20Virtual%20Machines%20at%20the%20moment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fwww.microsoftedgeinsider.com%252Fen-us%252Fdownload%26amp%3Bdata%3D04%257C01%257CJin.Lin%2540microsoft.com%257C6ea88dac734646df8c1908d8d82eafeb%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637497042354575976%257CUnknown%257CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%253D%257C1000%26amp%3Bsdata%3D2Z06IKR5HX9Y%252FoMMWvqwa1%252FyKMIGDHK9LDaRY%252BlXbpQ%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Elatest%20canary%20builds%3C%2FA%3E%20of%20Edge%20(version%2090)%2C%20Hardware-enforced%20Stack%20Protection%20is%20enabled%20in%20compatibility%20mode%20on%20the%20browser%20and%20a%20few%20non-sandboxed%20processes.%20In%20upcoming%20releases%2C%20there%20will%20be%20continued%20investments%20in%20expanding%20the%20list%20of%20processes%20protected%20by%20this%20mitigation.%20Please%20try%20it%20out%20and%20provide%20your%20feedback.%20You%20can%20send%20related%20questions%20to%20%3CA%20href%3D%22mailto%3ACETQuestions%40microsoft.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECETQuestions%40microsoft.com%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EKernel%20Protection%20team%20-%20Jin%20Lin%2C%20Jason%20Lin%2C%20Matthew%20Woolman%3C%2FSTRONG%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-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2163340%22%20slang%3D%22en-US%22%3E%3CP%3EWindows%2010%20implementation%20details%20of%20Hardware-enforced%20Stack%20Protection%2C%20which%20takes%20advantage%20of%20the%20latest%20chipset%20security%20extension%2C%20Control-flow%20Enforcement%20Technology%20(CET).%20This%20blog%20aims%20to%20help%20developers%20better%20understand%20how%20to%20take%20advantage%20of%20this%20feature.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2607839%22%20slang%3D%22zh-CN%22%3EReply%3A%20Developer%20Guidance%20for%20Hardware-enforced%20Protection%20Stack%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2607839%22%20slang%3D%22zh-CN%22%3E%3CP%3EHi%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F565467%22%20target%3D%22_blank%22%3E%40Jin_Lin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EDoes%20HSP%20must%20to%20be%20supported%20in%20Win11%3F%20because%20in%20the%20driver%20HLK%20test%2C%20we%20cannot%20pass%20without%20selected%20%22Y%22.%3C%2FLI%3E%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EthanHunag_0-1628041556027.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300320iEF5B40EE1A6D282A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22EthanHunag_0-1628041556027.png%22%20alt%3D%22EthanHunag_0-1628041556027.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EthanHunag_1-1628041584245.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300321iC8838E138F6697EB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22EthanHunag_1-1628041584245.png%22%20alt%3D%22EthanHunag_1-1628041584245.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLI%3E%3CLI%3EIf%20I%20want%20to%20support%20HSP%2C%20do%20I%20must%20to%20use%20Visual%20Studio%202019%2016.7%20Preview%204%20or%20later%20to%20build%20binary%20(.sys%2C%20.dll%2C%20.exe)%3F%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Mar 09 2021 10:57 AM
Updated by: