Re: RE: [PATCH 1/1] arm: get task_stack reference before dump_backtrace

From: bigeasy@xxxxxxxxxxxxx

Date: Tue Mar 31 2026 - 02:54:14 EST


On 2026-03-09 11:23:28 [+0530], Maninder Singh wrote:
> Hi,
Hi,

> >"otherwise if someone calls show_stack() for task" ... and the stack
> >trace given stops at show_stack() and doesn't show the "someone".
> >
> >I'd like to know _how_ this happens, and why ARM64 and now 32-bit ARM
> >are different from x86.
>
> I tried to simulate same thing on x86_64, it is also crashing.
>
> Just a dummy code to save task_struct to reproduce the race:
>
> + rcu_read_lock();
> + for_each_process(p) {
> + if (!strcmp(p->comm, "sleep")) {
> + check_task = p;
> + get_task_struct(p);
> + pr_emerg("get done for %s %d\n", p->comm, p->pid);
> + }
> + }
> + rcu_read_unlock();
>
> // in mean time here sleep binary will be exited.
>
> + show_stack(check_task, NULL, KERN_EMERG);

The task's stack is released on its final schedule() invocation.
Therefore holding task_struct does not hold the stack of the task if it
is separated out of task_struct and can be gone if the tasks quits.

Therefore holding a reference to the stack while accessing it, like
during a backtrace, makes sense and is required if the task is not
current.

Let me add this to my list and tackle it later today for x86. Then we
get probably Russell on board for ARM.

> //OOPs

Sebastian