Skip to content

Commit cc20e01

Browse files
lizf-oshtejun
authored andcommitted
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>
1 parent 712317a commit cc20e01

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

kernel/cgroup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,12 @@ static void cgroup_free_fn(struct work_struct *work)
848848
*/
849849
dput(cgrp->parent->dentry);
850850

851+
ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
852+
851853
/*
852854
* Drop the active superblock reference that we took when we
853-
* created the cgroup
855+
* created the cgroup. This will free cgrp->root, if we are
856+
* holding the last reference to @sb.
854857
*/
855858
deactivate_super(cgrp->root->sb);
856859

@@ -862,7 +865,6 @@ static void cgroup_free_fn(struct work_struct *work)
862865

863866
simple_xattrs_free(&cgrp->xattrs);
864867

865-
ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
866868
kfree(rcu_dereference_raw(cgrp->name));
867869
kfree(cgrp);
868870
}

0 commit comments

Comments
 (0)