Documentation/translations/zh_CN/dev-tools/kasan.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/dev-tools/kasan.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/dev-tools/kasan.rst- Extension
.rst- Size
- 21401 bytes
- Lines
- 477
- 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
function SANitizer
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/dev-tools/kasan.rst
:Translator: 万家兵 Wan Jiabing <wanjiabing@vivo.com>
内核地址消毒剂(KASAN)
=====================
概述
----
Kernel Address SANitizer(KASAN)是一种动态内存安全错误检测工具,主要功能是
检查内存越界访问和使用已释放内存的问题。
KASAN有三种模式:
1. 通用KASAN
2. 基于软件标签的KASAN
3. 基于硬件标签的KASAN
用CONFIG_KASAN_GENERIC启用的通用KASAN,是用于调试的模式,类似于用户空
间的ASan。这种模式在许多CPU架构上都被支持,但它有明显的性能和内存开销。
基于软件标签的KASAN或SW_TAGS KASAN,通过CONFIG_KASAN_SW_TAGS启用,
可以用于调试和自我测试,类似于用户空间HWASan。这种模式只支持arm64,但其
适度的内存开销允许在内存受限的设备上用真实的工作负载进行测试。
基于硬件标签的KASAN或HW_TAGS KASAN,用CONFIG_KASAN_HW_TAGS启用,被
用作现场内存错误检测器或作为安全缓解的模式。这种模式只在支持MTE(内存标签
扩展)的arm64 CPU上工作,但它的内存和性能开销很低,因此可以在生产中使用。
关于每种KASAN模式的内存和性能影响的细节,请参见相应的Kconfig选项的描述。
通用模式和基于软件标签的模式通常被称为软件模式。基于软件标签的模式和基于
硬件标签的模式被称为基于标签的模式。
支持
----
体系架构
~~~~~~~~
在x86_64、arm、arm64、powerpc、riscv、s390、xtensa和loongarch上支持通用KASAN,
而基于标签的KASAN模式只在arm64上支持。
编译器
~~~~~~
软件KASAN模式使用编译时工具在每个内存访问之前插入有效性检查,因此需要一个
提供支持的编译器版本。基于硬件标签的模式依靠硬件来执行这些检查,但仍然需要
一个支持内存标签指令的编译器版本。
通用KASAN需要GCC 8.3.0版本或更高版本,或者内核支持的任何Clang版本。
基于软件标签的KASAN需要GCC 11+或者内核支持的任何Clang版本。
基于硬件标签的KASAN需要GCC 10+或Clang 12+。
内存类型
~~~~~~~~
通用KASAN支持在所有的slab、page_alloc、vmap、vmalloc、堆栈和全局内存
中查找错误。
基于软件标签的KASAN支持slab、page_alloc、vmalloc和堆栈内存。
基于硬件标签的KASAN支持slab、page_alloc和不可执行的vmalloc内存。
Annotation
- Detected declarations: `function SANitizer`.
- 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.