powerpc/kdump: fix KASAN sanitization flag for core_$(BITS).o
Subsystems (2)
PATCH v3 1/2 powerpc/kdump: fix KASAN sanitization flag for core_$(BITS).o
KASAN instrumentation is intended to be disabled for the kexec core code, but the existing Makefile entry misses the object suffix. As a result, the flag is not applied correctly to core_$(BITS).o.
So when KASAN is enabled, kexec_copy_flush and copy_segments in kexec/core_64.c are instrumented, which can result in accesses to shadow memory via normal address translation paths. Since these run with the MMU disabled, such accesses may trigger page faults (bad_page_fault) that cannot be handled in the kdump path, ultimately causing a hang and preventing the kdump kernel from booting. The same is true for kexec as well, since the same functions are used there.
Update the entry to include the “.o” suffix so that KASAN instrumentation is properly disabled for this object file.
---
Changelog:
v3:
- Cc stable mailing list
- No functional changes
v2:
- Add Reviewed-by, Acked-by and Tested-by tags
- No functional changes
- https://lore.kernel.org/all/[email protected]/
v1:
- https://lore.kernel.org/all/[email protected]/
--- arch/powerpc/kexec/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kexec/Makefile +1 -1
@@ -16,4 +16,4 @@ GCOV_PROFILE_core_$(BITS).o := n KCOV_INSTRUMENT_core_$(BITS).o := n UBSAN_SANITIZE_core_$(BITS).o := n KASAN_SANITIZE_core.o := n -KASAN_SANITIZE_core_$(BITS) := n +KASAN_SANITIZE_core_$(BITS).o := n
Signature · 1 line
2.52.0
PATCH v3 2/2 powerpc/vmx: avoid KASAN instrumentation in enter_vmx_ops() for kexec
The kexec sequence invokes enter_vmx_ops() via copy_page() with the MMU disabled. In this context, code must not rely on normal virtual address translations or trigger page faults.
With KASAN enabled, functions get instrumented and may access shadow memory using regular address translation. When executed with the MMU off, this can lead to page faults (bad_page_fault) from which the kernel cannot recover in the kexec path, resulting in a hang.
The kexec path sets preempt_count to HARDIRQ_OFFSET before entering the MMU-off copy sequence.
current_thread_info()->preempt_count = HARDIRQ_OFFSET
kexec_sequence(..., copy_with_mmu_off = 1)
-> kexec_copy_flush(image)
copy_segments()
-> copy_page(dest, addr)
bl enter_vmx_ops()
if (in_interrupt())
return 0
beq .Lnonvmx_copySince kexec sets preempt_count to HARDIRQ_OFFSET, in_interrupt() evaluates to true and enter_vmx_ops() returns early.
As in_interrupt() (and preempt_count()) are always inlined, mark enter_vmx_ops() with __no_sanitize_address to avoid KASAN instrumentation and shadow memory access with MMU disabled, helping kexec boot fine with KASAN enabled.
--- arch/powerpc/lib/vmx-helper.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/powerpc/lib/vmx-helper.c +8 -1
@@ -52,7 +52,14 @@ int exit_vmx_usercopy(void) }EXPORT_SYMBOL (exit_vmx_usercopy); -int enter_vmx_ops (void ) +/* +* Can be called from kexec copy_page() path with MMU off. The kexec +* code sets preempt_count to HARDIRQ_OFFSET so we return early here. +* Since in_interrupt() is always inline, __no_sanitize_address on this +* function is sufficient to avoid KASAN shadow memory accesses in real +* mode. +*/ +int __no_sanitize_address enter_vmx_ops(void) {if (in_interrupt ())return 0 ;
Signature · 1 line
2.52.0
Quoted 12 lines · Sourabh Jain
KASAN instrumentation is intended to be disabled for the kexec core code, but the existing
Makefileentry misses the object suffix. As a result, the flag is not applied correctly to core_$(BITS).o.So when KASAN is enabled,
kexec_copy_flushandcopy_segmentsinkexec/core_64.care instrumented, which can result in accesses to shadow memory via normal address translation paths. Since these run with the MMU disabled, such accesses may trigger page faults (bad_page_fault) that cannot be handled in the kdump path, ultimately causing a hang and preventing the kdump kernel from booting. The same is true for kexec as well, since the same functions are used there.
Quoted 1 line
[...]
Applied to powerpc/fixes.
[1/2] powerpc/kdump: fix KASAN sanitization flag for core_$(BITS).o
https://git.kernel.org/powerpc/c/b3a97f9484080c6e71db9e803e3cc1bb372a9bc7 [2/2] powerpc/vmx: avoid KASAN instrumentation in enter_vmx_ops() for kexec https://git.kernel.org/powerpc/c/38e989d504fc52900a3786b7144fb53cd67e0389
cheers