[PATCH v4] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe()

Nam Cao namcao at linutronix.de
Thu Jul 2 01:05:52 PDT 2026


Jiakai Xu <xujiakai2025 at iscas.ac.cn> writes:
> +	if (sp >= (unsigned long)task_stack_page(task) &&
> +	    sp < (unsigned long)task_stack_page(task) + THREAD_SIZE) {
> +		high = (unsigned long)task_pt_regs(task);
> +	} else if (task != current) {
> +		pr_warn("%s: sp (%lx) is not in task stack of %s\n",
> +			__func__, sp, task->comm);
> +		return;
> +	}
> +#ifdef CONFIG_VMAP_STACK
> +	else {
> +		unsigned long ovf_base =
> +			(unsigned long)this_cpu_ptr(overflow_stack);
> +
> +		if (sp >= ovf_base && sp < ovf_base + OVERFLOW_STACK_SIZE)
> +			high = ovf_base + OVERFLOW_STACK_SIZE;
> +	}
> +#endif

Looks functionally correct to me. But this #ifdef goes against the
kernel's coding style. See:
https://docs.kernel.org/process/coding-style.html

Can we
    else if (IS_ENABLED(CONFIG_VMAP_STACK))
just like the irq stack thing?

> +	if (IS_ENABLED(CONFIG_IRQ_STACKS) && !high) {
> +		unsigned long irq_base =
> +			(unsigned long)this_cpu_read(irq_stack_ptr);
> +
> +		if (sp >= irq_base && sp < irq_base + IRQ_STACK_SIZE)
> +			high = irq_base + IRQ_STACK_SIZE;
> +	}



More information about the linux-riscv mailing list