fork: unify and tighten up CLONE_NEWUSER/CLONE_NEWPID checks
[deliverable/linux.git] / kernel / fork.c
index bf46287c91a45cc4f52d348d4be503e1ecf94620..84703db06cf355b072a5fcf6a3cfafb832d49b67 100644 (file)
@@ -1173,13 +1173,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
                return ERR_PTR(-EINVAL);
 
        /*
-        * If the new process will be in a different pid namespace
-        * don't allow the creation of threads.
+        * If the new process will be in a different pid or user namespace
+        * do not allow it to share a thread group or signal handlers or
+        * parent with the forking task.
         */
-       if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) &&
-           (task_active_pid_ns(current) !=
-            current->nsproxy->pid_ns_for_children))
-               return ERR_PTR(-EINVAL);
+       if (clone_flags & (CLONE_SIGHAND | CLONE_PARENT)) {
+               if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
+                   (task_active_pid_ns(current) !=
+                               current->nsproxy->pid_ns_for_children))
+                       return ERR_PTR(-EINVAL);
+       }
 
        retval = security_task_create(clone_flags);
        if (retval)
@@ -1575,15 +1578,6 @@ long do_fork(unsigned long clone_flags,
        int trace = 0;
        long nr;
 
-       /*
-        * Do some preliminary argument and permissions checking before we
-        * actually start allocating stuff
-        */
-       if (clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) {
-               if (clone_flags & (CLONE_THREAD|CLONE_PARENT))
-                       return -EINVAL;
-       }
-
        /*
         * Determine whether and which event to report to ptracer.  When
         * called from kernel_thread or CLONE_UNTRACED is explicitly
@@ -1824,11 +1818,6 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
         */
        if (unshare_flags & CLONE_NEWUSER)
                unshare_flags |= CLONE_THREAD | CLONE_FS;
-       /*
-        * If unsharing a pid namespace must also unshare the thread.
-        */
-       if (unshare_flags & CLONE_NEWPID)
-               unshare_flags |= CLONE_THREAD;
        /*
         * If unsharing a thread from a thread group, must also unshare vm.
         */
This page took 0.030342 seconds and 5 git commands to generate.