Shadow stack

Also known as: hardware-enforced stack protection

On this page 7

A shadow stack is a separate, write-protected stack that holds only return addresses, so that the processor or runtime can compare each function return with the address recorded at call time and stop the program on a mismatch. In OS security, it is the main defense of modern operating systems against return-oriented programming (ROP), the exploit technique that overwrites return addresses on the ordinary stack.

The hardware form, often called hardware-enforced stack protection, is implemented by Intel and AMD processors as part of Control-flow Enforcement Technology (CET) and by recent Arm processors as the Guarded Control Stack (GCS). The operating system allocates the shadow stack, marks its pages specially and handles violations, which makes the feature a cooperation between silicon, kernel, compiler and loader.

How a shadow stack protects return addresses

A shadow stack protects return addresses by storing each one twice: once on the normal data stack, where a buffer overflow can corrupt it, and once on the shadow stack, where ordinary memory writes cannot reach it. On every return, the two copies must match.

  1. A CALL instruction pushes the return address onto the normal stack and, at the same time, onto the shadow stack pointed to by the shadow stack pointer (SSP).
  2. The function runs; an attacker may overwrite the return address on the normal stack through a memory corruption bug.
  3. The RET instruction pops both copies and compares them.
  4. If they differ, the processor raises a control protection exception (#CP on x86), and the operating system terminates the process or, in the kernel, halts the system.

The protection depends on a special page type. Shadow stack pages are mapped with a combination of page table bits that ordinary store instructions cannot write, so only CALL, RET and a small set of dedicated shadow stack instructions can change their contents. A stray pointer write therefore faults instead of silently editing the copy.

Hardware and software implementations

Shadow stacks exist in hardware-enforced and compiler-based forms, and they differ mainly in how well the protected copy is isolated. Hardware variants rely on page attributes; software variants rely on keeping the shadow location secret or in a reserved register.

ImplementationPlatformProtection basisTypical use
Intel CET shadow stackIntel 11th generation Core and laterSpecial page type and SSP registerWindows, Linux user and kernel code
AMD shadow stackAMD Zen 3 and laterSame CET instruction setWindows, Linux
Arm GCSArmv9.4-A processorsGuarded control stack pagesLinux on arm64
Clang ShadowCallStackAArch64 softwareReserved register x18 and hidden memoryAndroid kernel and system components
Legacy software shadow stacksAny architectureCompiler-inserted checksResearch and hardened builds
Main shadow stack implementations

Software shadow stacks carry a measurable performance cost and remain vulnerable if an attacker can locate the hidden region. Hardware shadow stacks add near-zero runtime overhead because the comparison happens inside the return instruction itself.

Support in operating systems

Operating system support for shadow stacks requires the kernel to allocate shadow stacks per thread, switch the SSP on context switches and translate violations into crashes or reports. Applications must also be built as compatible, because the loader enables enforcement only for binaries that declare support.

Operating systemFeature nameScopeOpt-in marker
Windows 10 and 11Hardware-enforced Stack ProtectionUser-mode processes/CETCOMPAT linker flag
Windows 11Kernel-mode Hardware-enforced Stack ProtectionKernel and driversRequires virtualization-based security
Linux 6.6 and laterUser-space shadow stack on x86User-mode processesELF property SHSTK and glibc support
Linux on arm64Guarded Control StackUser-mode processesELF property and runtime opt-in
Shadow stack support in desktop operating systems

Windows offers a compatibility mode that tolerates some mismatches in non-compatible modules and a strict mode that terminates the process on any violation. Kernel enforcement on Windows additionally depends on virtualization-based security, because the hypervisor protects the kernel shadow stacks from a compromised kernel.

A shadow stack protects only the backward edge of control flow, meaning returns, so it is deployed alongside mitigations that cover other attack steps. Each neighboring protection has its own page; the comparison shows where the shadow stack fits.

MitigationWhat it protectsHow it detects or prevents attacksMain gap
Shadow stackReturn addressesCompares protected copy at every returnIndirect calls and jumps
Stack canaryStack frame boundaryChecks a secret value before returnLeaked canaries, non-linear writes
Indirect branch trackingIndirect calls and jumpsRequires a landing instruction at targetsCoarse set of valid targets
ASLRCode and data locationsRandomizes addressesInformation leaks
Executable space protectionInjected codeMarks data pages non-executableCode reuse attacks
Shadow stack and neighboring exploit mitigations

The combination matters. Executable space protection forces attackers toward code reuse, ASLR makes reuse harder to aim, and the shadow stack together with forward-edge control-flow integrity blocks the chains of reused code fragments that ROP depends on.

Limitations and compatibility pitfalls

Shadow stacks break any code that manipulates return addresses deliberately, which is why enforcement is opt-in per binary. Most failures appear in runtimes and low-level libraries rather than in ordinary application logic.

  • Non-local jumps such as setjmp and longjmp, C++ exception unwinding and coroutines must adjust the SSP with dedicated instructions, or they trigger false violations.
  • Just-in-time compilers and older anti-cheat or DRM code that rewrite return addresses need updates before enabling the feature.
  • One incompatible module loaded into a process can force compatibility mode or a crash in strict mode.
  • Shadow stacks do not stop data-only attacks, which change variables without hijacking control flow.
  • Protection is only as strong as the kernel that manages it; a kernel exploit can disable user-mode enforcement unless the kernel itself is protected.

In everyday language

When a program calls a function, it writes down where to come back afterward, much like leaving a bookmark. Attackers who find a bug can secretly move that bookmark so the program jumps into their chosen code.

A shadow stack keeps a second bookmark in a locked drawer that normal program code cannot open. Every time the program returns, the processor checks that both bookmarks agree. If someone moved the visible one, the mismatch stops the program before any harm is done.

Seen in the real world

A browser vendor ships a Windows build compiled with the /CETCOMPAT flag. On laptops with recent Intel or AMD processors, Windows enables hardware-enforced stack protection for the browser process automatically. Months later, security researchers report a heap overflow in the image decoder that lets a crafted web page overwrite a return address and start a ROP chain.

On machines without CET support, the proof-of-concept exploit runs code successfully. On protected machines, the first corrupted RET raises a control protection exception, and the tab crashes instead of executing the payload. The outcome: the vulnerability still needs a patch, but the shadow stack turns a remote code execution flaw into a crash for most users while the fix is prepared.