HWASan, ASan and KASAN

Hardware Address Sanitizer (HWASan), Address Sanitizer (ASan) and Kernel Address Sanitizer (KASAN) are a set of memory bug detection tools that should be used during development.

They insert compiler instrumentation for each memory operation which adds significant overhead -- 2x CPU, 15-30% RAM (ASan: 100% RAM), 50% code size, which makes them not suitable for use in production.
Since the instrumentation is inserted for each memory operation, they detect a wider range of memory safety bugs, including those applicable to stack and globals. This complements the heap detection tools described in the sections above.

Developers should check the presence of crashes by checking /data/tombstones or logcat for bug reports.

HWASan and ASan for detecting userspace memory safety bugs

On arm64 we recommend using HWASan, while for 32-bit arm and for non-Arm platforms we recommend using ASan. They provide equivalent functionality and should be used for detecting memory safety bugs in userspace code.

Enabling them requires a separate build as binaries are not compatible with non-address sanitized versions. To enable HWASan, set SANITIZE_TARGET=hwaddress in the build environment, or simply use the _hwasan- suffixed targets.
For more information on HWASan and ASan see the documentation.

HWAddress Sanitizer Address Sanitizer

KASAN for detecting kernel memory safety bugs

KASAN is the kernel counterpart of the userspace tools above. It shares the same compiler implementation. KASAN and ASan/HWASan are complementary as one tool applies to the kernel and another to userspace. We recommend enabling both at the same time to reduce the number of build configurations and to reduce the testing matrix.