Skip to content

Commit 726b7bb

Browse files
minatorvalds
authored andcommitted
hugetlb_cgroup: fix illegal access to memory
This appears to be a mistake in commit faced7e ("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: faced7e ("mm: hugetlb controller for cgroups v2") Reported-by: [email protected] Signed-off-by: Mina Almasry <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Giuseppe Scrivano <[email protected]> Acked-by: Tejun Heo <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: David Rientjes <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 53cdc1c commit 726b7bb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

mm/hugetlb_cgroup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
240240
if (!page_counter_try_charge(&h_cg->hugepage[idx], nr_pages,
241241
&counter)) {
242242
ret = -ENOMEM;
243-
hugetlb_event(hugetlb_cgroup_from_counter(counter, idx), idx,
244-
HUGETLB_MAX);
243+
hugetlb_event(h_cg, idx, HUGETLB_MAX);
245244
}
246245
css_put(&h_cg->css);
247246
done:

0 commit comments

Comments
 (0)