[Devel] [PATCH rh9] mm: Fix nil dereference in __mem_cgroup_charge_gen()
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Mar 30 18:30:03 MSK 2022
When we're running kdump kernel it starts up with cgroup_disable=memory,
ie without memory cgroup. In result __mem_cgroup_charge_gen tries to
dereference nil pointer. Add an appropriate guard here.
__mem_cgroup_charge_gen() has been introduced in Virtuozzo kernel by
modifying __mem_cgroup_charge() which (in RHEL code) also does not
contain the check for memcg availability. But the check absence does not
lead us to problems because __mem_cgroup_charge() is always called
through the wrapper mem_cgroup_charge() which, in its turn, contains the
check for memcg availability.
So let's move the check from upper mem_cgroup_charge() to lower
__mem_cgroup_charge_gen().
https://jira.sw.ru/browse/PSBM-139098
Fixes: d5952f29e492 ("mm/memcg: limit page cache in memcg hack")
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
include/linux/memcontrol.h | 2 --
mm/memcontrol.c | 3 +++
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index f4833aba4fe2..f8dbf93da040 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -712,8 +712,6 @@ int __mem_cgroup_charge(struct page *page, struct mm_struct *mm,
static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
gfp_t gfp_mask)
{
- if (mem_cgroup_disabled())
- return 0;
return __mem_cgroup_charge(page, mm, gfp_mask);
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 6627c919a5f0..0d36dd1001f6 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -7486,6 +7486,9 @@ static int __mem_cgroup_charge_gen(struct page *page, struct mm_struct *mm,
struct mem_cgroup *memcg;
int ret;
+ if (mem_cgroup_disabled())
+ return 0;
+
memcg = get_mem_cgroup_from_mm(mm);
ret = charge_memcg(page, memcg, gfp_mask, cache_charge);
css_put(&memcg->css);
--
2.31.1
More information about the Devel
mailing list