[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CFB4D39F-24B9-4AD9-B19C-E2D14D38A808@brauner.io>
Date: Wed, 24 Jul 2019 20:27:21 +0200
From: Christian Brauner <christian@...uner.io>
To: Jann Horn <jannh@...gle.com>
CC: kernel list <linux-kernel@...r.kernel.org>,
Oleg Nesterov <oleg@...hat.com>, Arnd Bergmann <arnd@...db.de>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Kees Cook <keescook@...omium.org>,
"Joel Fernandes (Google)" <joel@...lfernandes.org>,
Thomas Gleixner <tglx@...utronix.de>,
Tejun Heo <tj@...nel.org>, David Howells <dhowells@...hat.com>,
Andy Lutomirski <luto@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Aleksa Sarai <cyphar@...har.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Al Viro <viro@...iv.linux.org.uk>,
kernel-team <kernel-team@...roid.com>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Linux API <linux-api@...r.kernel.org>
Subject: Re: [PATCH 4/5] pidfd: add CLONE_WAIT_PID
On July 24, 2019 8:14:26 PM GMT+02:00, Jann Horn <jannh@...gle.com> wrote:
>On Wed, Jul 24, 2019 at 4:48 PM Christian Brauner
><christian@...uner.io> wrote:
>> If CLONE_WAIT_PID is set the newly created process will not be
>> considered by process wait requests that wait generically on children
>> such as:
>>
>> syscall(__NR_wait4, -1, wstatus, options, rusage)
>> syscall(__NR_waitpid, -1, wstatus, options)
>> syscall(__NR_waitid, P_ALL, -1, siginfo, options, rusage)
>> syscall(__NR_waitid, P_PGID, -1, siginfo, options, rusage)
>> syscall(__NR_waitpid, -pid, wstatus, options)
>> syscall(__NR_wait4, -pid, wstatus, options, rusage)
>>
>> A process created with CLONE_WAIT_PID can only be waited upon with a
>> focussed wait call. This ensures that processes can be reaped even if
>> all file descriptors referring to it are closed.
>[...]
>> diff --git a/kernel/fork.c b/kernel/fork.c
>> index baaff6570517..a067f3876e2e 100644
>> --- a/kernel/fork.c
>> +++ b/kernel/fork.c
>> @@ -1910,6 +1910,8 @@ static __latent_entropy struct task_struct
>*copy_process(
>> delayacct_tsk_init(p); /* Must remain after
>dup_task_struct() */
>> p->flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER | PF_IDLE);
>> p->flags |= PF_FORKNOEXEC;
>> + if (clone_flags & CLONE_WAIT_PID)
>> + p->flags |= PF_WAIT_PID;
>> INIT_LIST_HEAD(&p->children);
>> INIT_LIST_HEAD(&p->sibling);
>> rcu_copy_process(p);
>
>This means that if a process with PF_WAIT_PID forks, the child
>inherits the flag, right? That seems unintended? You might have to add
>something like "if (clone_flags & CLONE_THREAD == 0) p->flags &=
>~PF_WAIT_PID;" before this. (I think threads do have to inherit the
>flag so that the case where a non-leader thread of the child goes
>through execve and steals the leader's identity is handled properly.)
>Or you could cram it somewhere into signal_struct instead of on the
>task - that might be a more logical place for it?
Hm, CLONE_WAIT_PID is only useable with CLONE_PIDFD which in turn is
not useable with CLONE_THREAD.
But we should probably make that explicit for CLONE_WAIT_PID too.
Powered by blists - more mailing lists