linux-stable/arch/arm/kernel
Boy.Wu c4238686f9 ARM: 9381/1: kasan: clear stale stack poison
We found below OOB crash:

[   33.452494] ==================================================================
[   33.453513] BUG: KASAN: stack-out-of-bounds in refresh_cpu_vm_stats.constprop.0+0xcc/0x2ec
[   33.454660] Write of size 164 at addr c1d03d30 by task swapper/0/0
[   33.455515]
[   33.455767] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G           O       6.1.25-mainline #1
[   33.456880] Hardware name: Generic DT based system
[   33.457555]  unwind_backtrace from show_stack+0x18/0x1c
[   33.458326]  show_stack from dump_stack_lvl+0x40/0x4c
[   33.459072]  dump_stack_lvl from print_report+0x158/0x4a4
[   33.459863]  print_report from kasan_report+0x9c/0x148
[   33.460616]  kasan_report from kasan_check_range+0x94/0x1a0
[   33.461424]  kasan_check_range from memset+0x20/0x3c
[   33.462157]  memset from refresh_cpu_vm_stats.constprop.0+0xcc/0x2ec
[   33.463064]  refresh_cpu_vm_stats.constprop.0 from tick_nohz_idle_stop_tick+0x180/0x53c
[   33.464181]  tick_nohz_idle_stop_tick from do_idle+0x264/0x354
[   33.465029]  do_idle from cpu_startup_entry+0x20/0x24
[   33.465769]  cpu_startup_entry from rest_init+0xf0/0xf4
[   33.466528]  rest_init from arch_post_acpi_subsys_init+0x0/0x18
[   33.467397]
[   33.467644] The buggy address belongs to stack of task swapper/0/0
[   33.468493]  and is located at offset 112 in frame:
[   33.469172]  refresh_cpu_vm_stats.constprop.0+0x0/0x2ec
[   33.469917]
[   33.470165] This frame has 2 objects:
[   33.470696]  [32, 76) 'global_zone_diff'
[   33.470729]  [112, 276) 'global_node_diff'
[   33.471294]
[   33.472095] The buggy address belongs to the physical page:
[   33.472862] page:3cd72da8 refcount:1 mapcount:0 mapping:00000000 index:0x0 pfn:0x41d03
[   33.473944] flags: 0x1000(reserved|zone=0)
[   33.474565] raw: 00001000 ed741470 ed741470 00000000 00000000 00000000 ffffffff 00000001
[   33.475656] raw: 00000000
[   33.476050] page dumped because: kasan: bad access detected
[   33.476816]
[   33.477061] Memory state around the buggy address:
[   33.477732]  c1d03c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[   33.478630]  c1d03c80: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00 00 00
[   33.479526] >c1d03d00: 00 04 f2 f2 f2 f2 00 00 00 00 00 00 f1 f1 f1 f1
[   33.480415]                                                ^
[   33.481195]  c1d03d80: 00 00 00 00 00 00 00 00 00 00 04 f3 f3 f3 f3 f3
[   33.482088]  c1d03e00: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
[   33.482978] ==================================================================

We find the root cause of this OOB is that arm does not clear stale stack
poison in the case of cpuidle.

This patch refer to arch/arm64/kernel/sleep.S to resolve this issue.

From cited commit [1] that explain the problem

Functions which the compiler has instrumented for KASAN place poison on
the stack shadow upon entry and remove this poison prior to returning.

In the case of cpuidle, CPUs exit the kernel a number of levels deep in
C code.  Any instrumented functions on this critical path will leave
portions of the stack shadow poisoned.

If CPUs lose context and return to the kernel via a cold path, we
restore a prior context saved in __cpu_suspend_enter are forgotten, and
we never remove the poison they placed in the stack shadow area by
functions calls between this and the actual exit of the kernel.

Thus, (depending on stackframe layout) subsequent calls to instrumented
functions may hit this stale poison, resulting in (spurious) KASAN
splats to the console.

To avoid this, clear any stale poison from the idle thread for a CPU
prior to bringing a CPU online.

From cited commit [2]

Extend to check for CONFIG_KASAN_STACK

[1] commit 0d97e6d802 ("arm64: kasan: clear stale stack poison")
[2] commit d56a9ef84b ("kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK")

