# 监管模式访问保护

**监管模式访问保护**（SMAP）是 x86 处理器的一种安全特性：当内核特权代码（CPL < 3）读取或写入页表中标记为用户模式的页面时，除非内核已为该访问在 EFLAGS 中显式设置 AC（对齐检查）标志，否则会触发缺页异常。它补充了监管模式执行保护（SMEP），后者阻止内核执行用户模式页面；它也是 Arm 的特权访问禁止（PAN）和 RISC-V 的 SUM 在 x86 上的对应机制。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup><sup> • </sup><sup>[2](https://man.freebsd.org/cgi/man.cgi?apropos=0&manpath=FreeBSD+15.0-RELEASE+and+Ports&query=mitigations&sektion=7)</sup>

| 关键事实 | 详情 |
|---|---|
| 控制位 | 通过设置 CR4.SMAP 逐处理器启用；强制执行依据分页结构项中的 U/S（用户/监管）位<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup><sup> • </sup><sup>[3](https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/smap.h)</sup> |
| 覆盖机制 | 当 SMAP 生效且 EFLAGS.AC = 0 时，监管模式对用户模式地址的显式数据访问会触发异常；设置 AC 则允许这类访问。隐式监管模式访问（例如描述符表加载）无论 AC 如何都会触发异常<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup> |
| 切换指令 | STAC 设置 AC 标志，CLAC 清除 AC 标志；两者被加入 x86 指令集，使标志操作快到足以按每次访问使用<sup>[4](https://lkml.indiana.edu/1209.2/03295.html)</sup> |
| 厂商支持 | 在 Intel 64 与 IA-32 架构以及 AMD64 架构中均有定义（后者规定了相同的 RFLAGS.AC 行为和 CLAC/STAC 抑制）<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup><sup> • </sup><sup>[5](https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf)</sup> |
| 操作系统采用 | Linux 在 v3.7（2012 年）合并支持，并在可能时自动启用；OpenBSD 在 5.3 中加入；FreeBSD 在 2018 年将其加入 amd64<sup>[6](https://lkml.rescloud.iu.edu/hypermail/linux/kernel/1210.0/00382.html)</sup><sup> • </sup><sup>[7](https://www.openbsd.org/53.html)</sup><sup> • </sup><sup>[8](https://www.freebsd.org/status/report-2018-01-2018-09.html)</sup> |
| 防范对象 | 内核通过被破坏的指针读取或写入用户控制的数据，阻止在用户内存中伪造数据结构或栈的利用<sup>[9](https://www.usenix.org/system/files/usenixsecurity25-miller.pdf)</sup> |
| 禁用途径 | Linux 的 `nosmap` 启动参数即使处理器支持 SMAP 也会将其禁用<sup>[10](https://www.kernel.org/doc/html/v5.17/admin-guide/kernel-parameters.html)</sup> |

## 架构行为

Intel SDM 将每次对线性地址的访问归类为监管模式访问或用户模式访问。对于取指和大多数数据访问，当前特权级决定：CPL < 3 的访问为监管模式，CPL = 3 的访问为用户模式。某些操作，例如从 GDT 或 LDT 加载段描述符、通过 IDT 传递中断，以及触及 TSS 的任务切换，无论 CPL 如何都属于隐式监管模式访问。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup>

地址本身是否为用户模式由分页决定：如果在控制地址转换的任一分页结构项中 U/S 标志（第 2 位）为 0，该地址就是监管模式地址；否则它是用户模式地址。当 CR4.SMAP = 1 时，监管模式对用户模式地址的数据访问只有在 EFLAGS.AC = 1 且该访问为显式访问时才被允许。对用户模式地址的隐式监管模式访问无论 AC 如何都会触发异常。当 CR4.SMAP = 0 时，适用 SMAP 之前的规则，监管代码可以在受保护键约束的情况下读取或写入用户模式地址。<sup>[1](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)</sup>

AMD64 架构手册规定了相同策略：在支持并启用 SMAP 且 RFLAGS.AC = 0 时，监管模式下从用户模式可访问页面尝试显式数据访问会触发缺页异常（#PF），保护系统软件不使用可能已被用户模式代码修改的数据。需要此类访问的监管软件可以使用 CLAC 和 STAC 指令修改 RFLAGS.AC，临时抑制这些检查。<sup>[5](https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf)</sup>

## STAC 与 CLAC

由于合法内核确实会在用户空间与内核之间复制数据，SMAP 需要一种低成本的按次访问覆盖机制。启用 SMAP 时，内核访问用户空间由 AC 标志控制，而引入 STAC（设置 AC）和 CLAC（清除 AC）指令是为了让该标志的操作具有良好性能。[Linux 内核](https://www.edgepedia.org/zh/linux-kernel) x86 开发者 H·彼得·安文（H. Peter Anvin）于 2012 年 9 月通过替代指令机制将这些指令加入 Linux，因此只有当 SMAP 特性存在时指令才会出现在代码中；系统调用入口路径还会无条件清除 AC，使内核模式一开始就禁止访问用户空间。<sup>[4](https://lkml.indiana.edu/1209.2/03295.html)</sup>

在 Linux 内核中，当 CPU 枚举到 SMAP（特性位 X86_FEATURE_SMAP）时，`stac()` 和 `clac()` 内联辅助函数会展开为这些指令；同一组辅助函数还会为较新的线性地址空间隔离（LASS）特性切换强制执行。内核注释直接说明了规则：SMAP 强制执行基于页表中的 `_PAGE_BIT_USER` 位，除非 AC 位置位，否则内核不得触及设置了该位的页面。<sup>[3](https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/smap.h)</sup> `smap_save()` 和 `smap_restore()` 等辅助例程在必须触及用户内存的区域前后保存标志并清除 AC，然后再恢复标志。<sup>[3](https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/smap.h)</sup>

## 操作系统支持

**Linux。** x86/smap 分支于 2012 年 10 月被合入 v3.7 内核发布，被描述为一种硬件支持，可防止内核特权代码意外访问用户空间数据，并在可能时自动开启；合并说明指出，它与 SMEP 结合后，使利用空指针解引用等内核缺陷变得更加困难。SMAP 触发的缺页异常会被视为 oops，因为来自内核模式的此类异常表明存在缺陷。<sup>[6](https://lkml.rescloud.iu.edu/hypermail/linux/kernel/1210.0/00382.html)</sup>

**BSD 系统。** OpenBSD 在 5.3 版本中为 i386 和 amd64 加入对 Intel SMEP 和 SMAP 特性的支持。<sup>[7](https://www.openbsd.org/53.html)</sup> FreeBSD 于 2018 年将 SMAP 加入 amd64 内核，FreeBSD 提交者康斯坦丁·别洛乌索夫（Konstantin Belousov）是该项目的联系人。该实现使用 ifunc 框架，使运行时代码在每次调用 `copyout(9)` 及类似函数时不必检查 SMAP 能力。由于 FreeBSD amd64 在内核与用户之间共享一个地址空间，启用 SMAP 实际上会将其拆分为两个具有不同访问标准的互不相交空间：任何在 `copyout(9)` 系列之外由内核直接访问用户内存的行为都表明可能存在编程错误。报告指出，启用 SMAP 后发现的缺陷非常少；一个问题出现在 pci(9) 用户驱动中，并且发现 VBox 和 acpi_call 移植版会不安全地访问用户空间。<sup>[8](https://www.freebsd.org/status/report-2018-01-2018-09.html)</sup> FreeBSD 的 mitigations(7) 手册页将 SMAP 列为防止读/写访问，将 SMEP 列为防止执行，二者由内核自动应用，无需面向用户的配置，同时还列出 arm64 的 PAN/PXN 和 riscv 的 SUM 等等价机制。<sup>[2](https://man.freebsd.org/cgi/man.cgi?apropos=0&manpath=FreeBSD+15.0-RELEASE+and+Ports&query=mitigations&sektion=7)</sup>

## 安全作用与推测执行

SMAP 的主要目标是针对一种利用模式：攻击者诱使内核读取位于用户控制内存中的伪造数据结构或栈，例如通过被破坏的指针链。SMAP 生效时，任何未经显式 STAC 的内核从用户模式页面读取都会触发异常，因此内核无法以这种方式被欺骗去使用攻击者构造的数据。<sup>[9](https://www.usenix.org/system/files/usenixsecurity25-miller.pdf)</sup><sup> • </sup><sup>[11](https://github.com/AmesianX/kernelsight/blob/main/docs/mitigations/smep-smap.md)</sup>

该特性还与瞬态执行攻击相互作用。根据 Intel 的安全指南，SMAP 可以通过阻止分配应用缓存行来限制缓存侧信道可用的内存地址，从而使应用更难对内核实施攻击。在同时缓解恶意数据缓存加载（IA32_ARCH_CAPABILITIES[RDCL_NO]）并支持 SMAP 的 Intel 处理器上，因 SMAP 而触发异常的加载即使在 L1D 缓存命中时也不会推测性返回所加载的数据，并且不会为该地址填充或逐出缓存。在支持 SMAP 但不支持 RDCL_NO 的处理器上，此类加载在 L1D 命中时可能推测性返回数据，但仍不会为该地址填充或逐出缓存。SMAP 生效时，用户模式数据也不能参与内核模式泄露小工具。<sup>[12](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/hardware-behavior-related-to-speculative-execution.html)</sup>

较新的线性地址空间隔离（LASS）特性补充了 SMAP：它防止用户模式代码为监管地址引发页表遍历和 TLB 填充，否则这些行为可能泄露哪些监管地址已映射并破坏 KASLR；当 SMAP 启用且有效时，它也对监管代码访问用户模式地址施加类似限制。<sup>[12](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/hardware-behavior-related-to-speculative-execution.html)</sup>

## 绕过与限制

SMAP 是一种边界检查，而非完整防御，已公开的技术通过多种方式绕过它：

- **物理内存映射别名。** Linux 内核将所有物理内存映射到已知的内核虚拟区域（physmap）。能够定位用户控制页面的物理内存映射别名的攻击者，可以让内核通过监管模式地址读取攻击者数据，从而完全绕过 SMAP；ret2dir 技术曾利用这种别名攻击 SMEP，而同样的恒等映射也能击败 SMAP。<sup>[9](https://www.usenix.org/system/files/usenixsecurity25-miller.pdf)</sup><sup> • </sup><sup>[13](https://www.nccgroup.com/research/xen-smep-and-smap-bypass/)</sup>
- **控制寄存器与标志操纵。** 早期绕过使用 ROP 链覆写 CR4 并清除 SMEP 或 SMAP 位；现代内核固定安全关键的 CR4 位，而 VBS/HVCI 等基于管理程序的保护会捕获 CR4 写入。在没有硬件影子栈的系统上，拥有栈控制权的攻击者可以通过 ROP 跳转到 STAC 小工具来设置 AC；kCET 等控制流强制执行会在小工具运行前检测返回地址篡改。<sup>[11](https://github.com/AmesianX/kernelsight/blob/main/docs/mitigations/smep-smap.md)</sup>
- **PTE 重映射。** 拥有任意读/写原语的攻击者可以清除用户页面页表项中的 U/S 位，使 CPU 将其归类为监管页面，从而同时绕过 SMEP 和 SMAP；这在当前系统上仍然可行。<sup>[11](https://github.com/AmesianX/kernelsight/blob/main/docs/mitigations/smep-smap.md)</sup>
- **纯数据攻击。** 修改凭证令牌或安全描述符等内核数据结构的利用从不跨越用户/内核内存边界，因此 SMAP 和 SMEP 与它们无关；这种方法在现代利用中已占据主导地位。<sup>[11](https://github.com/AmesianX/kernelsight/blob/main/docs/mitigations/smep-smap.md)</sup>

SMAP 强制执行本身也出现过实现缺陷。FreeBSD CVE-2021-29628 允许在系统调用期间绕过 SMAP 的保护，可能导致在 FreeBSD 12.2 及更高版本上添加或修改数据。<sup>[14](https://notcve.org/cve/CVE-2021-29628)</sup> Linux 同样修复了启用 SMAP 的 futex 例程在禁用 SMAP 之前解引用用户指针的问题。<sup>[15](https://reviews.freebsd.org/D30276)</sup>

## References

1. [Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 3: System Programming Guide, Section 4.6.1 (Determination of Access Rights)](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf)
2. [mitigations(7), FreeBSD 15.0-RELEASE manual page](https://man.freebsd.org/cgi/man.cgi?apropos=0&manpath=FreeBSD+15.0-RELEASE+and+Ports&query=mitigations&sektion=7)
3. [linux/arch/x86/include/asm/smap.h, torvalds/linux on GitHub](https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/smap.h)
4. [tip-bot for H. Peter Anvin: x86, smap: Add STAC and CLAC instructions to control user space access, Linux-Kernel Archive (September 2012)](https://lkml.indiana.edu/1209.2/03295.html)
5. [AMD64 Architecture Programmer's Manual, Volume 2: System Programming (Page Translation and Protection)](https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf)
6. [Ingo Molnar: [GIT PULL] x86/smap changes for v3.7, Linux-Kernel Archive (October 2012)](https://lkml.rescloud.iu.edu/hypermail/linux/kernel/1210.0/00382.html)
7. [OpenBSD 5.3 release page](https://www.openbsd.org/53.html)
8. [FreeBSD Quarterly Status Report, January–September 2018: SMAP](https://www.freebsd.org/status/report-2018-01-2018-09.html)
9. [System Register Hijacking: Exploiting Kernel-Only System Registers, USENIX Security 2025](https://www.usenix.org/system/files/usenixsecurity25-miller.pdf)
10. [The kernel's command-line parameters, Linux kernel documentation (nosmap)](https://www.kernel.org/doc/html/v5.17/admin-guide/kernel-parameters.html)
11. [SMEP/SMAP mitigations and bypasses, kernelsight documentation on GitHub](https://github.com/AmesianX/kernelsight/blob/main/docs/mitigations/smep-smap.md)
12. [Hardware Features and Behaviors Related to Speculative Execution, Intel Software Security Guidance](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/hardware-behavior-related-to-speculative-execution.html)
13. [Xen SMEP & SMAP Bypass Technique Analysis, NCC Group](https://www.nccgroup.com/research/xen-smep-and-smap-bypass/)
14. [CVE-2021-29628: SMAP bypass (FreeBSD)](https://notcve.org/cve/CVE-2021-29628)
15. [D30276 linux: Fix SMAP-enabled futex routines, FreeBSD code review](https://reviews.freebsd.org/D30276)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › 处理器与处理器工程 › 指令集架构 › CPU运行模式与ISA支持机制

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/supervisor-mode-access-prevention

English original: https://www.edgepedia.org/supervisor-mode-access-prevention
