mm,boards/arm/qemu: Fix KASAN user-space false positives, global region link error, and linker script section placement.#19134
Open
leisiji wants to merge 3 commits into
Open
mm,boards/arm/qemu: Fix KASAN user-space false positives, global region link error, and linker script section placement.#19134leisiji wants to merge 3 commits into
leisiji wants to merge 3 commits into
Conversation
When CONFIG_BUILD_KERNEL is enabled, user-space and kernel-space have separate address spaces. User-space addresses passed via syscalls (e.g., open) are registered by KASAN but should not be monitored, as they are not kernel heap allocations. This causes KASAN to report false positives on user-space pointers accessed through system calls. Mark the user-space heap with nokasan=true so KASAN skips checking its address range, consistent with how rptun already handles this. Signed-off-by: leisiji <2265215145@qq.com>
…_KERNEL on When CONFIG_MM_KASAN_GLOBAL is enabled, hook.c is also linked into libmm.a. However, g_global_region (defined in global.c) is only injected into the nuttx ELF by kasan_global.py — it does not process the app binary. This causes undefined symbol errors when linking an app against libmm.a. Guard the inclusion of global.c with __KERNEL__ so that only kernel builds pull in the global KASAN region, while app builds fall back to the no-op stub. Signed-off-by: leisiji <2265215145@qq.com>
1. The .kasan.unused and .kasan.global sections contain compiler-generated data with the WRITE flag (.data..LASAN*), but the linker script placed them before .text without specifying a memory region. The linker could not put writable sections into the read-only ROM (rx) region, so it silently placed them at 0x40000000 in RAM, creating an extra LOAD segment that conflicts with QEMU virt's RAM layout and causes boot failure. 2. The .kasan.global should be placed before .data because .data patten (*(.data*)) includes .kasan.global pattern (*(.data..LASAN0)), and it cause kasan_global.py cannot find .kasan.global section to generate the g_global_region array. 3. Move .kasan.shadows from before .text to after .rodata. Placing it before .text causes .text to shift when .kasan.shadows transitions from empty (pass 1) to populated (pass 2+), preventing the multi-pass link addresses from converging. After .rodata it does not affect any upstream section addresses. 4. Add CMake post-build step to strip .kasan.unused and .kasan.global sections from the final binary, matching the Makefile build behavior. Signed-off-by: leisiji <2265215145@qq.com>
|
|
||
| /* where the global variable out-of-bounds detection information located */ | ||
|
|
||
| #ifdef CONFIG_MM_KASAN_GLOBAL |
Contributor
There was a problem hiding this comment.
@yf13 has the patch which could fix kasan on protectd/kernel build, let's wait his patch.
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.
Summary
qemu-armv7a:knsh, there are three issues preventing correct build
and runtime: (1) user-space heap false positive KASAN reports,
(2) app link failure due to undefined g_global_region symbol,
(3) linker script misplaces KASAN sections causing boot failure.
in kernel mode on QEMU ARMv7-A.
Impact
and .kasan.global sections when CONFIG_MM_KASAN_GLOBAL is enabled.
KASAN enabled in kernel build.
Testing
Setup config:
Build:
Run:
Testing logs before change: