[PW_SID:1121692] [v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()#2214
[PW_SID:1121692] [v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()#2214linux-riscv-bot wants to merge 2 commits into
Conversation
The fp_is_valid() function uses ALIGN(sp, THREAD_SIZE) as the upper bound for the frame pointer check. This bound is calculated relative to the current sp and shifts upward when sp itself exceeds the valid stack region, allowing the unwinder to read past the end of the allocated task stack and triggering KASAN stack-out-of-bounds. Fix this by using absolute stack boundaries determined once before the unwind loop: - When sp is on the task stack, use the task's pt_regs as the upper bound. - When sp is on the overflow_stack (CONFIG_VMAP_STACK=y), use the overflow_stack's top as the boundary. - When sp is on the IRQ stack (CONFIG_IRQ_STACKS=y), use the IRQ stack's top as the boundary. - When sp is not on any known stack, warn and return. - For remote tasks (task != current), if sp is not on the task stack, warn and return since we cannot reliably determine the correct boundary from a different CPU's stacks. Make the DECLARE_PER_CPU(overflow_stack) unconditional in asm/stacktrace.h so that stacktrace.c can use IS_ENABLED(CONFIG_VMAP_STACK) instead of #ifdef, in line with the kernel coding style which discourages the use of #ifdef in .c files (https://docs.kernel.org/process/coding-style.html). This is safe because the DEFINE_PER_CPU (memory allocation) in traps.c remains guarded by CONFIG_VMAP_STACK; the reference in stacktrace.c is only compiled when IS_ENABLED(CONFIG_VMAP_STACK) evaluates to true. Fixes: a2a4d4a ("riscv: stacktrace: fixed walk_stackframe()") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Assisted-by: YuanSheng:DeepSeek-V3.2 Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
|
Patch 1: "[v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()" |
2b6a725 to
da477a6
Compare
PR for series 1121692 applied to workflow__riscv__fixes
Name: [v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1121692
Version: 5