It may occur that a usermodehelper is scheduled before ub0 bound css is
initialized during late init. If this happens, the system will crash in
ub_enough_memory, which needs to dereference bound css.

To fix that let's initialize bound css right after cgroup_init.

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

Signed-off-by: Vladimir Davydov <vdavy...@virtuozzo.com>
---
 init/main.c             | 2 +-
 kernel/bc/beancounter.c | 8 +++-----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/init/main.c b/init/main.c
index 0f3533981674..ad443bea53a9 100644
--- a/init/main.c
+++ b/init/main.c
@@ -623,7 +623,6 @@ asmlinkage void __init start_kernel(void)
        cred_init();
        fork_init(totalram_pages);
        proc_caches_init();
-       ub_init_late();
        buffer_init();
        key_init();
        security_init();
@@ -636,6 +635,7 @@ asmlinkage void __init start_kernel(void)
        proc_root_init();
 #endif
        cgroup_init();
+       ub_init_late();
        cpuset_init();
        taskstats_init_early();
        delayacct_init();
diff --git a/kernel/bc/beancounter.c b/kernel/bc/beancounter.c
index 18188f7a42e8..b26d292e2881 100644
--- a/kernel/bc/beancounter.c
+++ b/kernel/bc/beancounter.c
@@ -1172,6 +1172,9 @@ static ctl_table ub_sysctl_root[] = {
 
 void __init ub_init_late(void)
 {
+       ub_set_mem_css(&ub0, task_subsys_state_check(&init_task,  
mem_cgroup_subsys_id, true));
+       ub_set_blkio_css(&ub0, task_subsys_state_check(&init_task, 
blkio_subsys_id, true));
+
        register_sysctl_table(ub_sysctl_root);
 }
 
@@ -1203,11 +1206,6 @@ int __init ub_init_cgroup(void)
                panic("Failed to mount beancounter cgroup: %ld\n",
                      PTR_ERR(ub_cgroup_mnt));
 
-       ub_set_mem_css(&ub0, cgroup_subsys_state(
-               cgroup_get_root(mem_cgroup_mnt), mem_cgroup_subsys_id));
-       ub_set_blkio_css(&ub0, cgroup_subsys_state(
-               cgroup_get_root(blkio_cgroup_mnt), blkio_subsys_id));
-
        return 0;
 }
 late_initcall(ub_init_cgroup);
-- 
2.1.4

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to