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

Jiakai Xu xujiakai2025 at iscas.ac.cn
Thu Jul 2 01:34:47 PDT 2026


Hi! Thanks for your review!

> > +	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?

You are right, that is my mistake. I will fix this.

I will wait a couple of days to see if there are any other suggestions 
from others. If not, I will submit a v5 with this change.

Thanks for the review!

> 
> > +	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;
> > +	}

Regards,
Jiakai




More information about the linux-riscv mailing list