SMEP

Also known as: Supervisor Mode Execution Prevention

On this page 8

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.

ElementRoleDetail
CR4.SMEPGlobal enable switchBit 20 of control register CR4
U/S bitMarks page ownershipSet means the page belongs to user mode
Current privilege levelIdentifies kernel executionRings 0 to 2 count as supervisor mode
Page fault (#PF)Reports the violationError code flags an instruction fetch
CPUID leaf 7Advertises supportBit 7 of EBX signals SMEP
Hardware elements of SMEP on x86

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 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.

MitigationWhat it preventsLayer
SMEPKernel executing user-mode codeCPU page-table check
SMAPKernel reading or writing user memory unexpectedlyCPU page-table check
NX / executable space protectionExecution of data pagesPage-table execute-disable bit
KASLRReliable guessing of kernel addressesRandomized kernel layout
Kernel page-table isolationLeaks of kernel memory to user spaceSeparate page tables per mode
Control-flow integrityHijacking of indirect calls and returnsCompiler and hardware checks
SMEP and neighboring kernel mitigations

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.

PlatformFeatureStatus
Intel x86-64SMEPSince Ivy Bridge, 2012
AMD x86-64SMEPSince the Zen architecture
ARMv8 and laterPXNStandard in kernel page tables
WindowsSMEP enforcementEnabled since Windows 8
LinuxSMEP enforcementEnabled since kernel 3.0 era
macOSSMEP and PXNEnabled on Intel and Apple silicon
Platform support for SMEP and equivalents

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 techniqueHow it worksCountermeasure
Kernel ROP chainsReuses existing kernel code fragmentsControl-flow integrity, shadow stacks
Clearing CR4.SMEPROP gadget writes CR4 without bit 20CR4 pinning, hypervisor protection
ret2dirExecutes user data through kernel direct mappingNon-executable direct map
Data-only attacksChanges credentials without running codeIntegrity checks, privilege separation
Bypass techniques and countermeasures

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 nosmep outside 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.