From 8f1f7f473d69f11e6d0d56541213611dd95531f2 Mon Sep 17 00:00:00 2001 From: Zefan Li Date: Sat, 30 Jan 2021 10:51:18 +0800 Subject: [PATCH] cgroup: check if cgroup root is alive in cgroupstats_show() euler inclusion category: bugfix bugzilla: 47460 CVE: N/A ------------------------------------------------- If a cgroup root is dying, show its hierarchy_id and num_cgroups as 0. Signed-off-by: Zefan Li Tested-by: Kefeng Wang Signed-off-by: Hanjun Guo Signed-off-by: Changchun Yu Reviewed-by: Zefan Li Signed-off-by: zhangyi (F) Signed-off-by: Lu Jialin Reviewed-by: xiu jianfeng Signed-off-by: Zheng Zengkai --- kernel/cgroup/cgroup-v1.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 32596fdbcd5b..01387b70cffb 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -655,6 +655,7 @@ int proc_cgroupstats_show(struct seq_file *m, void *v) { struct cgroup_subsys *ss; int i; + bool dead; seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); /* @@ -665,10 +666,13 @@ int proc_cgroupstats_show(struct seq_file *m, void *v) mutex_lock(&cgroup_mutex); for_each_subsys(ss, i) + for_each_subsys(ss, i) { + dead = percpu_ref_is_dying(&ss->root->cgrp.self.refcnt); seq_printf(m, "%s\t%d\t%d\t%d\n", - ss->legacy_name, ss->root->hierarchy_id, - atomic_read(&ss->root->nr_cgrps), + ss->legacy_name, dead ? 0 : ss->root->hierarchy_id, + dead ? 0 : atomic_read(&ss->root->nr_cgrps), cgroup_ssid_enabled(i)); + } mutex_unlock(&cgroup_mutex); return 0; -- GitLab