Skip to content

{bp-19198} mm,qemu: Fix KASAN user-space false positives, global region link error, and linker script section placement#19273

Merged
xiaoxiang781216 merged 3 commits into
apache:releases/13.0from
jerpelea:bp-19198
Jul 3, 2026
Merged

{bp-19198} mm,qemu: Fix KASAN user-space false positives, global region link error, and linker script section placement#19273
xiaoxiang781216 merged 3 commits into
apache:releases/13.0from
jerpelea:bp-19198

Conversation

@jerpelea

@jerpelea jerpelea commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

When CONFIG_MM_KASAN and CONFIG_BUILD_KERNEL are both enabled on
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.
This series fixes all three issues to make KASAN work correctly
in kernel mode on QEMU ARMv7-A.

Impact

RELEASE

Testing

CI

@jerpelea jerpelea requested review from anchao, simbit18 and yamt as code owners July 2, 2026 10:47
@github-actions github-actions Bot added Area: Build system Size: S The size of the change in this PR is small Board: arm labels Jul 2, 2026
leisiji added 3 commits July 2, 2026 17:21
…_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>
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>
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>
@xiaoxiang781216 xiaoxiang781216 merged commit 0f4f53f into apache:releases/13.0 Jul 3, 2026
24 of 41 checks passed
@jerpelea jerpelea deleted the bp-19198 branch July 3, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Build system Board: arm Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants