Documentation/translations/zh_TW/dev-tools/kasan.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_TW/dev-tools/kasan.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_TW/dev-tools/kasan.rst- Extension
.rst- Size
- 20605 bytes
- Lines
- 461
- 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_TW.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.