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.
- A
CALLinstruction 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). - The function runs; an attacker may overwrite the return address on the normal stack through a memory corruption bug.
- The
RETinstruction pops both copies and compares them. - If they differ, the processor raises a control protection exception (
#CPon 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.
| Implementation | Platform | Protection basis | Typical use |
|---|---|---|---|
| Intel CET shadow stack | Intel 11th generation Core and later | Special page type and SSP register | Windows, Linux user and kernel code |
| AMD shadow stack | AMD Zen 3 and later | Same CET instruction set | Windows, Linux |
| Arm GCS | Armv9.4-A processors | Guarded control stack pages | Linux on arm64 |
| Clang ShadowCallStack | AArch64 software | Reserved register x18 and hidden memory | Android kernel and system components |
| Legacy software shadow stacks | Any architecture | Compiler-inserted checks | Research and hardened builds |
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 system | Feature name | Scope | Opt-in marker |
|---|---|---|---|
| Windows 10 and 11 | Hardware-enforced Stack Protection | User-mode processes | /CETCOMPAT linker flag |
| Windows 11 | Kernel-mode Hardware-enforced Stack Protection | Kernel and drivers | Requires virtualization-based security |
| Linux 6.6 and later | User-space shadow stack on x86 | User-mode processes | ELF property SHSTK and glibc support |
| Linux on arm64 | Guarded Control Stack | User-mode processes | ELF property and runtime opt-in |
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.
Shadow stack compared with related mitigations
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.
| Mitigation | What it protects | How it detects or prevents attacks | Main gap |
|---|---|---|---|
| Shadow stack | Return addresses | Compares protected copy at every return | Indirect calls and jumps |
| Stack canary | Stack frame boundary | Checks a secret value before return | Leaked canaries, non-linear writes |
| Indirect branch tracking | Indirect calls and jumps | Requires a landing instruction at targets | Coarse set of valid targets |
| ASLR | Code and data locations | Randomizes addresses | Information leaks |
| Executable space protection | Injected code | Marks data pages non-executable | Code reuse attacks |
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
setjmpandlongjmp, 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.