aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorLi Zefan <lizefan@huawei.com>2014-09-04 02:43:38 -0400
committerTejun Heo <tj@kernel.org>2014-09-04 12:36:19 -0400
commitaa32362f011c6e863132b16c1761487166a4bad2 (patch)
tree21274b6b6111e83af93568c4e7c10357f4e58a0f /kernel
parenta4189487da1b4f8260c6006b9dc47c3c4107a5ae (diff)
cgroup: check cgroup liveliness before unbreaking kernfs
When cgroup_kn_lock_live() is called through some kernfs operation and another thread is calling cgroup_rmdir(), we'll trigger the warning in cgroup_get(). ------------[ cut here ]------------ WARNING: CPU: 1 PID: 1228 at kernel/cgroup.c:1034 cgroup_get+0x89/0xa0() ... Call Trace: [<c16ee73d>] dump_stack+0x41/0x52 [<c10468ef>] warn_slowpath_common+0x7f/0xa0 [<c104692d>] warn_slowpath_null+0x1d/0x20 [<c10bb999>] cgroup_get+0x89/0xa0 [<c10bbe58>] cgroup_kn_lock_live+0x28/0x70 [<c10be3c1>] __cgroup_procs_write.isra.26+0x51/0x230 [<c10be5b2>] cgroup_tasks_write+0x12/0x20 [<c10bb7b0>] cgroup_file_write+0x40/0x130 [<c11aee71>] kernfs_fop_write+0xd1/0x160 [<c1148e58>] vfs_write+0x98/0x1e0 [<c114934d>] SyS_write+0x4d/0xa0 [<c16f656b>] sysenter_do_call+0x12/0x12 ---[ end trace 6f2e0c38c2108a74 ]--- Fix this by calling css_tryget() instead of cgroup_get(). v2: - move cgroup_tryget() right below cgroup_get() definition. (Tejun) Cc: <stable@vger.kernel.org> # 3.15+ Reported-by: Toralf Förster <toralf.foerster@gmx.de> Signed-off-by: Zefan Li <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index bf30076664ca..940aced4ed00 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1035,6 +1035,11 @@ static void cgroup_get(struct cgroup *cgrp)
1035 css_get(&cgrp->self); 1035 css_get(&cgrp->self);
1036} 1036}
1037 1037
1038static bool cgroup_tryget(struct cgroup *cgrp)
1039{
1040 return css_tryget(&cgrp->self);
1041}
1042
1038static void cgroup_put(struct cgroup *cgrp) 1043static void cgroup_put(struct cgroup *cgrp)
1039{ 1044{
1040 css_put(&cgrp->self); 1045 css_put(&cgrp->self);
@@ -1147,7 +1152,8 @@ static struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn)
1147 * protection against removal. Ensure @cgrp stays accessible and 1152 * protection against removal. Ensure @cgrp stays accessible and
1148 * break the active_ref protection. 1153 * break the active_ref protection.
1149 */ 1154 */
1150 cgroup_get(cgrp); 1155 if (!cgroup_tryget(cgrp))
1156 return NULL;
1151 kernfs_break_active_protection(kn); 1157 kernfs_break_active_protection(kn);
1152 1158
1153 mutex_lock(&cgroup_mutex); 1159 mutex_lock(&cgroup_mutex);