pidns: Deny strange cases when creating pid namespaces.
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 2 Aug 2012 15:35:35 +0000 (08:35 -0700)
committerEric W. Biederman <ebiederm@xmission.com>
Mon, 19 Nov 2012 13:59:13 +0000 (05:59 -0800)
task_active_pid_ns(current) != current->ns_proxy->pid_ns will
soon be allowed to support unshare and setns.

The definition of creating a child pid namespace when
task_active_pid_ns(current) != current->ns_proxy->pid_ns could be that
we create a child pid namespace of current->ns_proxy->pid_ns.  However
that leads to strange cases like trying to have a single process be
init in multiple pid namespaces, which is racy and hard to think
about.

The definition of creating a child pid namespace when
task_active_pid_ns(current) != current->ns_proxy->pid_ns could be that
we create a child pid namespace of task_active_pid_ns(current).  While
that seems less racy it does not provide any utility.

Therefore define the semantics of creating a child pid namespace when
task_active_pid_ns(current) != current->ns_proxy->pid_ns to be that the
pid namespace creation fails.  That is easy to implement and easy
to think about.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
kernel/pid_namespace.c

index 3cc29b830e9ed8743bd9705c0a26f44275e9fc1c..0dbbc66b6ec6b1e6322ac1b3904522afe68d327e 100644 (file)
@@ -146,6 +146,8 @@ struct pid_namespace *copy_pid_ns(unsigned long flags,
                return get_pid_ns(old_ns);
        if (flags & (CLONE_THREAD|CLONE_PARENT))
                return ERR_PTR(-EINVAL);
+       if (task_active_pid_ns(current) != old_ns)
+               return ERR_PTR(-EINVAL);
        return create_pid_namespace(user_ns, old_ns);
 }