SMAP, short for Supervisor Mode Access Prevention, is a processor feature that makes the CPU raise a fault whenever code running in kernel (supervisor) mode reads or writes memory pages marked as user pages, unless the kernel has deliberately and temporarily allowed such access. In OS security it is a hardware-enforced exploit mitigation that removes a favorite trick of kernel attackers: placing fake data structures in user memory and tricking the kernel into using them.
Intel introduced SMAP with the Broadwell generation in 2014, and AMD added it with the Zen microarchitecture in 2017. It is the data-access counterpart of SMEP, which blocks the kernel from executing user pages, and the two are normally enabled together in modern operating systems.
How SMAP blocks kernel access to user pages
SMAP works by adding a check to every data access performed at privilege level 0, 1 or 2. The page tables already carry a user/supervisor (U/S) bit for each page; when SMAP is active and the CPU is in supervisor mode, a load or store that touches a page with the U/S bit set produces a page fault, even though the page is present and writable.
Kernels still need to copy data to and from user programs, for example when handling a read() system call. For that reason SMAP has a deliberate escape hatch: when the AC flag (alignment check, bit 18 of EFLAGS) is set, explicit supervisor accesses to user pages are permitted. Two dedicated instructions, STAC (set AC) and CLAC (clear AC), open and close this window, and they can only be executed in supervisor mode.
The following table summarizes how the processor decides whether a supervisor-mode data access to a user page is allowed.
| Condition | CR4.SMAP | EFLAGS.AC | Result |
|---|---|---|---|
| Explicit access to a user page | 0 | Any | Allowed |
| Explicit access to a user page | 1 | 0 | Page fault |
| Explicit access to a user page | 1 | 1 | Allowed |
| Implicit access to a user page | 1 | Any | Page fault |
| Access to a supervisor page | Any | Any | Allowed by SMAP |
Implicit accesses, such as the CPU reading a descriptor table on behalf of the kernel, are checked regardless of the AC flag. This prevents an attacker from relocating system structures into user memory and having the processor consume them silently.
Processor support and control bits
SMAP is enumerated through CPUID leaf 7, EBX bit 20 and switched on through bit 21 of the CR4 control register. Because only the kernel can write CR4, a user program cannot disable the feature, and a kernel that never sets the bit gains no protection at all.
Other architectures provide the same guarantee under different names, which is useful when comparing platforms.
| Architecture | Feature name | Introduced | Temporary override |
|---|---|---|---|
| x86-64 (Intel) | SMAP | Broadwell, 2014 | STAC and CLAC |
| x86-64 (AMD) | SMAP | Zen, 2017 | STAC and CLAC |
| Arm | PAN (Privileged Access Never) | Armv8.1-A | PSTATE.PAN toggle or unprivileged load/store |
| RISC-V | SUM bit in sstatus | Privileged specification | Set SUM to permit access |
The semantics are slightly different on RISC-V: access to user memory from supervisor mode is forbidden by default and is permitted only while the SUM bit is set, so the protection is the normal state rather than an optional extra.
SMAP compared with SMEP and related mitigations
SMAP is one layer of a defense-in-depth stack for the kernel, and each layer targets a different exploitation step. It is most often confused with SMEP, which blocks instruction fetches from user pages, while SMAP blocks data reads and writes.
| Mitigation | What it prevents | Attack step it disrupts |
|---|---|---|
| SMEP | Kernel executing code in user pages | Jumping to attacker shellcode |
| SMAP | Kernel reading or writing user pages | Using fake objects or ROP stacks in user memory |
| KASLR | Predictable kernel addresses | Locating gadgets and data |
| Kernel page-table isolation | User mappings of kernel memory | Meltdown-style leaks |
| Control-flow integrity | Illegal indirect branch targets | Hijacking function pointers |
Without SMAP, an attacker who corrupts a kernel pointer can simply point it at a crafted structure in user space, such as a fake function table or a pivoted stack for return-oriented programming. With SMAP, the attacker must first find a way to place controlled data at a known kernel address, which is considerably harder, especially when combined with KASLR.
How operating systems use SMAP
A kernel that enables SMAP must route every legitimate user-memory access through a small set of audited helper functions. In Linux, which gained SMAP support in version 3.7 (2012), functions such as copy_from_user(), copy_to_user() and get_user() execute STAC before the copy and CLAC immediately afterward, and the user_access_begin() interface groups several accesses into one short window.
Keeping that window as short as possible is a central design rule. Linux build-time tooling (objtool) warns when a function call occurs while AC is set, because an unexpected call could let attacker-influenced code run with user access open. FreeBSD and other kernels follow the same pattern, and Apple platforms rely on the Arm PAN equivalent.
- Detect support through CPUID and set CR4.SMAP early during boot.
- Wrap all user copies in STAC and CLAC, and never leave AC set across function calls.
- Save and restore AC on interrupts and exceptions so a handler never inherits an open window.
- Treat SMAP faults as bugs or attacks: kernels log an oops or crash rather than retrying.
The performance cost is small: STAC and CLAC take only a few cycles each and run only around user copies, so typical workloads see no measurable slowdown. Support and enforcement still differ between operating systems and versions, and some kernels have enabled it more selectively than Linux.
Limitations and known bypass techniques
SMAP is not a complete defense against kernel exploitation. It removes one convenient technique, but attackers with a memory-corruption bug have developed ways to work around it, and administrators should understand them when assessing real risk.
| Bypass technique | How it works | Countermeasure |
|---|---|---|
| Physmap aliasing (ret2dir) | User pages also appear in the kernel direct map | Restricting or randomizing the direct map |
| Clearing CR4.SMAP | ROP chain writes CR4 to disable the bit | CR4 bit pinning in Linux since 5.3 |
| Gadget that sets AC | Reused STAC sequences open the window | Objtool checks and control-flow integrity |
| Kernel heap spraying | Fake objects placed in kernel memory instead | Hardened allocators and heap randomization |
Another limitation is that SMAP does nothing for bugs inside the copy helpers themselves, for example a missing length check in a driver that calls copy_from_user() correctly but with a wrong size. Such flaws are memory-safety bugs in their own right and require code review, fuzzing and bounds checking. Virtual machines also need the hypervisor to expose the CPUID bit to the guest, otherwise the guest kernel silently runs without SMAP.
In everyday language
Think of the operating system kernel as a bank clerk and user programs as customers. Customers hand items across the counter, and the clerk needs to look at them sometimes. SMAP is a rule that says the clerk may only touch customer items through a supervised slot, opened for a moment and closed again.
If a dishonest customer slips a forged form onto the clerk’s desk and hopes it gets processed, the rule stops it, because the clerk is not allowed to pick up customer papers outside that slot. The computer refuses the action and reports an error instead of being fooled.
Seen in the real world
A security team at a hosting company reviews a published proof-of-concept for a use-after-free bug in a Linux network driver. The exploit replaces a freed kernel object with a pointer to a fake structure in user memory, then waits for the kernel to call a function pointer inside it.
On older test servers without SMAP, the proof-of-concept gains root privileges in seconds. On current servers with SMEP and SMAP enabled, the kernel touches the fake structure, the CPU raises a page fault, and the system logs a kernel oops naming the faulting address. The attack fails and leaves forensic evidence, giving the team time to apply the driver patch during the next maintenance window.