Re: [PATCH v2] ptrace: fix ptrace vs tasklist_lock race on PREEMPT_RT.

From: Peter Zijlstra
Date: Mon Apr 11 2022 - 07:35:54 EST


On Fri, Apr 08, 2022 at 10:06:30PM +0200, Peter Zijlstra wrote:

> I'll ponder if wait_task_inactive() can simplify things..

This,.. so ptrace_check_attach(), which does ptrace_freeze_traced()
already does wait_task_inactive(), but on the 'wrong' side of things.

AFAICT, if we move that up, we're almost there, except that opens up a
detach+attach race. That could be fixed by doing another
wait_task_inactive(), but we can't due to locking :/

Let's see if I can make that work without making a mess of things.
Because ensuring the task is stuck in schedule() makes the whole
saved_state thing go away -- as you noted.