[Devel] [PATCH rh7] ve/cpustat: don't try to update vcpustats for root_task_group

Andrey Ryabinin aryabinin at virtuozzo.com
Wed Jun 22 05:59:05 PDT 2016


root_task_group doesn't have vcpu stats. Attempt to upate those leads
to NULL-ptr deref:

	BUG: unable to handle kernel NULL pointer dereference at           (null)
	IP: [<ffffffff810b440c>] cpu_cgroup_update_vcpustat+0x13c/0x620
	...
	Call Trace:
	 [<ffffffff810bee3b>] cpu_cgroup_get_stat+0x7b/0x180
	 [<ffffffff810f1ef7>] ve_get_cpu_stat+0x27/0x70
	 [<ffffffffa01836a1>] fill_cpu_stat+0x91/0x1e0 [vzmon]
	 [<ffffffffa0183c6b>] vzcalls_ioctl+0x2bb/0x430 [vzmon]
	 [<ffffffffa018d0d5>] vzctl_ioctl+0x45/0x60 [vzdev]
	 [<ffffffff8120cfb5>] do_vfs_ioctl+0x255/0x4f0
	 [<ffffffff8120d2a4>] SyS_ioctl+0x54/0xa0
	 [<ffffffff81642ac9>] system_call_fastpath+0x16/0x1b

So, return -ENOENT if we asked for vcpu stats of root_task_group.

https://jira.sw.ru/browse/PSBM-48721

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 kernel/sched/core.c | 10 ++++++++--
 kernel/ve/ve.c      |  7 ++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index e885549..94deef4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9120,20 +9120,26 @@ int cpu_cgroup_proc_loadavg(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
-void cpu_cgroup_get_stat(struct cgroup *cgrp, struct kernel_cpustat *kstat)
+int cpu_cgroup_get_stat(struct cgroup *cgrp, struct kernel_cpustat *kstat)
 {
 	struct task_group *tg = cgroup_tg(cgrp);
 	int nr_vcpus = tg->nr_cpus ?: num_online_cpus();
 	int i;
 
+	kernel_cpustat_zero(kstat);
+
+	if (tg == &root_task_group)
+		return -ENOENT;
+
 	for_each_possible_cpu(i)
 		cpu_cgroup_update_stat(cgrp, i);
 
 	cpu_cgroup_update_vcpustat(cgrp);
 
-	kernel_cpustat_zero(kstat);
 	for (i = 0; i < nr_vcpus; i++)
 		kernel_cpustat_add(tg->vcpustat + i, kstat, kstat);
+
+	return 0;
 }
 
 int cpu_cgroup_get_avenrun(struct cgroup *cgrp, unsigned long *avenrun)
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 2459cb5..d196e3e 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1448,16 +1448,17 @@ int ve_get_cpu_avenrun(struct ve_struct *ve, unsigned long *avenrun)
 }
 EXPORT_SYMBOL(ve_get_cpu_avenrun);
 
-void cpu_cgroup_get_stat(struct cgroup *cgrp, struct kernel_cpustat *kstat);
+int cpu_cgroup_get_stat(struct cgroup *cgrp, struct kernel_cpustat *kstat);
 
 int ve_get_cpu_stat(struct ve_struct *ve, struct kernel_cpustat *kstat)
 {
 	struct cgroup_subsys_state *css;
+	int err;
 
 	css = ve_get_init_css(ve, cpu_cgroup_subsys_id);
-	cpu_cgroup_get_stat(css->cgroup, kstat);
+	err = cpu_cgroup_get_stat(css->cgroup, kstat);
 	css_put(css);
-	return 0;
+	return err;
 }
 EXPORT_SYMBOL(ve_get_cpu_stat);
 #endif /* CONFIG_CGROUP_SCHED */
-- 
2.7.3



More information about the Devel mailing list