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

Submitted by Andrey Ryabinin on Dec. 10, 2018, 12:27 p.m.

Details

Message ID 20181210122708.5260-1-aryabinin@virtuozzo.com
State New
Series "mm/memcg: Fix NULL-ptr dereference when memcg diabled at boot."
Headers show

Commit Message

Andrey Ryabinin Dec. 10, 2018, 12:27 p.m.
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@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;