aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cgroups/cgroups.txt2
-rw-r--r--arch/mips/configs/bcm47xx_defconfig1
-rw-r--r--arch/mn10300/configs/asb2364_defconfig1
-rw-r--r--arch/powerpc/configs/ppc6xx_defconfig1
-rw-r--r--arch/powerpc/configs/pseries_defconfig1
-rw-r--r--arch/sh/configs/apsh4ad0a_defconfig1
-rw-r--r--arch/sh/configs/sdk7786_defconfig1
-rw-r--r--arch/sh/configs/se7206_defconfig1
-rw-r--r--arch/sh/configs/shx3_defconfig1
-rw-r--r--arch/sh/configs/urquell_defconfig1
-rw-r--r--arch/x86/configs/i386_defconfig1
-rw-r--r--arch/x86/configs/x86_64_defconfig1
-rw-r--r--include/linux/cgroup.h3
-rw-r--r--include/linux/cgroup_subsys.h6
-rw-r--r--include/linux/nsproxy.h9
-rw-r--r--init/Kconfig8
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/cgroup.c116
-rw-r--r--kernel/cpuset.c7
-rw-r--r--kernel/fork.c6
-rw-r--r--kernel/ns_cgroup.c118
-rw-r--r--kernel/nsproxy.c4
22 files changed, 4 insertions, 287 deletions
diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
index 8c4f3466c894..0ed99f08f1f3 100644
--- a/Documentation/cgroups/cgroups.txt
+++ b/Documentation/cgroups/cgroups.txt
@@ -651,7 +651,7 @@ always handled well.
651void post_clone(struct cgroup_subsys *ss, struct cgroup *cgrp) 651void post_clone(struct cgroup_subsys *ss, struct cgroup *cgrp)
652(cgroup_mutex held by caller) 652(cgroup_mutex held by caller)
653 653
654Called at the end of cgroup_clone() to do any parameter 654Called during cgroup_create() to do any parameter
655initialization which might be required before a task could attach. For 655initialization which might be required before a task could attach. For
656example in cpusets, no task may attach before 'cpus' and 'mems' are set 656example in cpusets, no task may attach before 'cpus' and 'mems' are set
657up. 657up.
diff --git a/arch/mips/configs/bcm47xx_defconfig b/arch/mips/configs/bcm47xx_defconfig
index 22fdf2f0cc23..ad15fb10322b 100644
--- a/arch/mips/configs/bcm47xx_defconfig
+++ b/arch/mips/configs/bcm47xx_defconfig
@@ -16,7 +16,6 @@ CONFIG_TASK_IO_ACCOUNTING=y
16CONFIG_AUDIT=y 16CONFIG_AUDIT=y
17CONFIG_TINY_RCU=y 17CONFIG_TINY_RCU=y
18CONFIG_CGROUPS=y 18CONFIG_CGROUPS=y
19CONFIG_CGROUP_NS=y
20CONFIG_CGROUP_CPUACCT=y 19CONFIG_CGROUP_CPUACCT=y
21CONFIG_RELAY=y 20CONFIG_RELAY=y
22CONFIG_BLK_DEV_INITRD=y 21CONFIG_BLK_DEV_INITRD=y
diff --git a/arch/mn10300/configs/asb2364_defconfig b/arch/mn10300/configs/asb2364_defconfig
index 31d76261a3d5..fbb96ae3122a 100644
--- a/arch/mn10300/configs/asb2364_defconfig
+++ b/arch/mn10300/configs/asb2364_defconfig
@@ -8,7 +8,6 @@ CONFIG_TASK_XACCT=y
8CONFIG_TASK_IO_ACCOUNTING=y 8CONFIG_TASK_IO_ACCOUNTING=y
9CONFIG_LOG_BUF_SHIFT=14 9CONFIG_LOG_BUF_SHIFT=14
10CONFIG_CGROUPS=y 10CONFIG_CGROUPS=y
11CONFIG_CGROUP_NS=y
12CONFIG_CGROUP_FREEZER=y 11CONFIG_CGROUP_FREEZER=y
13CONFIG_CGROUP_DEVICE=y 12CONFIG_CGROUP_DEVICE=y
14CONFIG_CGROUP_CPUACCT=y 13CONFIG_CGROUP_CPUACCT=y
diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
index 214208924a9c..04360f9b0109 100644
--- a/arch/powerpc/configs/ppc6xx_defconfig
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -10,7 +10,6 @@ CONFIG_TASK_XACCT=y
10CONFIG_TASK_IO_ACCOUNTING=y 10CONFIG_TASK_IO_ACCOUNTING=y
11CONFIG_AUDIT=y 11CONFIG_AUDIT=y
12CONFIG_CGROUPS=y 12CONFIG_CGROUPS=y
13CONFIG_CGROUP_NS=y
14CONFIG_CGROUP_DEVICE=y 13CONFIG_CGROUP_DEVICE=y
15CONFIG_CGROUP_CPUACCT=y 14CONFIG_CGROUP_CPUACCT=y
16CONFIG_RESOURCE_COUNTERS=y 15CONFIG_RESOURCE_COUNTERS=y
diff --git a/arch/powerpc/configs/pseries_defconfig b/arch/powerpc/configs/pseries_defconfig
index 7de13865508c..c9f212b5f3de 100644
--- a/arch/powerpc/configs/pseries_defconfig
+++ b/arch/powerpc/configs/pseries_defconfig
@@ -15,7 +15,6 @@ CONFIG_AUDITSYSCALL=y
15CONFIG_IKCONFIG=y 15CONFIG_IKCONFIG=y
16CONFIG_IKCONFIG_PROC=y 16CONFIG_IKCONFIG_PROC=y
17CONFIG_CGROUPS=y 17CONFIG_CGROUPS=y
18CONFIG_CGROUP_NS=y
19CONFIG_CGROUP_FREEZER=y 18CONFIG_CGROUP_FREEZER=y
20CONFIG_CGROUP_DEVICE=y 19CONFIG_CGROUP_DEVICE=y
21CONFIG_CPUSETS=y 20CONFIG_CPUSETS=y
diff --git a/arch/sh/configs/apsh4ad0a_defconfig b/arch/sh/configs/apsh4ad0a_defconfig
index 77ec0e7b8ddf..e7583484cc07 100644
--- a/arch/sh/configs/apsh4ad0a_defconfig
+++ b/arch/sh/configs/apsh4ad0a_defconfig
@@ -7,7 +7,6 @@ CONFIG_IKCONFIG=y
7CONFIG_IKCONFIG_PROC=y 7CONFIG_IKCONFIG_PROC=y
8CONFIG_LOG_BUF_SHIFT=14 8CONFIG_LOG_BUF_SHIFT=14
9CONFIG_CGROUPS=y 9CONFIG_CGROUPS=y
10CONFIG_CGROUP_NS=y
11CONFIG_CGROUP_FREEZER=y 10CONFIG_CGROUP_FREEZER=y
12CONFIG_CGROUP_DEVICE=y 11CONFIG_CGROUP_DEVICE=y
13CONFIG_CGROUP_CPUACCT=y 12CONFIG_CGROUP_CPUACCT=y
diff --git a/arch/sh/configs/sdk7786_defconfig b/arch/sh/configs/sdk7786_defconfig
index c41650572d79..8a7dd7b59c5c 100644
--- a/arch/sh/configs/sdk7786_defconfig
+++ b/arch/sh/configs/sdk7786_defconfig
@@ -12,7 +12,6 @@ CONFIG_IKCONFIG=y
12CONFIG_IKCONFIG_PROC=y 12CONFIG_IKCONFIG_PROC=y
13CONFIG_CGROUPS=y 13CONFIG_CGROUPS=y
14CONFIG_CGROUP_DEBUG=y 14CONFIG_CGROUP_DEBUG=y
15CONFIG_CGROUP_NS=y
16CONFIG_CGROUP_FREEZER=y 15CONFIG_CGROUP_FREEZER=y
17CONFIG_CGROUP_DEVICE=y 16CONFIG_CGROUP_DEVICE=y
18CONFIG_CPUSETS=y 17CONFIG_CPUSETS=y
diff --git a/arch/sh/configs/se7206_defconfig b/arch/sh/configs/se7206_defconfig
index a468ff227fc6..72c3fad7383f 100644
--- a/arch/sh/configs/se7206_defconfig
+++ b/arch/sh/configs/se7206_defconfig
@@ -8,7 +8,6 @@ CONFIG_RCU_TRACE=y
8CONFIG_LOG_BUF_SHIFT=14 8CONFIG_LOG_BUF_SHIFT=14
9CONFIG_CGROUPS=y 9CONFIG_CGROUPS=y
10CONFIG_CGROUP_DEBUG=y 10CONFIG_CGROUP_DEBUG=y
11CONFIG_CGROUP_NS=y
12CONFIG_CGROUP_DEVICE=y 11CONFIG_CGROUP_DEVICE=y
13CONFIG_CGROUP_CPUACCT=y 12CONFIG_CGROUP_CPUACCT=y
14CONFIG_RESOURCE_COUNTERS=y 13CONFIG_RESOURCE_COUNTERS=y
diff --git a/arch/sh/configs/shx3_defconfig b/arch/sh/configs/shx3_defconfig
index 3f92d37c6374..6bb413036892 100644
--- a/arch/sh/configs/shx3_defconfig
+++ b/arch/sh/configs/shx3_defconfig
@@ -9,7 +9,6 @@ CONFIG_IKCONFIG=y
9CONFIG_IKCONFIG_PROC=y 9CONFIG_IKCONFIG_PROC=y
10CONFIG_LOG_BUF_SHIFT=14 10CONFIG_LOG_BUF_SHIFT=14
11CONFIG_CGROUPS=y 11CONFIG_CGROUPS=y
12CONFIG_CGROUP_NS=y
13CONFIG_CGROUP_FREEZER=y 12CONFIG_CGROUP_FREEZER=y
14CONFIG_CGROUP_DEVICE=y 13CONFIG_CGROUP_DEVICE=y
15CONFIG_CGROUP_CPUACCT=y 14CONFIG_CGROUP_CPUACCT=y
diff --git a/arch/sh/configs/urquell_defconfig b/arch/sh/configs/urquell_defconfig
index 7b3daec6fefe..8bfa4d056d7a 100644
--- a/arch/sh/configs/urquell_defconfig
+++ b/arch/sh/configs/urquell_defconfig
@@ -9,7 +9,6 @@ CONFIG_IKCONFIG_PROC=y
9CONFIG_LOG_BUF_SHIFT=14 9CONFIG_LOG_BUF_SHIFT=14
10CONFIG_CGROUPS=y 10CONFIG_CGROUPS=y
11CONFIG_CGROUP_DEBUG=y 11CONFIG_CGROUP_DEBUG=y
12CONFIG_CGROUP_NS=y
13CONFIG_CGROUP_FREEZER=y 12CONFIG_CGROUP_FREEZER=y
14CONFIG_CGROUP_DEVICE=y 13CONFIG_CGROUP_DEVICE=y
15CONFIG_CPUSETS=y 14CONFIG_CPUSETS=y
diff --git a/arch/x86/configs/i386_defconfig b/arch/x86/configs/i386_defconfig
index 6f9872658dd2..2bf18059fbea 100644
--- a/arch/x86/configs/i386_defconfig
+++ b/arch/x86/configs/i386_defconfig
@@ -10,7 +10,6 @@ CONFIG_TASK_IO_ACCOUNTING=y
10CONFIG_AUDIT=y 10CONFIG_AUDIT=y
11CONFIG_LOG_BUF_SHIFT=18 11CONFIG_LOG_BUF_SHIFT=18
12CONFIG_CGROUPS=y 12CONFIG_CGROUPS=y
13CONFIG_CGROUP_NS=y
14CONFIG_CGROUP_FREEZER=y 13CONFIG_CGROUP_FREEZER=y
15CONFIG_CPUSETS=y 14CONFIG_CPUSETS=y
16CONFIG_CGROUP_CPUACCT=y 15CONFIG_CGROUP_CPUACCT=y
diff --git a/arch/x86/configs/x86_64_defconfig b/arch/x86/configs/x86_64_defconfig
index ee01a9d5d4f0..22a0dc8e51dd 100644
--- a/arch/x86/configs/x86_64_defconfig
+++ b/arch/x86/configs/x86_64_defconfig
@@ -11,7 +11,6 @@ CONFIG_TASK_IO_ACCOUNTING=y
11CONFIG_AUDIT=y 11CONFIG_AUDIT=y
12CONFIG_LOG_BUF_SHIFT=18 12CONFIG_LOG_BUF_SHIFT=18
13CONFIG_CGROUPS=y 13CONFIG_CGROUPS=y
14CONFIG_CGROUP_NS=y
15CONFIG_CGROUP_FREEZER=y 14CONFIG_CGROUP_FREEZER=y
16CONFIG_CPUSETS=y 15CONFIG_CPUSETS=y
17CONFIG_CGROUP_CPUACCT=y 16CONFIG_CGROUP_CPUACCT=y
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 1e6cde21fa3f..ab4ac0ccb857 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -555,9 +555,6 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,
555 return task_subsys_state(task, subsys_id)->cgroup; 555 return task_subsys_state(task, subsys_id)->cgroup;
556} 556}
557 557
558int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *ss,
559 char *nodename);
560
561/* A cgroup_iter should be treated as an opaque object */ 558/* A cgroup_iter should be treated as an opaque object */
562struct cgroup_iter { 559struct cgroup_iter {
563 struct list_head *cg_link; 560 struct list_head *cg_link;
diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h
index cdbfcb8780ec..ac663c18776c 100644
--- a/include/linux/cgroup_subsys.h
+++ b/include/linux/cgroup_subsys.h
@@ -19,12 +19,6 @@ SUBSYS(debug)
19 19
20/* */ 20/* */
21 21
22#ifdef CONFIG_CGROUP_NS
23SUBSYS(ns)
24#endif
25
26/* */
27
28#ifdef CONFIG_CGROUP_SCHED 22#ifdef CONFIG_CGROUP_SCHED
29SUBSYS(cpu_cgroup) 23SUBSYS(cpu_cgroup)
30#endif 24#endif
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index 7b370c7cfeff..50d20aba57d3 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -81,13 +81,4 @@ static inline void get_nsproxy(struct nsproxy *ns)
81 atomic_inc(&ns->count); 81 atomic_inc(&ns->count);
82} 82}
83 83
84#ifdef CONFIG_CGROUP_NS
85int ns_cgroup_clone(struct task_struct *tsk, struct pid *pid);
86#else
87static inline int ns_cgroup_clone(struct task_struct *tsk, struct pid *pid)
88{
89 return 0;
90}
91#endif
92
93#endif 84#endif
diff --git a/init/Kconfig b/init/Kconfig
index 332aac649966..ebafac4231ee 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -589,14 +589,6 @@ config CGROUP_DEBUG
589 589
590 Say N if unsure. 590 Say N if unsure.
591 591
592config CGROUP_NS
593 bool "Namespace cgroup subsystem"
594 help
595 Provides a simple namespace cgroup subsystem to
596 provide hierarchical naming of sets of namespaces,
597 for instance virtual servers and checkpoint/restart
598 jobs.
599
600config CGROUP_FREEZER 592config CGROUP_FREEZER
601 bool "Freezer cgroup subsystem" 593 bool "Freezer cgroup subsystem"
602 help 594 help
diff --git a/kernel/Makefile b/kernel/Makefile
index e9cf19155b46..2d64cfcc8b42 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -61,7 +61,6 @@ obj-$(CONFIG_COMPAT) += compat.o
61obj-$(CONFIG_CGROUPS) += cgroup.o 61obj-$(CONFIG_CGROUPS) += cgroup.o
62obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o 62obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
63obj-$(CONFIG_CPUSETS) += cpuset.o 63obj-$(CONFIG_CPUSETS) += cpuset.o
64obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
65obj-$(CONFIG_UTS_NS) += utsname.o 64obj-$(CONFIG_UTS_NS) += utsname.o
66obj-$(CONFIG_USER_NS) += user_namespace.o 65obj-$(CONFIG_USER_NS) += user_namespace.o
67obj-$(CONFIG_PID_NS) += pid_namespace.o 66obj-$(CONFIG_PID_NS) += pid_namespace.o
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 00a884342d3d..2731d115d725 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4630,122 +4630,6 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
4630} 4630}
4631 4631
4632/** 4632/**
4633 * cgroup_clone - clone the cgroup the given subsystem is attached to
4634 * @tsk: the task to be moved
4635 * @subsys: the given subsystem
4636 * @nodename: the name for the new cgroup
4637 *
4638 * Duplicate the current cgroup in the hierarchy that the given
4639 * subsystem is attached to, and move this task into the new
4640 * child.
4641 */
4642int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys,
4643 char *nodename)
4644{
4645 struct dentry *dentry;
4646 int ret = 0;
4647 struct cgroup *parent, *child;
4648 struct inode *inode;
4649 struct css_set *cg;
4650 struct cgroupfs_root *root;
4651 struct cgroup_subsys *ss;
4652
4653 /* We shouldn't be called by an unregistered subsystem */
4654 BUG_ON(!subsys->active);
4655
4656 /* First figure out what hierarchy and cgroup we're dealing
4657 * with, and pin them so we can drop cgroup_mutex */
4658 mutex_lock(&cgroup_mutex);
4659 again:
4660 root = subsys->root;
4661 if (root == &rootnode) {
4662 mutex_unlock(&cgroup_mutex);
4663 return 0;
4664 }
4665
4666 /* Pin the hierarchy */
4667 if (!atomic_inc_not_zero(&root->sb->s_active)) {
4668 /* We race with the final deactivate_super() */
4669 mutex_unlock(&cgroup_mutex);
4670 return 0;
4671 }
4672
4673 /* Keep the cgroup alive */
4674 task_lock(tsk);
4675 parent = task_cgroup(tsk, subsys->subsys_id);
4676 cg = tsk->cgroups;
4677 get_css_set(cg);
4678 task_unlock(tsk);
4679
4680 mutex_unlock(&cgroup_mutex);
4681
4682 /* Now do the VFS work to create a cgroup */
4683 inode = parent->dentry->d_inode;
4684
4685 /* Hold the parent directory mutex across this operation to
4686 * stop anyone else deleting the new cgroup */
4687 mutex_lock(&inode->i_mutex);
4688 dentry = lookup_one_len(nodename, parent->dentry, strlen(nodename));
4689 if (IS_ERR(dentry)) {
4690 printk(KERN_INFO
4691 "cgroup: Couldn't allocate dentry for %s: %ld\n", nodename,
4692 PTR_ERR(dentry));
4693 ret = PTR_ERR(dentry);
4694 goto out_release;
4695 }
4696
4697 /* Create the cgroup directory, which also creates the cgroup */
4698 ret = vfs_mkdir(inode, dentry, 0755);
4699 child = __d_cgrp(dentry);
4700 dput(dentry);
4701 if (ret) {
4702 printk(KERN_INFO
4703 "Failed to create cgroup %s: %d\n", nodename,
4704 ret);
4705 goto out_release;
4706 }
4707
4708 /* The cgroup now exists. Retake cgroup_mutex and check
4709 * that we're still in the same state that we thought we
4710 * were. */
4711 mutex_lock(&cgroup_mutex);
4712 if ((root != subsys->root) ||
4713 (parent != task_cgroup(tsk, subsys->subsys_id))) {
4714 /* Aargh, we raced ... */
4715 mutex_unlock(&inode->i_mutex);
4716 put_css_set(cg);
4717
4718 deactivate_super(root->sb);
4719 /* The cgroup is still accessible in the VFS, but
4720 * we're not going to try to rmdir() it at this
4721 * point. */
4722 printk(KERN_INFO
4723 "Race in cgroup_clone() - leaking cgroup %s\n",
4724 nodename);
4725 goto again;
4726 }
4727
4728 /* do any required auto-setup */
4729 for_each_subsys(root, ss) {
4730 if (ss->post_clone)
4731 ss->post_clone(ss, child);
4732 }
4733
4734 /* All seems fine. Finish by moving the task into the new cgroup */
4735 ret = cgroup_attach_task(child, tsk);
4736 mutex_unlock(&cgroup_mutex);
4737
4738 out_release:
4739 mutex_unlock(&inode->i_mutex);
4740
4741 mutex_lock(&cgroup_mutex);
4742 put_css_set(cg);
4743 mutex_unlock(&cgroup_mutex);
4744 deactivate_super(root->sb);
4745 return ret;
4746}
4747
4748/**
4749 * cgroup_is_descendant - see if @cgrp is a descendant of @task's cgrp 4633 * cgroup_is_descendant - see if @cgrp is a descendant of @task's cgrp
4750 * @cgrp: the cgroup in question 4634 * @cgrp: the cgroup in question
4751 * @task: the task in question 4635 * @task: the task in question
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 55b297d78adc..1ceeb049c827 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1802,10 +1802,9 @@ static int cpuset_populate(struct cgroup_subsys *ss, struct cgroup *cont)
1802} 1802}
1803 1803
1804/* 1804/*
1805 * post_clone() is called at the end of cgroup_clone(). 1805 * post_clone() is called during cgroup_create() when the
1806 * 'cgroup' was just created automatically as a result of 1806 * clone_children mount argument was specified. The cgroup
1807 * a cgroup_clone(), and the current task is about to 1807 * can not yet have any tasks.
1808 * be moved into 'cgroup'.
1809 * 1808 *
1810 * Currently we refuse to set up the cgroup - thereby 1809 * Currently we refuse to set up the cgroup - thereby
1811 * refusing the task to be entered, and as a result refusing 1810 * refusing the task to be entered, and as a result refusing
diff --git a/kernel/fork.c b/kernel/fork.c
index 1fa9d940e301..1f84099ecce6 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1229,12 +1229,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1229 if (clone_flags & CLONE_THREAD) 1229 if (clone_flags & CLONE_THREAD)
1230 p->tgid = current->tgid; 1230 p->tgid = current->tgid;
1231 1231
1232 if (current->nsproxy != p->nsproxy) {
1233 retval = ns_cgroup_clone(p, pid);
1234 if (retval)
1235 goto bad_fork_free_pid;
1236 }
1237
1238 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; 1232 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
1239 /* 1233 /*
1240 * Clear TID on mm_release()? 1234 * Clear TID on mm_release()?
diff --git a/kernel/ns_cgroup.c b/kernel/ns_cgroup.c
deleted file mode 100644
index 2c98ad94ba0e..000000000000
--- a/kernel/ns_cgroup.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 * ns_cgroup.c - namespace cgroup subsystem
3 *
4 * Copyright 2006, 2007 IBM Corp
5 */
6
7#include <linux/module.h>
8#include <linux/cgroup.h>
9#include <linux/fs.h>
10#include <linux/proc_fs.h>
11#include <linux/slab.h>
12#include <linux/nsproxy.h>
13
14struct ns_cgroup {
15 struct cgroup_subsys_state css;
16};
17
18struct cgroup_subsys ns_subsys;
19
20static inline struct ns_cgroup *cgroup_to_ns(
21 struct cgroup *cgroup)
22{
23 return container_of(cgroup_subsys_state(cgroup, ns_subsys_id),
24 struct ns_cgroup, css);
25}
26
27int ns_cgroup_clone(struct task_struct *task, struct pid *pid)
28{
29 char name[PROC_NUMBUF];
30
31 snprintf(name, PROC_NUMBUF, "%d", pid_vnr(pid));
32 return cgroup_clone(task, &ns_subsys, name);
33}
34
35/*
36 * Rules:
37 * 1. you can only enter a cgroup which is a descendant of your current
38 * cgroup
39 * 2. you can only place another process into a cgroup if
40 * a. you have CAP_SYS_ADMIN
41 * b. your cgroup is an ancestor of task's destination cgroup
42 * (hence either you are in the same cgroup as task, or in an
43 * ancestor cgroup thereof)
44 */
45static int ns_can_attach(struct cgroup_subsys *ss, struct cgroup *new_cgroup,
46 struct task_struct *task, bool threadgroup)
47{
48 if (current != task) {
49 if (!capable(CAP_SYS_ADMIN))
50 return -EPERM;
51
52 if (!cgroup_is_descendant(new_cgroup, current))
53 return -EPERM;
54 }
55
56 if (!cgroup_is_descendant(new_cgroup, task))
57 return -EPERM;
58
59 if (threadgroup) {
60 struct task_struct *c;
61 rcu_read_lock();
62 list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
63 if (!cgroup_is_descendant(new_cgroup, c)) {
64 rcu_read_unlock();
65 return -EPERM;
66 }
67 }
68 rcu_read_unlock();
69 }
70
71 return 0;
72}
73
74/*
75 * Rules: you can only create a cgroup if
76 * 1. you are capable(CAP_SYS_ADMIN)
77 * 2. the target cgroup is a descendant of your own cgroup
78 */
79static struct cgroup_subsys_state *ns_create(struct cgroup_subsys *ss,
80 struct cgroup *cgroup)
81{
82 struct ns_cgroup *ns_cgroup;
83
84 if (!capable(CAP_SYS_ADMIN))
85 return ERR_PTR(-EPERM);
86 if (!cgroup_is_descendant(cgroup, current))
87 return ERR_PTR(-EPERM);
88 if (test_bit(CGRP_CLONE_CHILDREN, &cgroup->flags)) {
89 printk("ns_cgroup can't be created with parent "
90 "'clone_children' set.\n");
91 return ERR_PTR(-EINVAL);
92 }
93
94 printk_once("ns_cgroup deprecated: consider using the "
95 "'clone_children' flag without the ns_cgroup.\n");
96
97 ns_cgroup = kzalloc(sizeof(*ns_cgroup), GFP_KERNEL);
98 if (!ns_cgroup)
99 return ERR_PTR(-ENOMEM);
100 return &ns_cgroup->css;
101}
102
103static void ns_destroy(struct cgroup_subsys *ss,
104 struct cgroup *cgroup)
105{
106 struct ns_cgroup *ns_cgroup;
107
108 ns_cgroup = cgroup_to_ns(cgroup);
109 kfree(ns_cgroup);
110}
111
112struct cgroup_subsys ns_subsys = {
113 .name = "ns",
114 .can_attach = ns_can_attach,
115 .create = ns_create,
116 .destroy = ns_destroy,
117 .subsys_id = ns_subsys_id,
118};
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 5424e37673ed..d6a00f3de15d 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -201,10 +201,6 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
201 goto out; 201 goto out;
202 } 202 }
203 203
204 err = ns_cgroup_clone(current, task_pid(current));
205 if (err)
206 put_nsproxy(*new_nsp);
207
208out: 204out:
209 return err; 205 return err;
210} 206}