lkml.org 
[lkml]   [2022]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v4 10/12] ptrace: Don't change __state
Oleg Nesterov <oleg@redhat.com> writes:

> On 05/05, Eric W. Biederman wrote:
>>
>> static void ptrace_unfreeze_traced(struct task_struct *task)
>> {
>> - if (READ_ONCE(task->__state) != __TASK_TRACED)
>> - return;
>> -
>> - WARN_ON(!task->ptrace || task->parent != current);
>> + unsigned long flags;
>>
>> /*
>> - * PTRACE_LISTEN can allow ptrace_trap_notify to wake us up remotely.
>> - * Recheck state under the lock to close this race.
>> + * The child may be awake and may have cleared
>> + * JOBCTL_PTRACE_FROZEN (see ptrace_resume). The child will
>> + * not set JOBCTL_PTRACE_FROZEN or enter __TASK_TRACED anew.
>> */
>> - spin_lock_irq(&task->sighand->siglock);
>> - if (READ_ONCE(task->__state) == __TASK_TRACED) {
>> + if (lock_task_sighand(task, &flags)) {
>
> But I still think that a lockless
>
> if (!(task->jobctl & JOBCTL_PTRACE_FROZEN))
> return;
>
> check at the start of ptrace_unfreeze_traced() makes sense to avoid
> lock_task_sighand() if possible.
>
> And ptrace_resume() can probably clear JOBCTL_PTRACE_FROZEN along with
> JOBCTL_TRACED to make this optimization work better. The same for
> ptrace_signal_wake_up().

What do you have that suggests that taking siglock there is a problem?

What you propose will definitely work as an incremental change, and
in an incremental change we can explain why doing the stupid simple
thing is not good enough.

I am not really opposed on any grounds except that simplicity is good,
and hard to get wrong.

Eric

\
 
 \ /
  Last update: 2022-05-10 17:24    [W:1.367 / U:0.368 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site