linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, almasrymina@google.com,
	gscrivan@redhat.com, linux-mm@kvack.org, mike.kravetz@oracle.com,
	mm-commits@vger.kernel.org, rientjes@google.com, tj@kernel.org,
	torvalds@linux-foundation.org
Subject: [patch 3/5] hugetlb_cgroup: fix illegal access to memory
Date: Sat, 28 Mar 2020 19:17:22 -0700	[thread overview]
Message-ID: <20200329021722.W_psAYHe4%akpm@linux-foundation.org> (raw)
In-Reply-To: <20200328191456.4fc0b9ca86780f26c122399e@linux-foundation.org>

From: Mina Almasry <almasrymina@google.com>
Subject: hugetlb_cgroup: fix illegal access to memory

This appears to be a mistake in commit faced7e0806cf ("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 page_counter_try_charge has failed then it
seems it does not initialize counter, so
hugetlb_cgroup_from_counter(counter) ends up pointing to random memory,
causing kasan to complain.

Solution, 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.

Link: http://lkml.kernel.org/r/20200313223920.124230-1-almasrymina@google.com
Fixes: faced7e0806cf ("mm: hugetlb controller for cgroups v2")
Signed-off-by: Mina Almasry <almasrymina@google.com>
Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
Acked-by: Giuseppe Scrivano <gscrivan@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/hugetlb_cgroup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/mm/hugetlb_cgroup.c~hugetlb_cgroup-fix-illegal-access-to-memory
+++ a/mm/hugetlb_cgroup.c
@@ -240,8 +240,7 @@ again:
 	if (!page_counter_try_charge(&h_cg->hugepage[idx], nr_pages,
 				     &counter)) {
 		ret = -ENOMEM;
-		hugetlb_event(hugetlb_cgroup_from_counter(counter, idx), idx,
-			      HUGETLB_MAX);
+		hugetlb_event(h_cg, idx, HUGETLB_MAX);
 	}
 	css_put(&h_cg->css);
 done:
_


  parent reply	other threads:[~2020-03-29  2:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-29  2:14 incoming Andrew Morton
2020-03-29  2:17 ` [patch 1/5] mm/swapfile.c: move inode_lock out of claim_swapfile Andrew Morton
2020-03-29  2:17 ` [patch 2/5] drivers/base/memory.c: indicate all memory blocks as removable Andrew Morton
2020-03-29 16:46   ` Linus Torvalds
2020-03-29 18:03     ` David Hildenbrand
2020-03-29 18:28       ` Linus Torvalds
2020-03-29 19:11         ` David Hildenbrand
2020-03-29 19:15           ` Linus Torvalds
2020-03-29 19:43       ` Konstantin Ryabitsev
2020-03-29 19:55         ` Linus Torvalds
2020-03-29 19:56           ` Linus Torvalds
2020-03-30 14:46           ` Konstantin Ryabitsev
2020-03-30 14:54         ` David Hildenbrand
2020-04-01 13:35           ` David Hildenbrand
2020-04-01 15:33             ` Konstantin Ryabitsev
2020-04-01 15:40               ` David Hildenbrand
2020-03-29  2:17 ` Andrew Morton [this message]
2020-03-29  2:17 ` [patch 4/5] mm: fork: fix kernel_stack memcg stats for various stack implementations Andrew Morton
2020-03-29 16:41   ` Linus Torvalds
2020-03-29  2:17 ` [patch 5/5] mm/sparse: fix kernel crash with pfn_section_valid check Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200329021722.W_psAYHe4%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=gscrivan@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: [patch 3/5] hugetlb_cgroup: fix illegal access to memory' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).