Skip to content

Commit 40a0d32

Browse files
oleg-nesterovtorvalds
authored andcommitted
fork: unify and tighten up CLONE_NEWUSER/CLONE_NEWPID checks
do_fork() denies CLONE_THREAD | CLONE_PARENT if NEWUSER | NEWPID. Then later copy_process() denies CLONE_SIGHAND if the new process will be in a different pid namespace (task_active_pid_ns() doesn't match current->nsproxy->pid_ns). This looks confusing and inconsistent. CLONE_NEWPID is very similar to the case when ->pid_ns was already unshared, we want the same restrictions so copy_process() should also nack CLONE_PARENT. And it would be better to deny CLONE_NEWUSER && CLONE_SIGHAND as well just for consistency. Kill the "CLONE_NEWUSER | CLONE_NEWPID" check in do_fork() and change copy_process() to do the same check along with ->pid_ns check we already have. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Andy Lutomirski <luto@amacapital.net> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Colin Walters <walters@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5167246 commit 40a0d32

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

‎kernel/fork.c‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,13 +1173,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
11731173
return ERR_PTR(-EINVAL);
11741174

11751175
/*
1176-
* If the new process will be in a different pid namespace don't
1177-
* allow it to share a thread group or signal handlers with the
1178-
* forking task.
1176+
* If the new process will be in a different pid or user namespace
1177+
* do not allow it to share a thread group or signal handlers or
1178+
* parent with the forking task.
11791179
*/
1180-
if ((clone_flags & CLONE_SIGHAND) && (task_active_pid_ns(current) !=
1181-
current->nsproxy->pid_ns_for_children))
1182-
return ERR_PTR(-EINVAL);
1180+
if (clone_flags & (CLONE_SIGHAND | CLONE_PARENT)) {
1181+
if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
1182+
(task_active_pid_ns(current) !=
1183+
current->nsproxy->pid_ns_for_children))
1184+
return ERR_PTR(-EINVAL);
1185+
}
11831186

11841187
retval = security_task_create(clone_flags);
11851188
if (retval)
@@ -1575,15 +1578,6 @@ long do_fork(unsigned long clone_flags,
15751578
int trace = 0;
15761579
long nr;
15771580

1578-
/*
1579-
* Do some preliminary argument and permissions checking before we
1580-
* actually start allocating stuff
1581-
*/
1582-
if (clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) {
1583-
if (clone_flags & (CLONE_THREAD|CLONE_PARENT))
1584-
return -EINVAL;
1585-
}
1586-
15871581
/*
15881582
* Determine whether and which event to report to ptracer. When
15891583
* called from kernel_thread or CLONE_UNTRACED is explicitly

0 commit comments

Comments
 (0)