Skip to content

Commit f608ebd

Browse files
oleg-nesterovgregkh
authored andcommitted
pidns: fix vfork() after unshare(CLONE_NEWPID)
commit e79f525 upstream. Commit 8382fca ("pidns: Outlaw thread creation after unshare(CLONE_NEWPID)") nacks CLONE_VM if the forking process unshared pid_ns, this obviously breaks vfork: int main(void) { assert(unshare(CLONE_NEWUSER | CLONE_NEWPID) == 0); assert(vfork() >= 0); _exit(0); return 0; } fails without this patch. Change this check to use CLONE_SIGHAND instead. This also forbids CLONE_THREAD automatically, and this is what the comment implies. We could probably even drop CLONE_SIGHAND and use CLONE_THREAD, but it would be safer to not do this. The current check denies CLONE_SIGHAND implicitely and there is no reason to change this. Eric said "CLONE_SIGHAND is fine. CLONE_THREAD would be even better. Having shared signal handling between two different pid namespaces is the case that we are fundamentally guarding against." Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reported-by: Colin Walters <walters@redhat.com> Acked-by: Andy Lutomirski <luto@amacapital.net> Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5a48788 commit f608ebd

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎kernel/fork.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
11711171
return ERR_PTR(-EINVAL);
11721172

11731173
/*
1174-
* If the new process will be in a different pid namespace
1175-
* don't allow the creation of threads.
1174+
* If the new process will be in a different pid namespace don't
1175+
* allow it to share a thread group or signal handlers with the
1176+
* forking task.
11761177
*/
1177-
if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) &&
1178+
if ((clone_flags & (CLONE_SIGHAND | CLONE_NEWPID)) &&
11781179
(task_active_pid_ns(current) != current->nsproxy->pid_ns))
11791180
return ERR_PTR(-EINVAL);
11801181

0 commit comments

Comments
 (0)