Commit 726b7bbe authored by Mina Almasry's avatar Mina Almasry Committed by Linus Torvalds
Browse files

hugetlb_cgroup: fix illegal access to memory

This appears to be a mistake in commit faced7e0 ("mm: hugetlb
controller for cgroups v2").

Essentially that commit does a hugetlb_cgroup_from_counter assuming that
page_counter_try_charge has initialized counter.

But if that has failed then it seems will not initialize counter, so
hugetlb_cgroup_from_counter(counter) ends up pointing to random memory,
causing kasan to complain.

The solution is to simply use 'h_cg', instead of
hugetlb_cgroup_from_counter(counter), since that is a reference to the
hugetlb_cgroup anyway.  After this change kasan ceases to complain.

Fixes: faced7e0

 ("mm: hugetlb controller for cgroups v2")
Signed-off-by: default avatarMina Almasry <>
Signed-off-by: default avatarAndrew Morton <>
Acked-by: default avatarGiuseppe Scrivano <>
Acked-by: default avatarTejun Heo <>
Cc: Mike Kravetz <>
Cc: David Rientjes <>

Signed-off-by: default avatarLinus Torvalds <>
parent 53cdc1cb
......@@ -240,8 +240,7 @@ int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
if (!page_counter_try_charge(&h_cg->hugepage[idx], nr_pages,
&counter)) {
ret = -ENOMEM;
hugetlb_event(hugetlb_cgroup_from_counter(counter, idx), idx,
hugetlb_event(h_cg, idx, HUGETLB_MAX);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment