Re: [PATCH v2 2/5] sched,ptrace: Fix ptrace_check_attach() vs PREEMPT_RT
From: Oleg Nesterov
Date: Mon Apr 25 2022 - 13:47:37 EST
On 04/21, Peter Zijlstra wrote:
>
> @@ -2225,7 +2238,7 @@ static int ptrace_stop(int exit_code, in
> * schedule() will not sleep if there is a pending signal that
> * can awaken the task.
> */
> - current->jobctl |= JOBCTL_TRACED;
> + current->jobctl |= JOBCTL_TRACED | JOBCTL_TRACED_QUIESCE;
> set_special_state(TASK_TRACED);
OK, this looks wrong. I actually mean the previous patch which sets
JOBCTL_TRACED.
The problem is that the tracee can be already killed, so that
fatal_signal_pending(current) is true. In this case we can't rely on
signal_wake_up_state() which should clear JOBCTL_TRACED, or the
callers of ptrace_signal_wake_up/etc which clear this flag by hand.
In this case schedule() won't block and ptrace_stop() will leak
JOBCTL_TRACED. Unless I missed something.
We could check fatal_signal_pending() and damn! this is what I think
ptrace_stop() should have done from the very beginning. But for now
I'd suggest to simply clear this flag before return, along with
DELAY_WAKEKILL and LISTENING.
> current->jobctl &= ~JOBCTL_LISTENING;
> + current->jobctl &= ~JOBCTL_DELAY_WAKEKILL;
current->jobctl &=
~(~JOBCTL_TRACED | JOBCTL_DELAY_WAKEKILL | JOBCTL_LISTENING);
Oleg.