SMEP, short for Supervisor Mode Execution Prevention, is a processor feature that makes the CPU raise a fault whenever code running in kernel mode tries to execute instructions from user-mode memory. In OS security it is one of the hardware exploit mitigations that modern operating systems switch on at boot, and it closes a classic route by which attackers turned a kernel bug into full control of the machine.
Intel introduced SMEP with the Ivy Bridge generation in 2012, AMD added it with the Zen architecture, and ARM offers the equivalent Privileged Execute Never (PXN) attribute. Windows, Linux and macOS all enable it automatically on supported hardware, so in operating systems today it works largely unseen.
How SMEP blocks kernel execution of user pages
SMEP works at the level of page-table permissions. Every page table entry on x86 carries a user/supervisor (U/S) bit that marks the page as user-accessible or kernel-only. When SMEP is enabled, an instruction fetch at privilege level 0, 1 or 2 from any page marked as user-accessible triggers a page fault instead of running the code.
The feature is switched on by setting bit 20 of the CR4 control register. The check happens in the processor during address translation, so it adds no measurable performance cost and requires no changes to applications. The kernel only needs to set the bit early in boot and handle the resulting fault as a fatal error.
The table below summarizes the core hardware elements involved in the mechanism.
| Element | Role | Detail |
|---|---|---|
| CR4.SMEP | Global enable switch | Bit 20 of control register CR4 |
| U/S bit | Marks page ownership | Set means the page belongs to user mode |
| Current privilege level | Identifies kernel execution | Rings 0 to 2 count as supervisor mode |
| Page fault (#PF) | Reports the violation | Error code flags an instruction fetch |
| CPUID leaf 7 | Advertises support | Bit 7 of EBX signals SMEP |
The attack that SMEP was designed to stop
SMEP targets the return-to-user (ret2usr) attack. In this technique, an attacker exploits a kernel bug, such as an overwritten function pointer, to redirect kernel execution to shellcode placed in a user-space buffer that the attacker fully controls. Before SMEP, the kernel would happily execute that code with full privileges.
Ret2usr was attractive because it was simple: the attacker did not need to know kernel addresses for the payload, only for the hijacked pointer. With SMEP, the jump into user memory faults immediately, so a single corrupted pointer no longer yields arbitrary code execution, and exploits must become far more elaborate.
SMEP compared with related protections
SMEP is one layer in a defense-in-depth stack of memory protections, and it is easiest to understand next to its neighbors. The following comparison shows what each mitigation prevents.
| Mitigation | What it prevents | Layer |
|---|---|---|
| SMEP | Kernel executing user-mode code | CPU page-table check |
| SMAP | Kernel reading or writing user memory unexpectedly | CPU page-table check |
| NX / executable space protection | Execution of data pages | Page-table execute-disable bit |
| KASLR | Reliable guessing of kernel addresses | Randomized kernel layout |
| Kernel page-table isolation | Leaks of kernel memory to user space | Separate page tables per mode |
| Control-flow integrity | Hijacking of indirect calls and returns | Compiler and hardware checks |
The closest relative is SMAP (Supervisor Mode Access Prevention), controlled by bit 21 of CR4. SMEP covers instruction fetches, while SMAP covers data access, so together they stop the kernel from both running and silently reading attacker-supplied user memory. On ARM, PXN corresponds to SMEP and Privileged Access Never (PAN) corresponds to SMAP.
Support across processors and operating systems
Hardware support for SMEP is now near universal on desktop and server processors, and operating systems enable it by default. The table lists where it appeared and how each platform uses it.
| Platform | Feature | Status |
|---|---|---|
| Intel x86-64 | SMEP | Since Ivy Bridge, 2012 |
| AMD x86-64 | SMEP | Since the Zen architecture |
| ARMv8 and later | PXN | Standard in kernel page tables |
| Windows | SMEP enforcement | Enabled since Windows 8 |
| Linux | SMEP enforcement | Enabled since kernel 3.0 era |
| macOS | SMEP and PXN | Enabled on Intel and Apple silicon |
Administrators can confirm support on Linux by looking for the smep flag in /proc/cpuinfo. Virtual machines inherit SMEP only when the hypervisor exposes the CPUID flag to the guest, which some older or minimal configurations do not do.
Known bypasses and remaining weaknesses
SMEP raises the cost of kernel exploitation but does not make the kernel unexploitable. Attackers responded with techniques that keep execution inside kernel memory or switch the protection off.
| Bypass technique | How it works | Countermeasure |
|---|---|---|
| Kernel ROP chains | Reuses existing kernel code fragments | Control-flow integrity, shadow stacks |
| Clearing CR4.SMEP | ROP gadget writes CR4 without bit 20 | CR4 pinning, hypervisor protection |
| ret2dir | Executes user data through kernel direct mapping | Non-executable direct map |
| Data-only attacks | Changes credentials without running code | Integrity checks, privilege separation |
Modern kernels harden SMEP itself. Linux pins sensitive CR4 bits so that a write clearing them is reverted and reported, and Windows with virtualization-based security lets the hypervisor block changes to control registers. Kernel page-table isolation adds another layer, because user pages are mapped as non-executable in the kernel page tables.
Practical guidance for administrators and developers
- Never disable SMEP with boot parameters such as
nosmepoutside controlled debugging. - Check hypervisor CPU models so that guests receive the SMEP and SMAP flags.
- Treat SMEP faults as exploit indicators in crash dumps rather than as random driver bugs.
- Combine SMEP with SMAP, KASLR and CFI, because each covers a gap the others leave open.
- Audit legacy drivers that call into user memory, as they will crash on SMEP systems.
Stripped to the essentials
Your computer runs two kinds of code: ordinary programs and the operating system core, called the kernel, which has full control. SMEP is a rule built into the processor that says the kernel must never run instructions stored in an ordinary program’s memory.
Imagine a bank vault guard who has been told never to follow written orders slipped under the door by visitors. Even if someone tricks the guard into reading a note, the guard refuses to act on it. SMEP stops attackers from handing their own code to the kernel, so a single software bug is much less likely to become a full takeover.
Where it is applied
A security team at a hosting company runs hundreds of Linux virtual machines for customers who can execute their own programs. A newly disclosed bug in a network driver lets an unprivileged user overwrite a kernel function pointer, and public exploit code points that pointer at a payload in user memory.
On the team’s hosts, the virtual CPU model passes the SMEP and SMAP flags to every guest. When a customer runs the public exploit, the jump into user memory triggers a page fault and a kernel oops instead of granting root access. The monitoring system flags the crash signature, and the team identifies the attempt within minutes.
The team still patches the driver within a day, because a more skilled attacker could build a ROP chain. However, SMEP turned an easy privilege escalation into a contained crash, buying time for the update to roll out safely.