Skip to content

Commit 574c7e2

Browse files
committed
Merge branch 'for-4.7-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull more cgroup updates from Tejun Heo: "I forgot to include the patches which got applied to for-4.7-fixes late during last cycle. Eric's three patches fix bugs introduced with the namespace support" * 'for-4.7-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroupns: Only allow creation of hierarchies in the initial cgroup namespace cgroupns: Close race between cgroup_post_fork and copy_cgroup_ns cgroupns: Fix the locking in copy_cgroup_ns
2 parents a6408f6 + 726a499 commit 574c7e2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

kernel/cgroup.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,12 +2209,8 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
22092209
goto out_unlock;
22102210
}
22112211

2212-
/*
2213-
* We know this subsystem has not yet been bound. Users in a non-init
2214-
* user namespace may only mount hierarchies with no bound subsystems,
2215-
* i.e. 'none,name=user1'
2216-
*/
2217-
if (!opts.none && !capable(CAP_SYS_ADMIN)) {
2212+
/* Hierarchies may only be created in the initial cgroup namespace. */
2213+
if (ns != &init_cgroup_ns) {
22182214
ret = -EPERM;
22192215
goto out_unlock;
22202216
}
@@ -2956,6 +2952,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
29562952
int retval = 0;
29572953

29582954
mutex_lock(&cgroup_mutex);
2955+
percpu_down_write(&cgroup_threadgroup_rwsem);
29592956
for_each_root(root) {
29602957
struct cgroup *from_cgrp;
29612958

@@ -2970,6 +2967,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
29702967
if (retval)
29712968
break;
29722969
}
2970+
percpu_up_write(&cgroup_threadgroup_rwsem);
29732971
mutex_unlock(&cgroup_mutex);
29742972

29752973
return retval;
@@ -4337,6 +4335,8 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
43374335

43384336
mutex_lock(&cgroup_mutex);
43394337

4338+
percpu_down_write(&cgroup_threadgroup_rwsem);
4339+
43404340
/* all tasks in @from are being moved, all csets are source */
43414341
spin_lock_irq(&css_set_lock);
43424342
list_for_each_entry(link, &from->cset_links, cset_link)
@@ -4365,6 +4365,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
43654365
} while (task && !ret);
43664366
out_err:
43674367
cgroup_migrate_finish(&preloaded_csets);
4368+
percpu_up_write(&cgroup_threadgroup_rwsem);
43684369
mutex_unlock(&cgroup_mutex);
43694370
return ret;
43704371
}
@@ -6339,14 +6340,11 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
63396340
if (!ns_capable(user_ns, CAP_SYS_ADMIN))
63406341
return ERR_PTR(-EPERM);
63416342

6342-
mutex_lock(&cgroup_mutex);
6343+
/* It is not safe to take cgroup_mutex here */
63436344
spin_lock_irq(&css_set_lock);
6344-
63456345
cset = task_css_set(current);
63466346
get_css_set(cset);
6347-
63486347
spin_unlock_irq(&css_set_lock);
6349-
mutex_unlock(&cgroup_mutex);
63506348

63516349
new_ns = alloc_cgroup_ns();
63526350
if (IS_ERR(new_ns)) {

0 commit comments

Comments
 (0)