Signed-off-by: Boy Wu <boy.wu@mediatek.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Fixes: 5615f69bc2 ("ARM: 9016/2: Initialize the mapping of KASan shadow memory")
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
2024-04-29 14:11:25 +01:00
..
.gitignore
Makefile ARM updates for v6.9-rc1 2024-03-23 09:17:03 -07:00
arch_timer.c
armksyms.c
asm-offsets.c vdso/ARM: Make union vdso_data_store available for all architectures 2024-02-20 20:56:00 +01:00
atags.h ARM: 9011/1: centralize phys-to-virt conversion of DT/ATAGS address 2020-10-27 12:10:59 +00:00
atags_compat.c
atags_parse.c vgacon: clean up global screen_info instances 2023-10-17 10:17:02 +02:00
atags_proc.c atags_proc: Add __counted_by for struct buffer and use struct_size() 2023-12-02 12:32:07 -08:00
bios32.c PCI: Introduce pci_dev_for_each_resource() 2023-04-04 10:43:52 -05:00
bugs.c ARM: cpu: Switch to arch_cpu_finalize_init() 2023-06-16 10:15:59 +02:00
cpuidle.c ARM: cpuidle: Drop of_device.h include 2023-04-13 17:46:34 -05:00
crash_dump.c vmcore: convert copy_oldmem_page() to take an iov_iter 2022-04-29 14:37:59 -07:00
debug.S ARM: 9005/1: debug: Select flow control for all debug UARTs 2020-09-15 14:35:28 +01:00
devtree.c ARM: 9322/1: Explicitly include correct DT includes 2023-10-05 16:15:42 +01:00
dma.c
early_printk.c
efi.c vgacon: clean up global screen_info instances 2023-10-17 10:17:02 +02:00
elf.c
entry-armv.S Merge branch 'devel-stable' into for-next 2023-08-14 12:18:06 +01:00
entry-common.S ARM: ptrace: Restore syscall restart tracing 2023-08-16 13:58:49 -07:00
entry-ftrace.S ARM: ftrace: enable the graph tracer with the EABI unwinder 2022-02-09 09:13:59 +01:00
entry-header.S context_tracking: Split user tracking Kconfig 2022-06-29 17:04:09 -07:00
entry-v7m.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
fiq.c ARM: 9315/1: fiq: include asm/mach/irq.h for prototypes 2023-06-19 09:36:00 +01:00
fiqasm.S
ftrace.c ftrace: Remove return value of ftrace_arch_modify_*() 2022-05-26 21:13:00 -04:00
head-common.S ARM: implement THREAD_INFO_IN_TASK for uniprocessor systems 2021-12-06 12:49:17 +01:00
head-inflate-data.c ARM: 9310/1: xip-kernel: add __inflate_kernel_data prototype 2023-06-19 09:35:56 +01:00
head-nommu.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
head.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
head.h ARM: 9310/1: xip-kernel: add __inflate_kernel_data prototype 2023-06-19 09:35:56 +01:00
hibernate.c ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
hw_breakpoint.c hw_breakpoint: fix single-stepping when using bpf_overflow_handler 2023-08-18 17:04:09 +01:00
hyp-stub.S ARM: 9263/1: use .arch directives instead of assembler command line flags 2022-11-08 18:36:17 +00:00
insn.c ARM: 9078/1: Add warn suppress parameter to arm_gen_branch_link() 2021-06-07 12:56:20 +01:00
io.c
irq.c asm-generic: Conditionally enable do_softirq_own_stack() via Kconfig. 2022-09-05 17:20:55 +02:00
isa.c arm: Remove now superfluous sentinel elem from ctl_table arrays 2023-10-10 15:22:02 -07:00
iwmmxt.S ARM: 9352/1: iwmmxt: Remove support for PJ4/PJ4B cores 2024-02-26 10:16:31 +00:00
iwmmxt.h ARM: 9029/1: Make iwmmxt.S support Clang's integrated assembler 2020-12-08 10:14:59 +00:00
jump_label.c jump_label: make initial NOP patching the special case 2022-06-24 09:48:55 +02:00
kgdb.c ARM: Fix kgdb breakpoint for Thumb2 2022-02-21 14:56:53 +00:00
machine_kexec.c arch, crash: move arch_crash_save_vmcoreinfo() out to file vmcore_info.c 2024-02-23 17:48:25 -08:00
module-plts.c ARM: module: Use module_init_layout_section() to spot init sections 2023-08-03 13:42:02 -07:00
module.c ARM: 9299/1: module: use sign_extend32() to extend the signedness 2023-06-19 09:35:48 +01:00
opcodes.c
paravirt.c x86/paravirt: Switch time pvops functions to use static_call() 2021-03-11 16:17:52 +01:00
patch.c
perf_callchain.c ARM: 9258/1: stacktrace: Make stack walk callback consistent with generic code 2022-11-08 18:36:18 +00:00
perf_event_v6.c ARM: SoC code changes for 6.8 2024-01-11 11:42:53 -08:00
perf_event_v7.c arm: pmu: Move error message and -EOPNOTSUPP to individual PMUs 2023-12-12 09:46:22 +00:00
perf_event_xscale.c arm: perf: Remove PMU locking 2023-12-05 12:40:59 +00:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
phys2virt.S ARM: p2v: reduce p2v alignment requirement to 2 MiB 2020-10-28 16:59:43 +01:00
process.c ARM: kernel: Get rid of thread_info::used_cp[] array 2023-05-17 15:08:22 +02:00
psci_smp.c
ptrace.c ARM updates for v6.6-rc1 2023-08-31 12:49:10 -07:00
reboot.c ARM: 9219/1: fix undeclared soft_restart 2022-07-28 15:09:17 +01:00
reboot.h
relocate_kernel.S ARM: kexec: fix oops after TLB are invalidated 2021-02-05 10:23:29 +00:00
return_address.c ARM: 9258/1: stacktrace: Make stack walk callback consistent with generic code 2022-11-08 18:36:18 +00:00
setup.c arm, crash: wrap crash dumping code into crash related ifdefs 2024-02-23 17:48:24 -08:00
signal.c x86/shstk: Add user control-protection fault handler 2023-08-02 15:01:50 -07:00
signal.h
sigreturn_codes.S
sleep.S ARM: 9381/1: kasan: clear stale stack poison 2024-04-29 14:11:25 +01:00
smccc-call.S ARM: 9075/1: kernel: Fix interrupted SMC calls 2021-04-18 19:15:14 +01:00
smp.c nmi_backtrace: allow excluding an arbitrary CPU 2023-08-18 10:19:00 -07:00
smp_scu.c
smp_tlb.c
smp_twd.c
spectre.c ARM: fix build error when BPF_SYSCALL is disabled 2022-03-08 12:53:05 -08:00
stacktrace.c ARM: 9259/1: stacktrace: Convert stacktrace to generic ARCH_STACKWALK 2022-11-14 12:00:57 +00:00
suspend.c ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
swp_emulate.c ARM: 9263/1: use .arch directives instead of assembler command line flags 2022-11-08 18:36:17 +00:00
sys_arm.c ARM: 9309/1: add missing syscall prototypes 2023-06-19 09:35:55 +01:00
sys_oabi-compat.c ARM: 9309/1: add missing syscall prototypes 2023-06-19 09:35:55 +01:00
tcm.c ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
thumbee.c
time.c ARM: rpc: use legacy_timer_tick 2020-10-30 21:57:05 +01:00
topology.c ARM, sched/topology: Revert back to default scheduler topology 2020-08-19 10:49:47 +02:00
traps.c ARM: 9349/1: unwind: Add missing "Call trace:" line 2024-02-24 16:47:19 +00:00
unwind.c ARM: 9349/1: unwind: Add missing "Call trace:" line 2024-02-24 16:47:19 +00:00
v7m.c
vdso.c vdso/ARM: Make union vdso_data_store available for all architectures 2024-02-20 20:56:00 +01:00
vmcore_info.c arch, crash: move arch_crash_save_vmcoreinfo() out to file vmcore_info.c 2024-02-23 17:48:25 -08:00
vmlinux-xip.lds.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
vmlinux.lds.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
xscale-cp0.c ARM: iwmmxt: Use undef hook to enable coprocessor for task 2023-05-17 15:08:22 +02:00