[RHEL7,COMMIT] mm/memcg: Fix NULL-ptr dereference when memcg diabled at boot.

Submitted by Konstantin Khorenko on Dec. 12, 2018, 9:55 a.m.

Details

Message ID 201812120954.wBC9sxke008950@finist-ce7.sw.ru
State New
Series "mm/memcg: Fix NULL-ptr dereference when memcg diabled at boot."
Headers show

Commit Message

Konstantin Khorenko Dec. 12, 2018, 9:55 a.m.
The commit is pushed to "branch-rh7-3.10.0-862.20.2.vz7.73.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.20.2.vz7.73.18
------>
commit 790d189e1da53a2542286946d68046cd98ede820
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Wed Dec 12 12:54:59 2018 +0300

    mm/memcg: Fix NULL-ptr dereference when memcg diabled at boot.
    
    If kernel booted with cgroup_disable=memory, the memcg in mem_cgroup_swappiness()
    could be NULL. Derefernce memcg only if mem_cgroup_disabled() = false,
    otherwise:
    
     BUG: unable to handle kernel NULL pointer dereference at           (null)
     IP: [<ffffffff8122d6cc>] mem_cgroup_swappiness+0xc/0x30
    
     RIP: 0010:[<ffffffff8122d6cc>]  [<ffffffff8122d6cc>] mem_cgroup_swappiness+0xc/0x30
    
     Call Trace:
      [<ffffffff811c195a>] balance_pgdat+0x4ca/0x820
      [<ffffffff811c1e23>] kswapd+0x173/0x440
      [<ffffffff810bf741>] kthread+0xd1/0xe0
      [<ffffffff817556f7>] ret_from_fork_nospec_begin+0x21/0x21
    
    Note: kdump kernel is bootes with "cgroup_disable=memory" option by default.
    
    Found in the scope of
    https://pmc.acronis.com/browse/VSTOR-18694
    
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c889102fe955..31ba8dcb6bc7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2033,10 +2033,8 @@  static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg, bool kmem)
 
 int mem_cgroup_swappiness(struct mem_cgroup *memcg)
 {
-	struct cgroup *cgrp = memcg->css.cgroup;
-
 	/* root ? */
-	if (mem_cgroup_disabled() || cgrp->parent == NULL)
+	if (mem_cgroup_disabled() || memcg->css.cgroup->parent == NULL)
 		return vm_swappiness;
 
 	return memcg->swappiness;