arm64: BUG: KASAN: invalid-access in arch_stack_walk
Catalin Marinas
catalin.marinas at arm.com
Tue Jun 24 02:00:38 PDT 2025
On Mon, Jun 23, 2025 at 09:56:33AM -0700, Breno Leitao wrote:
> arm64: Use arch_alloc_vmap_stack for EFI runtime stack allocation
>
> Refactor vmap stack allocation by moving the CONFIG_VMAP_STACK check
> from BUILD_BUG_ON to a runtime return of NULL if the config is not set.
> The side effect of this is that _init_sdei_stack() might NOT fail in
> build time if _VMAP_STACK, but in runtime. It shifts error
> detection from compile-time to runtime
_init_sdei_stack() is only called from init_sdei_stacks() if
CONFIG_VMAP_STACK is enabled.
> Then, reuse arch_alloc_vmap_stack() to allocate the ACPI stack
> memory in the arm64_efi_rt_init().
>
> Suggested-by: Andrey Konovalov <andreyknvl at gmail.com>
> Suggested-by: Catalin Marinas <catalin.marinas at arm.com>
> Signed-off-by: Breno Leitao <leitao at debian.org>
>
> diff --git a/arch/arm64/include/asm/vmap_stack.h b/arch/arm64/include/asm/vmap_stack.h
> index 20873099c035c..8380af4507d01 100644
> --- a/arch/arm64/include/asm/vmap_stack.h
> +++ b/arch/arm64/include/asm/vmap_stack.h
> @@ -19,7 +19,8 @@ static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)
> {
> void *p;
>
> - BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));
> + if (!IS_ENABLED(CONFIG_VMAP_STACK))
> + return NULL;
>
> p = __vmalloc_node(stack_size, THREAD_ALIGN, THREADINFO_GFP, node,
> __builtin_return_address(0));
We can leave this unchanged to catch possible misuses in the future.
> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> index 3857fd7ee8d46..6c371b158b99f 100644
> --- a/arch/arm64/kernel/efi.c
> +++ b/arch/arm64/kernel/efi.c
> @@ -15,6 +15,7 @@
>
> #include <asm/efi.h>
> #include <asm/stacktrace.h>
> +#include <asm/vmap_stack.h>
>
> static bool region_is_misaligned(const efi_memory_desc_t *md)
> {
> @@ -214,9 +215,8 @@ static int __init arm64_efi_rt_init(void)
> if (!efi_enabled(EFI_RUNTIME_SERVICES))
> return 0;
>
> - p = __vmalloc_node(THREAD_SIZE, THREAD_ALIGN, GFP_KERNEL,
> - NUMA_NO_NODE, &&l);
> -l: if (!p) {
> + p = arch_alloc_vmap_stack(THREAD_SIZE, NUMA_NO_NODE);
and bail out earlier here similar to init_sdei_stacks():
if (!IS_ENABLED(CONFIG_VMAP_STACK))
return -ENOMEM;
> + if (!p) {
> pr_warn("Failed to allocate EFI runtime stack\n");
> clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
> return -ENOMEM;
--
Catalin
More information about the linux-arm-kernel
mailing list