[Devel] [PATCH rh7] mm/memcg: Fix NULL-ptr dereference when memcg diabled at boot.

Andrey Ryabinin aryabinin at virtuozzo.com
Mon Dec 10 15:27:08 MSK 2018


If kernel booted with cgroup_disabl=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

https://pmc.acronis.com/browse/VSTOR-18694
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/memcontrol.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

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;
-- 
2.19.2



More information about the Devel mailing list