Re: [PATCH] signal: Avoid corrupting si_pid and si_uid in do_notify_parent

From: Oleg Nesterov
Date: Tue Apr 21 2020 - 07:12:06 EST


Sorry Christian, I don't understand...

On 04/21, Christian Brauner wrote:
>
> On Tue, Apr 21, 2020 at 11:28:47AM +0200, Oleg Nesterov wrote:
> > On 04/21, Christian Brauner wrote:
> > >
> > > > - __group_send_sig_info(sig, &info, tsk->parent);
> > > > + __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false);
> > >
> > > So below you switch to __send_signal() but set the "force" argument to
> > > to "false".
> >
> > it must be false, the signal is generated from the parent's namespace or
> > its descendant
> >
> > > Before that, if the signal was generated from another pid
> > > namespace and we fixed up si_pid and si_uid the "force" argument was set
> > > to "true",
> >
> > before that the "force" argument could be falsely true by the same reason,
> > task_pid_nr_ns(tsk, tsk->parent) can return 0 because "tsk" no longer have
> > pids after __unhash_process().
>
> As I said in my mail, looking at the codepath it seems safe. My question
> was whether it is _always_ incorrectly false which I do think it is

Again, it must be always "false", it can be incorrectly "true" and this
too is fixed by Eric's patch.

> because child subreapers can't come from outside the pid namespace. If
> they could you could create a scenario where the signal is generated
> from a sibling pid namespace in which case it would be correctly set to
> true.

not sure I understand, but probably the answer is "yes"...

task and task->parent either live in the same namespace or the child's
namespace is the descendant of task->parent's namespace. In both cases
task_pid_nr_ns(tsk, tsk->parent) should return the valid pid_nr and
"force" must be false.

The corner case is release_task() when the last exiting sub-thread sends
a signal on behalf of its ->group_leader, and at this point all the tsk's
pid pointers are NULL, that is why "force" can be falsely "true".

Oleg.