summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorLi Zefan <lizefan@huawei.com>2013-04-26 11:58:02 -0700
committerTejun Heo <tj@kernel.org>2013-04-26 11:58:02 -0700
commitcc20e01cd607282d48f8ea538aba10fa850a4312 (patch)
tree598ff80edab2c3bb3547dcd109e35ed1291f4454 /kernel/cgroup.c
parent712317ad97f41e738e1a19aa0a6392a78a84094e (diff)
downloadop-kernel-dev-cc20e01cd607282d48f8ea538aba10fa850a4312.zip
op-kernel-dev-cc20e01cd607282d48f8ea538aba10fa850a4312.tar.gz
cgroup: fix use-after-free when umounting cgroupfs
Try: # mount -t cgroup xxx /cgroup # mkdir /cgroup/sub && rmdir /cgroup/sub && umount /cgroup And you might see this: ida_remove called for id=1 which is not allocated. It's because cgroup_kill_sb() is called to destroy root->cgroup_ida and free cgrp->root before ida_simple_removed() is called. What's worse is we're accessing cgrp->root while it has been freed. Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 192d762..bd4de46 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -848,9 +848,12 @@ static void cgroup_free_fn(struct work_struct *work)
*/
dput(cgrp->parent->dentry);
+ ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
+
/*
* Drop the active superblock reference that we took when we
- * created the cgroup
+ * created the cgroup. This will free cgrp->root, if we are
+ * holding the last reference to @sb.
*/
deactivate_super(cgrp->root->sb);
@@ -862,7 +865,6 @@ static void cgroup_free_fn(struct work_struct *work)
simple_xattrs_free(&cgrp->xattrs);
- ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
kfree(rcu_dereference_raw(cgrp->name));
kfree(cgrp);
}
OpenPOWER on IntegriCloud