Documentation/translations/zh_CN/security/self-protection.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/security/self-protection.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/security/self-protection.rst- Extension
.rst- Size
- 12418 bytes
- Lines
- 272
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/security/self-protection.rst
:翻译:
张巍 zhangwei <zhangwei@cqsoftware.com.cn>
============
内核自我保护
============
内核自我保护是指在Linux内核中设计与实现的各种系统与结构
以防止内核本身的安全漏洞问题。它涵盖了广泛问题,包括去除
整个类的漏洞,阻止安全漏洞利用方法,以及主动检测攻击尝
试。并非所有的话题都在本文中涉及,但它应该为了解内核自我
保护提供一个合理的起点,并解答常见的问题。(当然,欢迎提
交补丁!)
在最坏的情况下,我们假设一个非特权的本地攻击者对内核内存
有任意读写访问权限。虽然在许多情况下,漏洞被利用时并不会
提供此级别的访问权限,但如果我们能防御最坏情况,也能应对
权限较低的攻击。一个更高的标准,且需要牢记的是保护内核免
受具有特权的本地攻击者的攻击,因为root用户可以有更多权限。
(尤其是当他们能够加载任意内核模块时)
成功的自我保护的目标是:有效、默认开启、不需要开发者主动
选择、没有性能影响、不妨碍内核调试、并且没有测试。虽然很
难满足所有的这些目标,但明确提到这些目标非常重要,因为这
些方面需要被探索、解决或接受。
==========
攻击面缩减
==========
防止安全漏洞最基本的防御方式是减少可以被用来重定向执行的
内核区域。这包括限制用户公开使用的API、使内核API更难被错
误使用、最小化可写内核内存区域等。
严格的内核内存权限
-------------------
当所有内核内存都是可写的,攻击者可以轻松地重定向执行流。
为了减少这种攻击目标的可用性,内核需要更严格的权限集来
保护其内存。
可执行代码和只读数据必须不可写
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
任何具有可执行内存的区域必须不可写,显然这也包括内核文本
本身。我们还必须考虑其他地方:内核模块、JIT内存等,(在
某些情况下,为了支持像指令替代、断点、kprobes等功能,这些
区域会暂时被设置为可写。如果这些功能必须存在于内核中,它
们的实现方式是:在更新期间将内存临时设置可写,然后再恢复
为原始权限。)
为了支持这一点,CONFIG_STRICT_KERNEL_RWX 和
CONFIG_STRICT_MODULE_RWX 的设计旨在确保代码不可写,数据不
可执行,以及只读数据既不可写也不可执行。
大多数架构默认支持这些选项,且用户无法选择。对于一些像arm
这种希望能够选择这些选项的架构,可以在架构Kconfig中选择
ARCH_OPTIONAL_KERNEL_RWX以启用Kconfig提示。
CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT决定在启用
ARCH_OPTIONAL_KERNEL_RWX时的默认设置。
函数指针和敏感变量必须不可写
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
内核内存中有大量的函数指针,这些指针被内核查找并用于继续执行
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.