Skip to content

Commit 8d25879

Browse files
Phil Carmodytorvalds
authored andcommitted
cgroups: if you list_empty() a head then don't list_del() it
list_del() leaves poison in the prev and next pointers. The next list_empty() will compare those poisons, and say the list isn't empty. Any list operations that assume the node is on a list because of such a check will be fooled into dereferencing poison. One needs to INIT the node after the del, and fortunately there's already a wrapper for that - list_del_init(). Some of the dels are followed by deallocations, so can be ignored, and one can be merged with an add to make a move. Apart from that, I erred on the side of caution in making nodes list_empty()-queriable. Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com> Reviewed-by: Paul Menage <menage@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Kirill A. Shutemov <kirill@shutemov.name> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent edd4554 commit 8d25879

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎kernel/cgroup.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,8 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
18131813

18141814
/* Update the css_set linked lists if we're using them */
18151815
write_lock(&css_set_lock);
1816-
if (!list_empty(&tsk->cg_list)) {
1817-
list_del(&tsk->cg_list);
1818-
list_add(&tsk->cg_list, &newcg->tasks);
1819-
}
1816+
if (!list_empty(&tsk->cg_list))
1817+
list_move(&tsk->cg_list, &newcg->tasks);
18201818
write_unlock(&css_set_lock);
18211819

18221820
for_each_subsys(root, ss) {
@@ -3655,12 +3653,12 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
36553653
spin_lock(&release_list_lock);
36563654
set_bit(CGRP_REMOVED, &cgrp->flags);
36573655
if (!list_empty(&cgrp->release_list))
3658-
list_del(&cgrp->release_list);
3656+
list_del_init(&cgrp->release_list);
36593657
spin_unlock(&release_list_lock);
36603658

36613659
cgroup_lock_hierarchy(cgrp->root);
36623660
/* delete this cgroup from parent->children */
3663-
list_del(&cgrp->sibling);
3661+
list_del_init(&cgrp->sibling);
36643662
cgroup_unlock_hierarchy(cgrp->root);
36653663

36663664
d = dget(cgrp->dentry);
@@ -3879,7 +3877,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
38793877
subsys[ss->subsys_id] = NULL;
38803878

38813879
/* remove subsystem from rootnode's list of subsystems */
3882-
list_del(&ss->sibling);
3880+
list_del_init(&ss->sibling);
38833881

38843882
/*
38853883
* disentangle the css from all css_sets attached to the dummytop. as
@@ -4241,7 +4239,7 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
42414239
if (!list_empty(&tsk->cg_list)) {
42424240
write_lock(&css_set_lock);
42434241
if (!list_empty(&tsk->cg_list))
4244-
list_del(&tsk->cg_list);
4242+
list_del_init(&tsk->cg_list);
42454243
write_unlock(&css_set_lock);
42464244
}
42474245

0 commit comments

Comments
 (0)