Repository navigation
mm/kasan: fixes and __asan_(un)poison_memory_region() - #22278
Merged
Merged
Conversation
ld.lld: error: undefined symbol: __sanitizer_annotate_double_ended_contiguous_container >>> referenced by deque:987 (include/libcxx/deque:987) Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
Current kasan dump exceeds 80 cols thus is not easy with standard terminal. This makes it fit in 80 cols. Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
Code written against user-space AddressSanitizer (for example the mbedtls test framework) includes <sanitizer/asan_interface.h> and calls __asan_poison_memory_region()/__asan_unpoison_memory_region() to enforce memory access policies. On a KASAN target NuttX does not link the compiler-rt user-space ASan runtime, so these standard entry points were undefined and such code failed to link. Provide them from mm/kasan alongside the other compiler-rt __asan_* entry points already implemented in hook.c, bridging to the in-kernel KASAN shadow via kasan_poison()/kasan_unpoison(). Add a matching public header include/sanitizer/asan_interface.h so the standard include path resolves on a target build. They are excluded for the SIM mode, where the host compiler-rt runtime already defines these symbols and kasan_poison() forwards to them. Signed-off-by: makejian <makejian@xiaomi.com>
Change CONFIG_MM_KASAN_DISABLE_READS_CHECK default from n to y. This disables read-side instrumentation (--param asan-instrument-reads=0) by default, significantly reducing KASAN CPU overhead on hot paths like UART serial I/O. Write-side checks remain active to catch use-after-free and buffer overflows on write. Most memory corruption bugs (UAF, heap overflow, stack overflow) are caught by write-side checks. Read-side checks add substantial overhead with relatively lower detection value in embedded RTOS environments. Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
huojianchaoyy
requested review from
anchao,
simbit18 and
xiaoxiang781216
as code owners
November 24, 2026 12:47
xiaoxiang781216
approved these changes
Nov 24, 2026
GUIDINGLI
approved these changes
Nov 24, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
KASAN changes from Xiaomi Vela, split out of #22206 as asked in its review.
__sanitizer_annotate_double_ended_contiguous_container(), which libc++ (<deque>) calls when built with the sanitizer.__asan_poison_memory_region()and__asan_unpoison_memory_region()on top ofkasan_poison()/kasan_unpoison(), and a new<sanitizer/asan_interface.h>, so code written for user-space ASan links on a KASAN target.Impact
CONFIG_MM_KASAN_DISABLE_READS_CHECKdefaults to y: KASAN checks writes only unless it is turned off.__asan_poison_memory_region()/__asan_unpoison_memory_region()and<sanitizer/asan_interface.h>.Testing
Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim, aarch64-none-elf), CMake 3.23 + Ninja 1.10. Base: master 25b649e.
./tools/checkpatch.sh -c -u -m -g HEAD~4..HEADpasses.sim:ostest(KASAN and UBSAN): a 320 s run completes one ostest pass with no KASAN/UBSAN report; apart from the delays printed by hrtimer_test, the output is the same as master's.CONFIG_MM_KASAN_DISABLE_READS_CHECK=yin that build.qemu-armv8a:sw_tagsbuilds. In both buildshook.c.odefines__asan_poison_memory_region,__asan_unpoison_memory_regionand__sanitizer_annotate_double_ended_contiguous_container.Not tested: linking libc++
<deque>with KASAN, real hardware.