Skip to content

Commit

Permalink
cgroup: fix use-after-free when umounting cgroupfs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>
  • Loading branch information
lizf-os authored and htejun committed Apr 26, 2013
1 parent 712317a commit cc20e01
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down

0 comments on commit cc20e01

Please sign in to comment.