Re: [PATCH] proc: Disable /proc/$pid/wchan

From: Peter Zijlstra
Date: Wed Sep 29 2021 - 15:46:10 EST


On Wed, Sep 29, 2021 at 11:54:55AM -0700, Kees Cook wrote:

> > > > > > It's supposed to show where a blocked task is blocked; the "wait
> > > > > > channel".

> Since I think we're considering get_wchan() to be slow-path, can we just
> lock the runqueue and use arch_stack_walk_reliable()?

Funny thing, when a task is blocked it isn't on the runqueue :-)

So if all we want to do is capture a blocked task and fail otherwise we
don't need the rq->lock at all.

Something like:

unsigned long ip = 0;

raw_spin_lock_irq(&p->pi_lock);
state = READ_ONCE(p->__state);
smp_rmb(); /* see try_to_wake_up() */
if (state == TASK_RUNNING || state == TASK_WAKING || p->on_rq)
goto unlock;

ip = /* do actual stack walk on a blocked task */
unlock:
raw_spin_unlock_irq(&p->pi_lock);

return ip;


Should get us there.