Re: [PATCH 1/1] signal: on exit skip waiting for an ack from the tracer if it is frozen

From: Suren Baghdasaryan
Date: Wed Jul 03 2024 - 14:23:34 EST


On Wed, Jul 3, 2024 at 9:50 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> Suren, I am sorry for the late reply,
>
> On 06/30, Suren Baghdasaryan wrote:
> >
> > > I think it would better to simply change ptrace_stop() to check TIF_MEMDIE
> > > along with __fatal_signal_pending() and return in this case.
> >
> > I think this would not fix the case we are experiencing. In our case
> > the tracee is killed from the userspace (TIF_MEMDIE is not set yet),
>
> OK, I misunderstood the problem.
>
> > gets stuck in ptrace_stop() waiting for an ack from the tracer and
> > then is picked up by OOM-killer with the abovementioned consequences.
>
> and __task_will_free_mem() returns true if SIGNAL_GROUP_EXIT is set...
> Nevermind.
>
> > > Of course, this won't fix all problems.
> >
> > As I mentioned, I'm not an expert in ptrace, so I'll gladly try any
> > better solution if one is proposed.
>
> I do not see any solution, sorry.

Ok, in any case, thanks for the feedback!

Do you think if I resolve the race you mentioned (what if
try_to_freeze_tasks() does freeze_task(tracee->parent) right after the
check in ptrace_stop()) and replace cgroup_task_frozen() with
frozen(), this solution would be acceptable?
Your question about a tracer being traced itself and its tracer being
frozen *I think* would be quite rare. I don't think it's a common
pattern to trace a process which in turn is tracing another one. Or am
I wrong?
Thanks,
Suren.

>
> ptrace doesn't allow to intercept/nack SIGKILL, but at the same time it
> happily allows the killed tracee to sleep in PTRACE_EVENT_EXIT. And even
> another SIGKILL/whatever can't wake the tracee up.
>
> This is historical behaviour, I do not see how can we change it. Any
> change will break something.
>
> Oleg.
>