sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget#/translations/zh_CN/dev-tools/kasanmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/zh_TW/dev-tools/kasanmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/it_IT/dev-tools/kasanmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/ja_JP/dev-tools/kasanmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/ko_KR/dev-tools/kasanmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget#/translations/sp_SP/dev-tools/kasanmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh=/var/lib/git/docbuild/linux/Documentation/dev-tools/kasan.rsthKubh)}(hCopyright (C) 2023, Google LLC.h]hCopyright (C) 2023, Google LLC.}hhsbah}(h]h ]h"]h$]h&]hhuh1hhhhhhhhKubhsection)}(hhh](htitle)}(h Kernel Address Sanitizer (KASAN)h]h Kernel Address Sanitizer (KASAN)}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hOverviewh]hOverview}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hKernel Address Sanitizer (KASAN) is a dynamic memory safety error detector designed to find out-of-bounds and use-after-free bugs.h]hKernel Address Sanitizer (KASAN) is a dynamic memory safety error detector designed to find out-of-bounds and use-after-free bugs.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hKASAN has three modes:h]hKASAN has three modes:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubhenumerated_list)}(hhh](h list_item)}(h Generic KASANh]h)}(hjh]h Generic KASAN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubj )}(hSoftware Tag-Based KASANh]h)}(hj&h]hSoftware Tag-Based KASAN}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$ubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubj )}(hHardware Tag-Based KASAN h]h)}(hHardware Tag-Based KASANh]hHardware Tag-Based KASAN}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj;ubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jhhhhhhhKubh)}(hGeneric KASAN, enabled with CONFIG_KASAN_GENERIC, is the mode intended for debugging, similar to userspace ASan. This mode is supported on many CPU architectures, but it has significant performance and memory overheads.h]hGeneric KASAN, enabled with CONFIG_KASAN_GENERIC, is the mode intended for debugging, similar to userspace ASan. This mode is supported on many CPU architectures, but it has significant performance and memory overheads.}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hX4Software Tag-Based KASAN or SW_TAGS KASAN, enabled with CONFIG_KASAN_SW_TAGS, can be used for both debugging and dogfood testing, similar to userspace HWASan. This mode is only supported for arm64, but its moderate memory overhead allows using it for testing on memory-restricted devices with real workloads.h]hX4Software Tag-Based KASAN or SW_TAGS KASAN, enabled with CONFIG_KASAN_SW_TAGS, can be used for both debugging and dogfood testing, similar to userspace HWASan. This mode is only supported for arm64, but its moderate memory overhead allows using it for testing on memory-restricted devices with real workloads.}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXQHardware Tag-Based KASAN or HW_TAGS KASAN, enabled with CONFIG_KASAN_HW_TAGS, is the mode intended to be used as an in-field memory bug detector or as a security mitigation. This mode only works on arm64 CPUs that support MTE (Memory Tagging Extension), but it has low memory and performance overheads and thus can be used in production.h]hXQHardware Tag-Based KASAN or HW_TAGS KASAN, enabled with CONFIG_KASAN_HW_TAGS, is the mode intended to be used as an in-field memory bug detector or as a security mitigation. This mode only works on arm64 CPUs that support MTE (Memory Tagging Extension), but it has low memory and performance overheads and thus can be used in production.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hFor details about the memory and performance impact of each KASAN mode, see the descriptions of the corresponding Kconfig options.h]hFor details about the memory and performance impact of each KASAN mode, see the descriptions of the corresponding Kconfig options.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK"hhhhubh)}(hThe Generic and the Software Tag-Based modes are commonly referred to as the software modes. The Software Tag-Based and the Hardware Tag-Based modes are referred to as the tag-based modes.h]hThe Generic and the Software Tag-Based modes are commonly referred to as the software modes. The Software Tag-Based and the Hardware Tag-Based modes are referred to as the tag-based modes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hhhhubeh}(h]overviewah ]h"]overviewah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hSupporth]hSupport}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK*ubh)}(hhh](h)}(h Architecturesh]h Architectures}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK-ubh)}(hGeneric KASAN is supported on x86_64, arm, arm64, powerpc, riscv, s390, xtensa, and loongarch, and the tag-based KASAN modes are supported only on arm64.h]hGeneric KASAN is supported on x86_64, arm, arm64, powerpc, riscv, s390, xtensa, and loongarch, and the tag-based KASAN modes are supported only on arm64.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjhhubeh}(h] architecturesah ]h"] architecturesah$]h&]uh1hhjhhhhhK-ubh)}(hhh](h)}(h Compilersh]h Compilers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK3ubh)}(hXJSoftware KASAN modes use compile-time instrumentation to insert validity checks before every memory access and thus require a compiler version that provides support for that. The Hardware Tag-Based mode relies on hardware to perform these checks but still requires a compiler version that supports the memory tagging instructions.h]hXJSoftware KASAN modes use compile-time instrumentation to insert validity checks before every memory access and thus require a compiler version that provides support for that. The Hardware Tag-Based mode relies on hardware to perform these checks but still requires a compiler version that supports the memory tagging instructions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK5hjhhubh)}(h_Generic KASAN requires GCC version 8.3.0 or later or any Clang version supported by the kernel.h]h_Generic KASAN requires GCC version 8.3.0 or later or any Clang version supported by the kernel.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hjhhubh)}(hWSoftware Tag-Based KASAN requires GCC 11+ or any Clang version supported by the kernel.h]hWSoftware Tag-Based KASAN requires GCC 11+ or any Clang version supported by the kernel.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubh)}(h7Hardware Tag-Based KASAN requires GCC 10+ or Clang 12+.h]h7Hardware Tag-Based KASAN requires GCC 10+ or Clang 12+.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjhhubeh}(h] compilersah ]h"] compilersah$]h&]uh1hhjhhhhhK3ubh)}(hhh](h)}(h Memory typesh]h Memory types}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj5hhhhhKDubh)}(hhGeneric KASAN supports finding bugs in all of slab, page_alloc, vmap, vmalloc, stack, and global memory.h]hhGeneric KASAN supports finding bugs in all of slab, page_alloc, vmap, vmalloc, stack, and global memory.}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKFhj5hhubh)}(hNSoftware Tag-Based KASAN supports slab, page_alloc, vmalloc, and stack memory.h]hNSoftware Tag-Based KASAN supports slab, page_alloc, vmalloc, and stack memory.}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKIhj5hhubh)}(hVHardware Tag-Based KASAN supports slab, page_alloc, and non-executable vmalloc memory.h]hVHardware Tag-Based KASAN supports slab, page_alloc, and non-executable vmalloc memory.}(hjbhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhj5hhubh)}(hxFor slab, both software KASAN modes support SLUB and SLAB allocators, while Hardware Tag-Based KASAN only supports SLUB.h]hxFor slab, both software KASAN modes support SLUB and SLAB allocators, while Hardware Tag-Based KASAN only supports SLUB.}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhj5hhubeh}(h] memory-typesah ]h"] memory typesah$]h&]uh1hhjhhhhhKDubeh}(h]supportah ]h"]supportah$]h&]uh1hhhhhhhhK*ubh)}(hhh](h)}(hUsageh]hUsage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKRubh)}(h,To enable KASAN, configure the kernel with::h]h+To enable KASAN, configure the kernel with:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjhhubh literal_block)}(hCONFIG_KASAN=yh]hCONFIG_KASAN=y}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKVhjhhubh)}(hand choose between ``CONFIG_KASAN_GENERIC`` (to enable Generic KASAN), ``CONFIG_KASAN_SW_TAGS`` (to enable Software Tag-Based KASAN), and ``CONFIG_KASAN_HW_TAGS`` (to enable Hardware Tag-Based KASAN).h](hand choose between }(hjhhhNhNubhliteral)}(h``CONFIG_KASAN_GENERIC``h]hCONFIG_KASAN_GENERIC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh (to enable Generic KASAN), }(hjhhhNhNubj)}(h``CONFIG_KASAN_SW_TAGS``h]hCONFIG_KASAN_SW_TAGS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh+ (to enable Software Tag-Based KASAN), and }(hjhhhNhNubj)}(h``CONFIG_KASAN_HW_TAGS``h]hCONFIG_KASAN_HW_TAGS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh& (to enable Hardware Tag-Based KASAN).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKXhjhhubh)}(hFor the software modes, also choose between ``CONFIG_KASAN_OUTLINE`` and ``CONFIG_KASAN_INLINE``. Outline and inline are compiler instrumentation types. The former produces a smaller binary while the latter is up to 2 times faster.h](h,For the software modes, also choose between }(hjhhhNhNubj)}(h``CONFIG_KASAN_OUTLINE``h]hCONFIG_KASAN_OUTLINE}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh and }(hjhhhNhNubj)}(h``CONFIG_KASAN_INLINE``h]hCONFIG_KASAN_INLINE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh. Outline and inline are compiler instrumentation types. The former produces a smaller binary while the latter is up to 2 times faster.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK\hjhhubh)}(hTo include alloc and free stack traces of affected slab objects into reports, enable ``CONFIG_STACKTRACE``. To include alloc and free stack traces of affected physical pages, enable ``CONFIG_PAGE_OWNER`` and boot with ``page_owner=on``.h](hUTo include alloc and free stack traces of affected slab objects into reports, enable }(hj5hhhNhNubj)}(h``CONFIG_STACKTRACE``h]hCONFIG_STACKTRACE}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj5ubhL. To include alloc and free stack traces of affected physical pages, enable }(hj5hhhNhNubj)}(h``CONFIG_PAGE_OWNER``h]hCONFIG_PAGE_OWNER}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj5ubh and boot with }(hj5hhhNhNubj)}(h``page_owner=on``h]h page_owner=on}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jhj5ubh.}(hj5hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK`hjhhubh)}(hhh](h)}(hBoot parametersh]hBoot parameters}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjyhhhhhKeubh)}(hKASAN is affected by the generic ``panic_on_warn`` command line parameter. When it is enabled, KASAN panics the kernel after printing a bug report.h](h!KASAN is affected by the generic }(hjhhhNhNubj)}(h``panic_on_warn``h]h panic_on_warn}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubha command line parameter. When it is enabled, KASAN panics the kernel after printing a bug report.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKghjyhhubh)}(hBy default, KASAN prints a bug report only for the first invalid memory access. With ``kasan_multi_shot``, KASAN prints a report on every invalid access. This effectively disables ``panic_on_warn`` for KASAN reports.h](hUBy default, KASAN prints a bug report only for the first invalid memory access. With }(hjhhhNhNubj)}(h``kasan_multi_shot``h]hkasan_multi_shot}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhK, KASAN prints a report on every invalid access. This effectively disables }(hjhhhNhNubj)}(h``panic_on_warn``h]h panic_on_warn}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh for KASAN reports.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKjhjyhhubh)}(hAlternatively, independent of ``panic_on_warn``, the ``kasan.fault=`` boot parameter can be used to control panic and reporting behaviour:h](hAlternatively, independent of }(hjhhhNhNubj)}(h``panic_on_warn``h]h panic_on_warn}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, the }(hjhhhNhNubj)}(h``kasan.fault=``h]h kasan.fault=}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhE boot parameter can be used to control panic and reporting behaviour:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKnhjyhhubh bullet_list)}(hhh]j )}(hX``kasan.fault=report``, ``=panic``, or ``=panic_on_write`` controls whether to only print a KASAN report, panic the kernel, or panic the kernel on invalid writes only (default: ``report``). The panic happens even if ``kasan_multi_shot`` is enabled. Note that when using asynchronous mode of Hardware Tag-Based KASAN, ``kasan.fault=panic_on_write`` always panics on asynchronously checked accesses (including reads). h]h)}(hX``kasan.fault=report``, ``=panic``, or ``=panic_on_write`` controls whether to only print a KASAN report, panic the kernel, or panic the kernel on invalid writes only (default: ``report``). The panic happens even if ``kasan_multi_shot`` is enabled. Note that when using asynchronous mode of Hardware Tag-Based KASAN, ``kasan.fault=panic_on_write`` always panics on asynchronously checked accesses (including reads).h](j)}(h``kasan.fault=report``h]hkasan.fault=report}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, }(hjhhhNhNubj)}(h ``=panic``h]h=panic}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, or }(hjhhhNhNubj)}(h``=panic_on_write``h]h=panic_on_write}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhw controls whether to only print a KASAN report, panic the kernel, or panic the kernel on invalid writes only (default: }(hjhhhNhNubj)}(h ``report``h]hreport}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh). The panic happens even if }(hjhhhNhNubj)}(h``kasan_multi_shot``h]hkasan_multi_shot}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhQ is enabled. Note that when using asynchronous mode of Hardware Tag-Based KASAN, }(hjhhhNhNubj)}(h``kasan.fault=panic_on_write``h]hkasan.fault=panic_on_write}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhD always panics on asynchronously checked accesses (including reads).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKqhjubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubah}(h]h ]h"]h$]h&]bullet-uh1jhhhKqhjyhhubh)}(hSoftware and Hardware Tag-Based KASAN modes (see the section about various modes below) support altering stack trace collection behavior:h]hSoftware and Hardware Tag-Based KASAN modes (see the section about various modes below) support altering stack trace collection behavior:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKxhjyhhubj)}(hhh](j )}(hq``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack traces collection (default: ``on``).h]h)}(hq``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack traces collection (default: ``on``).h](j)}(h``kasan.stacktrace=off``h]hkasan.stacktrace=off}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h``=on``h]h=on}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhF disables or enables alloc and free stack traces collection (default: }(hjhhhNhNubj)}(h``on``h]hon}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK{hjubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubj )}(hv``kasan.stack_ring_size=`` specifies the number of entries in the stack ring (default: ``32768``). h]h)}(hu``kasan.stack_ring_size=`` specifies the number of entries in the stack ring (default: ``32768``).h](j)}(h-``kasan.stack_ring_size=``h]h)kasan.stack_ring_size=}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh= specifies the number of entries in the stack ring (default: }(hjhhhNhNubj)}(h ``32768``h]h32768}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK}hjubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhK{hjyhhubh)}(hHardware Tag-Based KASAN mode is intended for use in production as a security mitigation. Therefore, it supports additional boot parameters that allow disabling KASAN altogether or controlling its features:h]hHardware Tag-Based KASAN mode is intended for use in production as a security mitigation. Therefore, it supports additional boot parameters that allow disabling KASAN altogether or controlling its features:}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjyhhubj)}(hhh](j )}(hN``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``). h]h)}(hM``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).h](j)}(h ``kasan=off``h]h kasan=off}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjIubh or }(hjIhhhNhNubj)}(h``=on``h]h=on}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjIubh- controls whether KASAN is enabled (default: }(hjIhhhNhNubj)}(h``on``h]hon}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjIubh).}(hjIhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjEubah}(h]h ]h"]h$]h&]uh1j hjBhhhhhNubj )}(hXX``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN is configured in synchronous, asynchronous or asymmetric mode of execution (default: ``sync``). Synchronous mode: a bad access is detected immediately when a tag check fault occurs. Asynchronous mode: a bad access detection is delayed. When a tag check fault occurs, the information is stored in hardware (in the TFSR_EL1 register for arm64). The kernel periodically checks the hardware and only reports tag faults during these checks. Asymmetric mode: a bad access is detected synchronously on reads and asynchronously on writes. h]h)}(hXW``kasan.mode=sync``, ``=async`` or ``=asymm`` controls whether KASAN is configured in synchronous, asynchronous or asymmetric mode of execution (default: ``sync``). Synchronous mode: a bad access is detected immediately when a tag check fault occurs. Asynchronous mode: a bad access detection is delayed. When a tag check fault occurs, the information is stored in hardware (in the TFSR_EL1 register for arm64). The kernel periodically checks the hardware and only reports tag faults during these checks. Asymmetric mode: a bad access is detected synchronously on reads and asynchronously on writes.h](j)}(h``kasan.mode=sync``h]hkasan.mode=sync}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, }(hjhhhNhNubj)}(h ``=async``h]h=async}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h ``=asymm``h]h=asymm}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhm controls whether KASAN is configured in synchronous, asynchronous or asymmetric mode of execution (default: }(hjhhhNhNubj)}(h``sync``h]hsync}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX). Synchronous mode: a bad access is detected immediately when a tag check fault occurs. Asynchronous mode: a bad access detection is delayed. When a tag check fault occurs, the information is stored in hardware (in the TFSR_EL1 register for arm64). The kernel periodically checks the hardware and only reports tag faults during these checks. Asymmetric mode: a bad access is detected synchronously on reads and asynchronously on writes.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j hjBhhhhhNubj )}(hg``kasan.vmalloc=off`` or ``=on`` disables or enables tagging of vmalloc allocations (default: ``on``). h]h)}(hf``kasan.vmalloc=off`` or ``=on`` disables or enables tagging of vmalloc allocations (default: ``on``).h](j)}(h``kasan.vmalloc=off``h]hkasan.vmalloc=off}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h``=on``h]h=on}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh> disables or enables tagging of vmalloc allocations (default: }(hjhhhNhNubj)}(h``on``h]hon}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j hjBhhhhhNubj )}(hX5``kasan.page_alloc.sample=`` makes KASAN tag only every Nth page_alloc allocation with the order equal or greater than ``kasan.page_alloc.sample.order``, where N is the value of the ``sample`` parameter (default: ``1``, or tag every such allocation). This parameter is intended to mitigate the performance overhead introduced by KASAN. Note that enabling this parameter makes Hardware Tag-Based KASAN skip checks of allocations chosen by sampling and thus miss bad accesses to these allocations. Use the default value for accurate bug detection. h]h)}(hX4``kasan.page_alloc.sample=`` makes KASAN tag only every Nth page_alloc allocation with the order equal or greater than ``kasan.page_alloc.sample.order``, where N is the value of the ``sample`` parameter (default: ``1``, or tag every such allocation). This parameter is intended to mitigate the performance overhead introduced by KASAN. Note that enabling this parameter makes Hardware Tag-Based KASAN skip checks of allocations chosen by sampling and thus miss bad accesses to these allocations. Use the default value for accurate bug detection.h](j)}(h/``kasan.page_alloc.sample=``h]h+kasan.page_alloc.sample=}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubh[ makes KASAN tag only every Nth page_alloc allocation with the order equal or greater than }(hj9hhhNhNubj)}(h!``kasan.page_alloc.sample.order``h]hkasan.page_alloc.sample.order}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubh, where N is the value of the }(hj9hhhNhNubj)}(h ``sample``h]hsample}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubh parameter (default: }(hj9hhhNhNubj)}(h``1``h]h1}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubhXG, or tag every such allocation). This parameter is intended to mitigate the performance overhead introduced by KASAN. Note that enabling this parameter makes Hardware Tag-Based KASAN skip checks of allocations chosen by sampling and thus miss bad accesses to these allocations. Use the default value for accurate bug detection.}(hj9hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj5ubah}(h]h ]h"]h$]h&]uh1j hjBhhhhhNubj )}(hXo``kasan.page_alloc.sample.order=`` specifies the minimum order of allocations that are affected by sampling (default: ``3``). Only applies when ``kasan.page_alloc.sample`` is set to a value greater than ``1``. This parameter is intended to allow sampling only large page_alloc allocations, which is the biggest source of the performance overhead. h]h)}(hXn``kasan.page_alloc.sample.order=`` specifies the minimum order of allocations that are affected by sampling (default: ``3``). Only applies when ``kasan.page_alloc.sample`` is set to a value greater than ``1``. This parameter is intended to allow sampling only large page_alloc allocations, which is the biggest source of the performance overhead.h](j)}(h6``kasan.page_alloc.sample.order=``h]h2kasan.page_alloc.sample.order=}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhT specifies the minimum order of allocations that are affected by sampling (default: }(hjhhhNhNubj)}(h``3``h]h3}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh). Only applies when }(hjhhhNhNubj)}(h``kasan.page_alloc.sample``h]hkasan.page_alloc.sample}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh is set to a value greater than }(hjhhhNhNubj)}(h``1``h]h1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh. This parameter is intended to allow sampling only large page_alloc allocations, which is the biggest source of the performance overhead.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j hjBhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjyhhubeh}(h]boot-parametersah ]h"]boot parametersah$]h&]uh1hhjhhhhhKeubh)}(hhh](h)}(h Error reportsh]h Error reports}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h(A typical KASAN report looks like this::h]h'A typical KASAN report looks like this:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hXO ================================================================== BUG: KASAN: slab-out-of-bounds in kmalloc_oob_right+0xa8/0xbc [kasan_test] Write of size 1 at addr ffff8801f44ec37b by task insmod/2760 CPU: 1 PID: 2760 Comm: insmod Not tainted 4.19.0-rc3+ #698 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Call Trace: dump_stack+0x94/0xd8 print_address_description+0x73/0x280 kasan_report+0x144/0x187 __asan_report_store1_noabort+0x17/0x20 kmalloc_oob_right+0xa8/0xbc [kasan_test] kmalloc_tests_init+0x16/0x700 [kasan_test] do_one_initcall+0xa5/0x3ae do_init_module+0x1b6/0x547 load_module+0x75df/0x8070 __do_sys_init_module+0x1c6/0x200 __x64_sys_init_module+0x6e/0xb0 do_syscall_64+0x9f/0x2c0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f96443109da RSP: 002b:00007ffcf0b51b08 EFLAGS: 00000202 ORIG_RAX: 00000000000000af RAX: ffffffffffffffda RBX: 000055dc3ee521a0 RCX: 00007f96443109da RDX: 00007f96445cff88 RSI: 0000000000057a50 RDI: 00007f9644992000 RBP: 000055dc3ee510b0 R08: 0000000000000003 R09: 0000000000000000 R10: 00007f964430cd0a R11: 0000000000000202 R12: 00007f96445cff88 R13: 000055dc3ee51090 R14: 0000000000000000 R15: 0000000000000000 Allocated by task 2760: save_stack+0x43/0xd0 kasan_kmalloc+0xa7/0xd0 kmem_cache_alloc_trace+0xe1/0x1b0 kmalloc_oob_right+0x56/0xbc [kasan_test] kmalloc_tests_init+0x16/0x700 [kasan_test] do_one_initcall+0xa5/0x3ae do_init_module+0x1b6/0x547 load_module+0x75df/0x8070 __do_sys_init_module+0x1c6/0x200 __x64_sys_init_module+0x6e/0xb0 do_syscall_64+0x9f/0x2c0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Freed by task 815: save_stack+0x43/0xd0 __kasan_slab_free+0x135/0x190 kasan_slab_free+0xe/0x10 kfree+0x93/0x1a0 umh_complete+0x6a/0xa0 call_usermodehelper_exec_async+0x4c3/0x640 ret_from_fork+0x35/0x40 The buggy address belongs to the object at ffff8801f44ec300 which belongs to the cache kmalloc-128 of size 128 The buggy address is located 123 bytes inside of 128-byte region [ffff8801f44ec300, ffff8801f44ec380) The buggy address belongs to the page: page:ffffea0007d13b00 count:1 mapcount:0 mapping:ffff8801f7001640 index:0x0 flags: 0x200000000000100(slab) raw: 0200000000000100 ffffea0007d11dc0 0000001a0000001a ffff8801f7001640 raw: 0000000000000000 0000000080150015 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8801f44ec200: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8801f44ec280: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc >ffff8801f44ec300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ^ ffff8801f44ec380: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8801f44ec400: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ==================================================================h]hXO ================================================================== BUG: KASAN: slab-out-of-bounds in kmalloc_oob_right+0xa8/0xbc [kasan_test] Write of size 1 at addr ffff8801f44ec37b by task insmod/2760 CPU: 1 PID: 2760 Comm: insmod Not tainted 4.19.0-rc3+ #698 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Call Trace: dump_stack+0x94/0xd8 print_address_description+0x73/0x280 kasan_report+0x144/0x187 __asan_report_store1_noabort+0x17/0x20 kmalloc_oob_right+0xa8/0xbc [kasan_test] kmalloc_tests_init+0x16/0x700 [kasan_test] do_one_initcall+0xa5/0x3ae do_init_module+0x1b6/0x547 load_module+0x75df/0x8070 __do_sys_init_module+0x1c6/0x200 __x64_sys_init_module+0x6e/0xb0 do_syscall_64+0x9f/0x2c0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f96443109da RSP: 002b:00007ffcf0b51b08 EFLAGS: 00000202 ORIG_RAX: 00000000000000af RAX: ffffffffffffffda RBX: 000055dc3ee521a0 RCX: 00007f96443109da RDX: 00007f96445cff88 RSI: 0000000000057a50 RDI: 00007f9644992000 RBP: 000055dc3ee510b0 R08: 0000000000000003 R09: 0000000000000000 R10: 00007f964430cd0a R11: 0000000000000202 R12: 00007f96445cff88 R13: 000055dc3ee51090 R14: 0000000000000000 R15: 0000000000000000 Allocated by task 2760: save_stack+0x43/0xd0 kasan_kmalloc+0xa7/0xd0 kmem_cache_alloc_trace+0xe1/0x1b0 kmalloc_oob_right+0x56/0xbc [kasan_test] kmalloc_tests_init+0x16/0x700 [kasan_test] do_one_initcall+0xa5/0x3ae do_init_module+0x1b6/0x547 load_module+0x75df/0x8070 __do_sys_init_module+0x1c6/0x200 __x64_sys_init_module+0x6e/0xb0 do_syscall_64+0x9f/0x2c0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Freed by task 815: save_stack+0x43/0xd0 __kasan_slab_free+0x135/0x190 kasan_slab_free+0xe/0x10 kfree+0x93/0x1a0 umh_complete+0x6a/0xa0 call_usermodehelper_exec_async+0x4c3/0x640 ret_from_fork+0x35/0x40 The buggy address belongs to the object at ffff8801f44ec300 which belongs to the cache kmalloc-128 of size 128 The buggy address is located 123 bytes inside of 128-byte region [ffff8801f44ec300, ffff8801f44ec380) The buggy address belongs to the page: page:ffffea0007d13b00 count:1 mapcount:0 mapping:ffff8801f7001640 index:0x0 flags: 0x200000000000100(slab) raw: 0200000000000100 ffffea0007d11dc0 0000001a0000001a ffff8801f7001640 raw: 0000000000000000 0000000080150015 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8801f44ec200: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8801f44ec280: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc >ffff8801f44ec300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ^ ffff8801f44ec380: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8801f44ec400: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ==================================================================}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hXThe report header summarizes what kind of bug happened and what kind of access caused it. It is followed by a stack trace of the bad access, a stack trace of where the accessed memory was allocated (in case a slab object was accessed), and a stack trace of where the object was freed (in case of a use-after-free bug report). Next comes a description of the accessed slab object and the information about the accessed memory page.h]hXThe report header summarizes what kind of bug happened and what kind of access caused it. It is followed by a stack trace of the bad access, a stack trace of where the accessed memory was allocated (in case a slab object was accessed), and a stack trace of where the object was freed (in case of a use-after-free bug report). Next comes a description of the accessed slab object and the information about the accessed memory page.}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hX[In the end, the report shows the memory state around the accessed address. Internally, KASAN tracks memory state separately for each memory granule, which is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the memory state section of the report shows the state of one of the memory granules that surround the accessed address.h]hX[In the end, the report shows the memory state around the accessed address. Internally, KASAN tracks memory state separately for each memory granule, which is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the memory state section of the report shows the state of one of the memory granules that surround the accessed address.}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXFor Generic KASAN, the size of each memory granule is 8. The state of each granule is encoded in one shadow byte. Those 8 bytes can be accessible, partially accessible, freed, or be a part of a redzone. KASAN uses the following encoding for each shadow byte: 00 means that all 8 bytes of the corresponding memory region are accessible; number N (1 <= N <= 7) means that the first N bytes are accessible, and other (8 - N) bytes are not; any negative value indicates that the entire 8-byte word is inaccessible. KASAN uses different negative values to distinguish between different kinds of inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h).h]hXFor Generic KASAN, the size of each memory granule is 8. The state of each granule is encoded in one shadow byte. Those 8 bytes can be accessible, partially accessible, freed, or be a part of a redzone. KASAN uses the following encoding for each shadow byte: 00 means that all 8 bytes of the corresponding memory region are accessible; number N (1 <= N <= 7) means that the first N bytes are accessible, and other (8 - N) bytes are not; any negative value indicates that the entire 8-byte word is inaccessible. KASAN uses different negative values to distinguish between different kinds of inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h).}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hIn the report above, the arrow points to the shadow byte ``03``, which means that the accessed address is partially accessible.h](h9In the report above, the arrow points to the shadow byte }(hjRhhhNhNubj)}(h``03``h]h03}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjRubh@, which means that the accessed address is partially accessible.}(hjRhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hjhhubh)}(hFor tag-based KASAN modes, this last report section shows the memory tags around the accessed address (see the `Implementation details`_ section).h](hoFor tag-based KASAN modes, this last report section shows the memory tags around the accessed address (see the }(hjrhhhNhNubh reference)}(h`Implementation details`_h]hImplementation details}(hj|hhhNhNubah}(h]h ]h"]h$]h&]nameImplementation detailsrefidimplementation-detailsuh1jzhjrresolvedKubh section).}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hjhhubh)}(hNote that KASAN bug titles (like ``slab-out-of-bounds`` or ``use-after-free``) are best-effort: KASAN prints the most probable bug type based on the limited information it has. The actual type of the bug might be different.h](h!Note that KASAN bug titles (like }(hjhhhNhNubj)}(h``slab-out-of-bounds``h]hslab-out-of-bounds}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h``use-after-free``h]huse-after-free}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh) are best-effort: KASAN prints the most probable bug type based on the limited information it has. The actual type of the bug might be different.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXGeneric KASAN also reports up to two auxiliary call stack traces. These stack traces point to places in code that interacted with the object but that are not directly present in the bad access stack trace. Currently, this includes call_rcu() and workqueue queuing.h]hXGeneric KASAN also reports up to two auxiliary call stack traces. These stack traces point to places in code that interacted with the object but that are not directly present in the bad access stack trace. Currently, this includes call_rcu() and workqueue queuing.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h] error-reportsah ]h"] error reportsah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hCONFIG_KASAN_EXTRA_INFOh]hCONFIG_KASAN_EXTRA_INFO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXEnabling CONFIG_KASAN_EXTRA_INFO allows KASAN to record and report more information. The extra information currently supported is the CPU number and timestamp at allocation and free. More information can help find the cause of the bug and correlate the error with other system events, at the cost of using extra memory to record more information (more cost details in the help text of CONFIG_KASAN_EXTRA_INFO).h]hXEnabling CONFIG_KASAN_EXTRA_INFO allows KASAN to record and report more information. The extra information currently supported is the CPU number and timestamp at allocation and free. More information can help find the cause of the bug and correlate the error with other system events, at the cost of using extra memory to record more information (more cost details in the help text of CONFIG_KASAN_EXTRA_INFO).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h^Here is the report with CONFIG_KASAN_EXTRA_INFO enabled (only the different parts are shown)::h]h]Here is the report with CONFIG_KASAN_EXTRA_INFO enabled (only the different parts are shown):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM"hjhhubj)}(h================================================================== ... Allocated by task 134 on cpu 5 at 229.133855s: ... Freed by task 136 on cpu 3 at 230.199335s: ... ==================================================================h]h================================================================== ... Allocated by task 134 on cpu 5 at 229.133855s: ... Freed by task 136 on cpu 3 at 230.199335s: ... ==================================================================}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhM%hjhhubeh}(h]config-kasan-extra-infoah ]h"]config_kasan_extra_infoah$]h&]uh1hhjhhhhhMubeh}(h]usageah ]h"]usageah$]h&]uh1hhhhhhhhKRubh)}(hhh](h)}(hImplementation detailsh]hImplementation details}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj,hhhhhM.ubh)}(hhh](h)}(h Generic KASANh]h Generic KASAN}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj=hhhhhM1ubh)}(hSoftware KASAN modes use shadow memory to record whether each byte of memory is safe to access and use compile-time instrumentation to insert shadow memory checks before each memory access.h]hSoftware KASAN modes use shadow memory to record whether each byte of memory is safe to access and use compile-time instrumentation to insert shadow memory checks before each memory access.}(hjNhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM3hj=hhubh)}(hGeneric KASAN dedicates 1/8th of kernel memory to its shadow memory (16TB to cover 128TB on x86_64) and uses direct mapping with a scale and offset to translate a memory address to its corresponding shadow address.h]hGeneric KASAN dedicates 1/8th of kernel memory to its shadow memory (16TB to cover 128TB on x86_64) and uses direct mapping with a scale and offset to translate a memory address to its corresponding shadow address.}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM7hj=hhubh)}(hVHere is the function which translates an address to its corresponding shadow address::h]hUHere is the function which translates an address to its corresponding shadow address:}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hj=hhubj)}(hstatic inline void *kasan_mem_to_shadow(const void *addr) { return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; }h]hstatic inline void *kasan_mem_to_shadow(const void *addr) { return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; }}hjxsbah}(h]h ]h"]h$]h&]hhuh1jhhhM>hj=hhubh)}(h'where ``KASAN_SHADOW_SCALE_SHIFT = 3``.h](hwhere }(hjhhhNhNubj)}(h ``KASAN_SHADOW_SCALE_SHIFT = 3``h]hKASAN_SHADOW_SCALE_SHIFT = 3}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhj=hhubh)}(hX3Compile-time instrumentation is used to insert memory access checks. Compiler inserts function calls (``__asan_load*(addr)``, ``__asan_store*(addr)``) before each memory access of size 1, 2, 4, 8, or 16. These functions check whether memory accesses are valid or not by checking corresponding shadow memory.h](hfCompile-time instrumentation is used to insert memory access checks. Compiler inserts function calls (}(hjhhhNhNubj)}(h``__asan_load*(addr)``h]h__asan_load*(addr)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh, }(hjhhhNhNubj)}(h``__asan_store*(addr)``h]h__asan_store*(addr)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh) before each memory access of size 1, 2, 4, 8, or 16. These functions check whether memory accesses are valid or not by checking corresponding shadow memory.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMFhj=hhubh)}(hWith inline instrumentation, instead of making function calls, the compiler directly inserts the code to check shadow memory. This option significantly enlarges the kernel, but it gives an x1.1-x2 performance boost over the outline-instrumented kernel.h]hWith inline instrumentation, instead of making function calls, the compiler directly inserts the code to check shadow memory. This option significantly enlarges the kernel, but it gives an x1.1-x2 performance boost over the outline-instrumented kernel.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMKhj=hhubh)}(hGeneric KASAN is the only mode that delays the reuse of freed objects via quarantine (see mm/kasan/quarantine.c for implementation).h]hGeneric KASAN is the only mode that delays the reuse of freed objects via quarantine (see mm/kasan/quarantine.c for implementation).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhj=hhubeh}(h] generic-kasanah ]h"] generic kasanah$]h&]uh1hhj,hhhhhM1ubh)}(hhh](h)}(hSoftware Tag-Based KASANh]hSoftware Tag-Based KASAN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMTubh)}(hSoftware Tag-Based KASAN uses a software memory tagging approach to checking access validity. It is currently only implemented for the arm64 architecture.h]hSoftware Tag-Based KASAN uses a software memory tagging approach to checking access validity. It is currently only implemented for the arm64 architecture.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjhhubh)}(hX%Software Tag-Based KASAN uses the Top Byte Ignore (TBI) feature of arm64 CPUs to store a pointer tag in the top byte of kernel pointers. It uses shadow memory to store memory tags associated with each 16-byte memory cell (therefore, it dedicates 1/16th of the kernel memory for shadow memory).h]hX%Software Tag-Based KASAN uses the Top Byte Ignore (TBI) feature of arm64 CPUs to store a pointer tag in the top byte of kernel pointers. It uses shadow memory to store memory tags associated with each 16-byte memory cell (therefore, it dedicates 1/16th of the kernel memory for shadow memory).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhjhhubh)}(hOn each memory allocation, Software Tag-Based KASAN generates a random tag, tags the allocated memory with this tag, and embeds the same tag into the returned pointer.h]hOn each memory allocation, Software Tag-Based KASAN generates a random tag, tags the allocated memory with this tag, and embeds the same tag into the returned pointer.}(hj) hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hjhhubh)}(hX?Software Tag-Based KASAN uses compile-time instrumentation to insert checks before each memory access. These checks make sure that the tag of the memory that is being accessed is equal to the tag of the pointer that is used to access this memory. In case of a tag mismatch, Software Tag-Based KASAN prints a bug report.h]hX?Software Tag-Based KASAN uses compile-time instrumentation to insert checks before each memory access. These checks make sure that the tag of the memory that is being accessed is equal to the tag of the pointer that is used to access this memory. In case of a tag mismatch, Software Tag-Based KASAN prints a bug report.}(hj7 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMbhjhhubh)}(hXSoftware Tag-Based KASAN also has two instrumentation modes (outline, which emits callbacks to check memory accesses; and inline, which performs the shadow memory checks inline). With outline instrumentation mode, a bug report is printed from the function that performs the access check. With inline instrumentation, a ``brk`` instruction is emitted by the compiler, and a dedicated ``brk`` handler is used to print bug reports.h](hX?Software Tag-Based KASAN also has two instrumentation modes (outline, which emits callbacks to check memory accesses; and inline, which performs the shadow memory checks inline). With outline instrumentation mode, a bug report is printed from the function that performs the access check. With inline instrumentation, a }(hjE hhhNhNubj)}(h``brk``h]hbrk}(hjM hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjE ubh9 instruction is emitted by the compiler, and a dedicated }(hjE hhhNhNubj)}(h``brk``h]hbrk}(hj_ hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjE ubh& handler is used to print bug reports.}(hjE hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhhjhhubh)}(hSoftware Tag-Based KASAN uses 0xFF as a match-all pointer tag (accesses through pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions.h]hSoftware Tag-Based KASAN uses 0xFF as a match-all pointer tag (accesses through pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions.}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMohjhhubeh}(h]software-tag-based-kasanah ]h"]software tag-based kasanah$]h&]uh1hhj,hhhhhMTubh)}(hhh](h)}(hHardware Tag-Based KASANh]hHardware Tag-Based KASAN}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMtubh)}(hHardware Tag-Based KASAN is similar to the software mode in concept but uses hardware memory tagging support instead of compiler instrumentation and shadow memory.h]hHardware Tag-Based KASAN is similar to the software mode in concept but uses hardware memory tagging support instead of compiler instrumentation and shadow memory.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMvhj hhubh)}(hHardware Tag-Based KASAN is currently only implemented for arm64 architecture and based on both arm64 Memory Tagging Extension (MTE) introduced in ARMv8.5 Instruction Set Architecture and Top Byte Ignore (TBI).h]hHardware Tag-Based KASAN is currently only implemented for arm64 architecture and based on both arm64 Memory Tagging Extension (MTE) introduced in ARMv8.5 Instruction Set Architecture and Top Byte Ignore (TBI).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMzhj hhubh)}(hXvSpecial arm64 instructions are used to assign memory tags for each allocation. Same tags are assigned to pointers to those allocations. On every memory access, hardware makes sure that the tag of the memory that is being accessed is equal to the tag of the pointer that is used to access this memory. In case of a tag mismatch, a fault is generated, and a report is printed.h]hXvSpecial arm64 instructions are used to assign memory tags for each allocation. Same tags are assigned to pointers to those allocations. On every memory access, hardware makes sure that the tag of the memory that is being accessed is equal to the tag of the pointer that is used to access this memory. In case of a tag mismatch, a fault is generated, and a report is printed.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM~hj hhubh)}(hHardware Tag-Based KASAN uses 0xFF as a match-all pointer tag (accesses through pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions.h]hHardware Tag-Based KASAN uses 0xFF as a match-all pointer tag (accesses through pointers with the 0xFF pointer tag are not checked). The value 0xFE is currently reserved to tag freed memory regions.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hIf the hardware does not support MTE (pre ARMv8.5), Hardware Tag-Based KASAN will not be enabled. In this case, all KASAN boot parameters are ignored.h]hIf the hardware does not support MTE (pre ARMv8.5), Hardware Tag-Based KASAN will not be enabled. In this case, all KASAN boot parameters are ignored.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hNote that enabling CONFIG_KASAN_HW_TAGS always results in in-kernel TBI being enabled. Even when ``kasan.mode=off`` is provided or when the hardware does not support MTE (but supports TBI).h](haNote that enabling CONFIG_KASAN_HW_TAGS always results in in-kernel TBI being enabled. Even when }(hj hhhNhNubj)}(h``kasan.mode=off``h]hkasan.mode=off}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubhJ is provided or when the hardware does not support MTE (but supports TBI).}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hfHardware Tag-Based KASAN only reports the first found bug. After that, MTE tag checking gets disabled.h]hfHardware Tag-Based KASAN only reports the first found bug. After that, MTE tag checking gets disabled.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h]hardware-tag-based-kasanah ]h"]hardware tag-based kasanah$]h&]uh1hhj,hhhhhMtubeh}(h]jah ]h"]implementation detailsah$]h&]uh1hhhhhhhhM. referencedKubh)}(hhh](h)}(h Shadow memoryh]h Shadow memory}(hj% hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj" hhhhhMubh)}(hIThe contents of this section are only applicable to software KASAN modes.h]hIThe contents of this section are only applicable to software KASAN modes.}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj" hhubh)}(hX>The kernel maps memory in several different parts of the address space. The range of kernel virtual addresses is large: there is not enough real memory to support a real shadow region for every address that could be accessed by the kernel. Therefore, KASAN only maps real shadow for certain parts of the address space.h]hX>The kernel maps memory in several different parts of the address space. The range of kernel virtual addresses is large: there is not enough real memory to support a real shadow region for every address that could be accessed by the kernel. Therefore, KASAN only maps real shadow for certain parts of the address space.}(hjA hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj" hhubh)}(hhh](h)}(hDefault behaviourh]hDefault behaviour}(hjR hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjO hhhhhMubh)}(hX9By default, architectures only map real memory over the shadow region for the linear mapping (and potentially other small areas). For all other areas - such as vmalloc and vmemmap space - a single read-only page is mapped over the shadow area. This read-only shadow page declares all memory accesses as permitted.h]hX9By default, architectures only map real memory over the shadow region for the linear mapping (and potentially other small areas). For all other areas - such as vmalloc and vmemmap space - a single read-only page is mapped over the shadow area. This read-only shadow page declares all memory accesses as permitted.}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjO hhubh)}(hXThis presents a problem for modules: they do not live in the linear mapping but in a dedicated module space. By hooking into the module allocator, KASAN temporarily maps real shadow memory to cover them. This allows detection of invalid accesses to module globals, for example.h]hXThis presents a problem for modules: they do not live in the linear mapping but in a dedicated module space. By hooking into the module allocator, KASAN temporarily maps real shadow memory to cover them. This allows detection of invalid accesses to module globals, for example.}(hjn hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjO hhubh)}(hThis also creates an incompatibility with ``VMAP_STACK``: if the stack lives in vmalloc space, it will be shadowed by the read-only page, and the kernel will fault when trying to set up the shadow data for stack variables.h](h*This also creates an incompatibility with }(hj| hhhNhNubj)}(h``VMAP_STACK``h]h VMAP_STACK}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj| ubh: if the stack lives in vmalloc space, it will be shadowed by the read-only page, and the kernel will fault when trying to set up the shadow data for stack variables.}(hj| hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjO hhubeh}(h]default-behaviourah ]h"]default behaviourah$]h&]uh1hhj" hhhhhMubh)}(hhh](h)}(hCONFIG_KASAN_VMALLOCh]hCONFIG_KASAN_VMALLOC}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hWith ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the cost of greater memory usage. Currently, this is supported on x86, arm64, riscv, s390, and powerpc.h](hWith }(hj hhhNhNubj)}(h``CONFIG_KASAN_VMALLOC``h]hCONFIG_KASAN_VMALLOC}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh, KASAN can cover vmalloc space at the cost of greater memory usage. Currently, this is supported on x86, arm64, riscv, s390, and powerpc.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hoThis works by hooking into vmalloc and vmap and dynamically allocating real shadow memory to back the mappings.h]hoThis works by hooking into vmalloc and vmap and dynamically allocating real shadow memory to back the mappings.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hX5Most mappings in vmalloc space are small, requiring less than a full page of shadow space. Allocating a full shadow page per mapping would therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to ``KASAN_GRANULE_SIZE * PAGE_SIZE``.h](hXMost mappings in vmalloc space are small, requiring less than a full page of shadow space. Allocating a full shadow page per mapping would therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to }(hj hhhNhNubj)}(h"``KASAN_GRANULE_SIZE * PAGE_SIZE``h]hKASAN_GRANULE_SIZE * PAGE_SIZE}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hInstead, KASAN shares backing space across multiple mappings. It allocates a backing page when a mapping in vmalloc space uses a particular page of the shadow region. This page can be shared by other vmalloc mappings later on.h]hInstead, KASAN shares backing space across multiple mappings. It allocates a backing page when a mapping in vmalloc space uses a particular page of the shadow region. This page can be shared by other vmalloc mappings later on.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hQKASAN hooks into the vmap infrastructure to lazily clean up unused shadow memory.h]hQKASAN hooks into the vmap infrastructure to lazily clean up unused shadow memory.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hXTo avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will not be covered by the early shadow page but will be left unmapped. This will require changes in arch-specific code.h]hXTo avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will not be covered by the early shadow page but will be left unmapped. This will require changes in arch-specific code.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(h{This allows ``VMAP_STACK`` support on x86 and can simplify support of architectures that do not have a fixed module region.h](h This allows }(hj- hhhNhNubj)}(h``VMAP_STACK``h]h VMAP_STACK}(hj5 hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj- ubha support on x86 and can simplify support of architectures that do not have a fixed module region.}(hj- hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h]config-kasan-vmallocah ]h"]config_kasan_vmallocah$]h&]uh1hhj" hhhhhMubeh}(h] shadow-memoryah ]h"] shadow memoryah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hFor developersh]hFor developers}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj] hhhhhMubh)}(hhh](h)}(hIgnoring accessesh]hIgnoring accesses}(hjq hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjn hhhhhMubh)}(hSoftware KASAN modes use compiler instrumentation to insert validity checks. Such instrumentation might be incompatible with some parts of the kernel, and therefore needs to be disabled.h]hSoftware KASAN modes use compiler instrumentation to insert validity checks. Such instrumentation might be incompatible with some parts of the kernel, and therefore needs to be disabled.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubh)}(hOther parts of the kernel might access metadata for allocated objects. Normally, KASAN detects and reports such accesses, but in some cases (e.g., in memory allocators), these accesses are valid.h]hOther parts of the kernel might access metadata for allocated objects. Normally, KASAN detects and reports such accesses, but in some cases (e.g., in memory allocators), these accesses are valid.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubh)}(hFor software KASAN modes, to disable instrumentation for a specific file or directory, add a ``KASAN_SANITIZE`` annotation to the respective kernel Makefile:h](h]For software KASAN modes, to disable instrumentation for a specific file or directory, add a }(hj hhhNhNubj)}(h``KASAN_SANITIZE``h]hKASAN_SANITIZE}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh. annotation to the respective kernel Makefile:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubj)}(hh>Bh](j )}(hAFor a single file (e.g., main.o):: KASAN_SANITIZE_main.o := n h](h)}(h"For a single file (e.g., main.o)::h]h!For a single file (e.g., main.o):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubj)}(hKASAN_SANITIZE_main.o := nh]hKASAN_SANITIZE_main.o := n}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(h8For all files in one directory:: KASAN_SANITIZE := n h](h)}(h For all files in one directory::h]hFor all files in one directory:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubj)}(hKASAN_SANITIZE := nh]hKASAN_SANITIZE := n}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j hj hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhMhjn hhubh)}(hFor software KASAN modes, to disable instrumentation on a per-function basis, use the KASAN-specific ``__no_sanitize_address`` function attribute or the generic ``noinstr`` one.h](heFor software KASAN modes, to disable instrumentation on a per-function basis, use the KASAN-specific }(hj hhhNhNubj)}(h``__no_sanitize_address``h]h__no_sanitize_address}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh# function attribute or the generic }(hj hhhNhNubj)}(h ``noinstr``h]hnoinstr}(hj* hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh one.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubh)}(hXeNote that disabling compiler instrumentation (either on a per-file or a per-function basis) makes KASAN ignore the accesses that happen directly in that code for software KASAN modes. It does not help when the accesses happen indirectly (through calls to instrumented functions) or with Hardware Tag-Based KASAN, which does not use compiler instrumentation.h]hXeNote that disabling compiler instrumentation (either on a per-file or a per-function basis) makes KASAN ignore the accesses that happen directly in that code for software KASAN modes. It does not help when the accesses happen indirectly (through calls to instrumented functions) or with Hardware Tag-Based KASAN, which does not use compiler instrumentation.}(hjB hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubh)}(hX$For software KASAN modes, to disable KASAN reports in a part of the kernel code for the current task, annotate this part of the code with a ``kasan_disable_current()``/``kasan_enable_current()`` section. This also disables the reports for indirect accesses that happen through function calls.h](hFor software KASAN modes, to disable KASAN reports in a part of the kernel code for the current task, annotate this part of the code with a }(hjP hhhNhNubj)}(h``kasan_disable_current()``h]hkasan_disable_current()}(hjX hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjP ubh/}(hjP hhhNhNubj)}(h``kasan_enable_current()``h]hkasan_enable_current()}(hjj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjP ubhb section. This also disables the reports for indirect accesses that happen through function calls.}(hjP hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubh)}(hX"For tag-based KASAN modes, to disable access checking, use ``kasan_reset_tag()`` or ``page_kasan_tag_reset()``. Note that temporarily disabling access checking via ``page_kasan_tag_reset()`` requires saving and restoring the per-page KASAN tag via ``page_kasan_tag``/``page_kasan_tag_set``.h](h;For tag-based KASAN modes, to disable access checking, use }(hj hhhNhNubj)}(h``kasan_reset_tag()``h]hkasan_reset_tag()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh or }(hj hhhNhNubj)}(h``page_kasan_tag_reset()``h]hpage_kasan_tag_reset()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh6. Note that temporarily disabling access checking via }(hj hhhNhNubj)}(h``page_kasan_tag_reset()``h]hpage_kasan_tag_reset()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh: requires saving and restoring the per-page KASAN tag via }(hj hhhNhNubj)}(h``page_kasan_tag``h]hpage_kasan_tag}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh/}(hj hhhNhNubj)}(h``page_kasan_tag_set``h]hpage_kasan_tag_set}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjn hhubeh}(h]ignoring-accessesah ]h"]ignoring accessesah$]h&]uh1hhj] hhhhhMubh)}(hhh](h)}(hTestsh]hTests}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hoThere are KASAN tests that allow verifying that KASAN works and can detect certain types of memory corruptions.h]hoThere are KASAN tests that allow verifying that KASAN works and can detect certain types of memory corruptions.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hAll KASAN tests are integrated with the KUnit Test Framework and can be enabled via ``CONFIG_KASAN_KUNIT_TEST``. The tests can be run and partially verified automatically in a few different ways; see the instructions below.h](hTAll KASAN tests are integrated with the KUnit Test Framework and can be enabled via }(hj hhhNhNubj)}(h``CONFIG_KASAN_KUNIT_TEST``h]hCONFIG_KASAN_KUNIT_TEST}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubhp. The tests can be run and partially verified automatically in a few different ways; see the instructions below.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hyEach KASAN test prints one of multiple KASAN reports if an error is detected. Then the test prints its number and status.h]hyEach KASAN test prints one of multiple KASAN reports if an error is detected. Then the test prints its number and status.}(hj1 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hWhen a test passes::h]hWhen a test passes:}(hj? hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj hhubj)}(hok 28 - kmalloc_double_kzfreeh]hok 28 - kmalloc_double_kzfree}hjM sbah}(h]h ]h"]h$]h&]hhuh1jhhhM hj hhubh)}(h/When a test fails due to a failed ``kmalloc``::h](h"When a test fails due to a failed }(hj[ hhhNhNubj)}(h ``kmalloc``h]hkmalloc}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj[ ubh:}(hj[ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(h# kmalloc_large_oob_right: ASSERTION FAILED at mm/kasan/kasan_test.c:245 Expected ptr is not null, but is not ok 5 - kmalloc_large_oob_righth]h# kmalloc_large_oob_right: ASSERTION FAILED at mm/kasan/kasan_test.c:245 Expected ptr is not null, but is not ok 5 - kmalloc_large_oob_right}hj{ sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubh)}(h1When a test fails due to a missing KASAN report::h]h0When a test fails due to a missing KASAN report:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(h# kmalloc_double_kzfree: EXPECTATION FAILED at mm/kasan/kasan_test.c:709 KASAN failure expected in "kfree_sensitive(ptr)", but none occurred not ok 28 - kmalloc_double_kzfreeh]h# kmalloc_double_kzfree: EXPECTATION FAILED at mm/kasan/kasan_test.c:709 KASAN failure expected in "kfree_sensitive(ptr)", but none occurred not ok 28 - kmalloc_double_kzfree}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubh)}(hLAt the end the cumulative status of all KASAN tests is printed. On success::h]hKAt the end the cumulative status of all KASAN tests is printed. On success:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(h ok 1 - kasanh]h ok 1 - kasan}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubh)}(h Or, if one of the tests failed::h]hOr, if one of the tests failed:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj hhubj)}(hnot ok 1 - kasanh]hnot ok 1 - kasan}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhM"hj hhubh)}(h,There are a few ways to run the KASAN tests.h]h,There are a few ways to run the KASAN tests.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hj hhubj)}(hhh](j )}(hLoadable module With ``CONFIG_KUNIT`` enabled, the tests can be built as a loadable module and run by loading ``kasan_test.ko`` with ``insmod`` or ``modprobe``. h](h)}(hLoadable moduleh]hLoadable module}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM&hj ubh)}(hWith ``CONFIG_KUNIT`` enabled, the tests can be built as a loadable module and run by loading ``kasan_test.ko`` with ``insmod`` or ``modprobe``.h](hWith }(hjhhhNhNubj)}(h``CONFIG_KUNIT``h]h CONFIG_KUNIT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhI enabled, the tests can be built as a loadable module and run by loading }(hjhhhNhNubj)}(h``kasan_test.ko``h]h kasan_test.ko}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh with }(hjhhhNhNubj)}(h ``insmod``h]hinsmod}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h ``modprobe``h]hmodprobe}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM(hj ubeh}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(hBuilt-In With ``CONFIG_KUNIT`` built-in, the tests can be built-in as well. In this case, the tests will run at boot as a late-init call. h](h)}(hBuilt-Inh]hBuilt-In}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hj\ubh)}(hWith ``CONFIG_KUNIT`` built-in, the tests can be built-in as well. In this case, the tests will run at boot as a late-init call.h](hWith }(hjnhhhNhNubj)}(h``CONFIG_KUNIT``h]h CONFIG_KUNIT}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjnubhk built-in, the tests can be built-in as well. In this case, the tests will run at boot as a late-init call.}(hjnhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM-hj\ubeh}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(hXUsing kunit_tool With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it is also possible to use ``kunit_tool`` to see the results of KUnit tests in a more readable way. This will not print the KASAN reports of the tests that passed. See `KUnit documentation `_ for more up-to-date information on ``kunit_tool``. h](h)}(hUsing kunit_toolh]hUsing kunit_tool}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM0hjubh)}(hXuWith ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it is also possible to use ``kunit_tool`` to see the results of KUnit tests in a more readable way. This will not print the KASAN reports of the tests that passed. See `KUnit documentation `_ for more up-to-date information on ``kunit_tool``.h](hWith }(hjhhhNhNubj)}(h``CONFIG_KUNIT``h]h CONFIG_KUNIT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh and }(hjhhhNhNubj)}(h``CONFIG_KASAN_KUNIT_TEST``h]hCONFIG_KASAN_KUNIT_TEST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh& built-in, it is also possible to use }(hjhhhNhNubj)}(h``kunit_tool``h]h kunit_tool}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh to see the results of KUnit tests in a more readable way. This will not print the KASAN reports of the tests that passed. See }(hjhhhNhNubj{)}(hZ`KUnit documentation `_h]hKUnit documentation}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameKUnit documentationrefuriAhttps://www.kernel.org/doc/html/latest/dev-tools/kunit/index.htmluh1jzhjubhtarget)}(hD h]h}(h]kunit-documentationah ]h"]kunit documentationah$]h&]refurijuh1jj! Khjubh$ for more up-to-date information on }(hjhhhNhNubj)}(h``kunit_tool``h]h kunit_tool}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM2hjubeh}(h]h ]h"]h$]h&]uh1j hj hhhhhNubeh}(h]h ]h"]h$]h&]jYjZj[hj\j]uh1jhj hhhhhM&ubj)}(hL.. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.htmlh]h}(h]kunitah ]h"]kunitah$]h&]jAhttps://www.kernel.org/doc/html/latest/dev-tools/kunit/index.htmluh1jhM8hj hhhhubeh}(h]testsah ]h"]testsah$]h&]uh1hhj] hhhhhMubeh}(h]for-developersah ]h"]for developersah$]h&]uh1hhhhhhhhMubeh}(h]kernel-address-sanitizer-kasanah ]h"] kernel address sanitizer (kasan)ah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjuerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}implementation details]j|asrefids}nameids}(jOjLjjjjjjj2j/jjj)j&jjjjj!jj jjjj j j j jZ jW j j jR jO jGjDj j j?j<jjj6j3u nametypes}(jOjjjj2jj)jjj!j jj j jZ j jR jGj j?jj6uh}(jLhjhjjjjj/jjj5j&jjjyjjjjjj,jj=j jj j jW j" j jO jO j jDj] j jn j<j jjj3j-u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages]hsystem_message)}(hhh]h)}(hhh]h+Hyperlink target "kunit" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypeINFOsourcehlineM8uh1juba transformerN include_log] decorationNhhub.