]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - kernel/pid_namespace.c
rtc: tps6591x: wake up from suspend on alarm
[linux-2.6.git] / kernel / pid_namespace.c
index ea567b78d1aa6111bf207ac0556ff1e35b088794..a8968396046d3b2f9310c0ca6bd6bb0757c34cca 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/syscalls.h>
 #include <linux/err.h>
 #include <linux/acct.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
 
 #define BITS_PER_PAGE          (PAGE_SIZE*8)
 
@@ -67,10 +69,11 @@ err_alloc:
        return NULL;
 }
 
-static struct pid_namespace *create_pid_namespace(unsigned int level)
+static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_pid_ns)
 {
        struct pid_namespace *ns;
-       int i;
+       unsigned int level = parent_pid_ns->level + 1;
+       int i, err = -ENOMEM;
 
        ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL);
        if (ns == NULL)
@@ -86,6 +89,7 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)
 
        kref_init(&ns->kref);
        ns->level = level;
+       ns->parent = get_pid_ns(parent_pid_ns);
 
        set_bit(0, ns->pidmap[0].page);
        atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1);
@@ -93,14 +97,20 @@ static struct pid_namespace *create_pid_namespace(unsigned int level)
        for (i = 1; i < PIDMAP_ENTRIES; i++)
                atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
 
+       err = pid_ns_prepare_proc(ns);
+       if (err)
+               goto out_put_parent_pid_ns;
+
        return ns;
 
+out_put_parent_pid_ns:
+       put_pid_ns(parent_pid_ns);
 out_free_map:
        kfree(ns->pidmap[0].page);
 out_free:
        kmem_cache_free(pid_ns_cachep, ns);
 out:
-       return ERR_PTR(-ENOMEM);
+       return ERR_PTR(err);
 }
 
 static void destroy_pid_namespace(struct pid_namespace *ns)
@@ -114,25 +124,11 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
 
 struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old_ns)
 {
-       struct pid_namespace *new_ns;
-
-       BUG_ON(!old_ns);
-       new_ns = get_pid_ns(old_ns);
        if (!(flags & CLONE_NEWPID))
-               goto out;
-
-       new_ns = ERR_PTR(-EINVAL);
-       if (flags & CLONE_THREAD)
-               goto out_put;
-
-       new_ns = create_pid_namespace(old_ns->level + 1);
-       if (!IS_ERR(new_ns))
-               new_ns->parent = get_pid_ns(old_ns);
-
-out_put:
-       put_pid_ns(old_ns);
-out:
-       return new_ns;
+               return get_pid_ns(old_ns);
+       if (flags & (CLONE_THREAD|CLONE_PARENT))
+               return ERR_PTR(-EINVAL);
+       return create_pid_namespace(old_ns);
 }
 
 void free_pid_ns(struct kref *kref)
@@ -152,6 +148,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 {
        int nr;
        int rc;
+       struct task_struct *task;
 
        /*
         * The last thread in the cgroup-init thread group is terminating.
@@ -169,7 +166,18 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
        read_lock(&tasklist_lock);
        nr = next_pidmap(pid_ns, 1);
        while (nr > 0) {
-               kill_proc_info(SIGKILL, SEND_SIG_PRIV, nr);
+               rcu_read_lock();
+
+               /*
+                * Any nested-container's init processes won't ignore the
+                * SEND_SIG_NOINFO signal, see send_signal()->si_fromuser().
+                */
+               task = pid_task(find_vpid(nr), PIDTYPE_PID);
+               if (task)
+                       send_sig_info(SIGKILL, SEND_SIG_NOINFO, task);
+
+               rcu_read_unlock();
+
                nr = next_pidmap(pid_ns, nr);
        }
        read_unlock(&tasklist_lock);
@@ -179,16 +187,44 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
                rc = sys_wait4(-1, NULL, __WALL, NULL);
        } while (rc != -ECHILD);
 
-
-       /* Child reaper for the pid namespace is going away */
-       pid_ns->child_reaper = NULL;
        acct_exit_ns(pid_ns);
        return;
 }
 
+static int pid_ns_ctl_handler(struct ctl_table *table, int write,
+               void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+       struct ctl_table tmp = *table;
+
+       if (write && !capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       /*
+        * Writing directly to ns' last_pid field is OK, since this field
+        * is volatile in a living namespace anyway and a code writing to
+        * it should synchronize its usage with external means.
+        */
+
+       tmp.data = &current->nsproxy->pid_ns->last_pid;
+       return proc_dointvec(&tmp, write, buffer, lenp, ppos);
+}
+
+static struct ctl_table pid_ns_ctl_table[] = {
+       {
+               .procname = "ns_last_pid",
+               .maxlen = sizeof(int),
+               .mode = 0666, /* permissions are checked in the handler */
+               .proc_handler = pid_ns_ctl_handler,
+       },
+       { }
+};
+
+static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } };
+
 static __init int pid_namespaces_init(void)
 {
        pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
+       register_sysctl_paths(kern_path, pid_ns_ctl_table);
        return 0;
 }