linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] hugetlb_cgroup: fix illegal access to memory
@ 2020-03-13 22:39 Mina Almasry
  2020-03-13 22:48 ` Mina Almasry
  2020-03-24 18:24 ` Tejun Heo
  0 siblings, 2 replies; 5+ messages in thread
From: Mina Almasry @ 2020-03-13 22:39 UTC (permalink / raw)
  Cc: Mina Almasry, syzbot+cac0c4e204952cf449b1, Andrew Morton,
	linux-mm, linux-kernel, Giuseppe Scrivano, Tejun Heo,
	mike.kravetz, rientjes

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.

Signed-off-by: Mina Almasry <almasrymina@google.com>
Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2")
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Cc: Giuseppe Scrivano <gscrivan@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: mike.kravetz@oracle.com
Cc: rientjes@google.com

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

diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 7994eb8a2a0b4..aabf65d4d91ba 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -259,8 +259,7 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
 		    __hugetlb_cgroup_counter_from_cgroup(h_cg, idx, rsvd),
 		    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);
 		goto done;
 	}
--
2.25.1.481.gfbce0eb801-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] hugetlb_cgroup: fix illegal access to memory
  2020-03-13 22:39 [PATCH -next] hugetlb_cgroup: fix illegal access to memory Mina Almasry
@ 2020-03-13 22:48 ` Mina Almasry
  2020-03-14 18:20   ` Giuseppe Scrivano
  2020-03-24 18:24 ` Tejun Heo
  1 sibling, 1 reply; 5+ messages in thread
From: Mina Almasry @ 2020-03-13 22:48 UTC (permalink / raw)
  Cc: syzbot, Andrew Morton, Linux-MM, open list, Giuseppe Scrivano,
	Tejun Heo, Mike Kravetz, David Rientjes

On Fri, Mar 13, 2020 at 3:39 PM Mina Almasry <almasrymina@google.com> wrote:
>
> 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.
>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
> Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
> Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2")
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Cc: Giuseppe Scrivano <gscrivan@redhat.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: mike.kravetz@oracle.com
> Cc: rientjes@google.com
>
> ---
>  mm/hugetlb_cgroup.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> index 7994eb8a2a0b4..aabf65d4d91ba 100644
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -259,8 +259,7 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
>                     __hugetlb_cgroup_counter_from_cgroup(h_cg, idx, rsvd),
>                     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);
>                 goto done;
>         }
> --
> 2.25.1.481.gfbce0eb801-goog

The patch this fixes is in linus's tree, but isn't in 5.5 stable yet.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] hugetlb_cgroup: fix illegal access to memory
  2020-03-13 22:48 ` Mina Almasry
@ 2020-03-14 18:20   ` Giuseppe Scrivano
  2020-03-20 19:32     ` Mina Almasry
  0 siblings, 1 reply; 5+ messages in thread
From: Giuseppe Scrivano @ 2020-03-14 18:20 UTC (permalink / raw)
  To: Mina Almasry
  Cc: syzbot, Andrew Morton, Linux-MM, open list, Tejun Heo,
	Mike Kravetz, David Rientjes

Mina Almasry <almasrymina@google.com> writes:

> On Fri, Mar 13, 2020 at 3:39 PM Mina Almasry <almasrymina@google.com> wrote:
>>
>> 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.
>>
>> Signed-off-by: Mina Almasry <almasrymina@google.com>
>> Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
>> Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2")
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: linux-mm@kvack.org
>> Cc: linux-kernel@vger.kernel.org
>> Cc: Giuseppe Scrivano <gscrivan@redhat.com>
>> Cc: Tejun Heo <tj@kernel.org>
>> Cc: mike.kravetz@oracle.com
>> Cc: rientjes@google.com
>>
>> ---
>>  mm/hugetlb_cgroup.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
>> index 7994eb8a2a0b4..aabf65d4d91ba 100644
>> --- a/mm/hugetlb_cgroup.c
>> +++ b/mm/hugetlb_cgroup.c
>> @@ -259,8 +259,7 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
>>                     __hugetlb_cgroup_counter_from_cgroup(h_cg, idx, rsvd),
>>                     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);
>>                 goto done;
>>         }
>> --
>> 2.25.1.481.gfbce0eb801-goog

Acked-by: Giuseppe Scrivano <gscrivan@redhat.com>

Thanks,
Giuseppe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] hugetlb_cgroup: fix illegal access to memory
  2020-03-14 18:20   ` Giuseppe Scrivano
@ 2020-03-20 19:32     ` Mina Almasry
  0 siblings, 0 replies; 5+ messages in thread
From: Mina Almasry @ 2020-03-20 19:32 UTC (permalink / raw)
  To: Giuseppe Scrivano
  Cc: syzbot, Andrew Morton, Linux-MM, open list, Tejun Heo,
	Mike Kravetz, David Rientjes

Tejun/Mike you want to also give this a quick look?

On Sat, Mar 14, 2020 at 11:21 AM Giuseppe Scrivano <gscrivan@redhat.com> wrote:
>
> Mina Almasry <almasrymina@google.com> writes:
>
> > On Fri, Mar 13, 2020 at 3:39 PM Mina Almasry <almasrymina@google.com> wrote:
> >>
> >> 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.
> >>
> >> Signed-off-by: Mina Almasry <almasrymina@google.com>
> >> Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
> >> Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2")
> >> Cc: Andrew Morton <akpm@linux-foundation.org>
> >> Cc: linux-mm@kvack.org
> >> Cc: linux-kernel@vger.kernel.org
> >> Cc: Giuseppe Scrivano <gscrivan@redhat.com>
> >> Cc: Tejun Heo <tj@kernel.org>
> >> Cc: mike.kravetz@oracle.com
> >> Cc: rientjes@google.com
> >>
> >> ---
> >>  mm/hugetlb_cgroup.c | 3 +--
> >>  1 file changed, 1 insertion(+), 2 deletions(-)
> >>
> >> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> >> index 7994eb8a2a0b4..aabf65d4d91ba 100644
> >> --- a/mm/hugetlb_cgroup.c
> >> +++ b/mm/hugetlb_cgroup.c
> >> @@ -259,8 +259,7 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
> >>                     __hugetlb_cgroup_counter_from_cgroup(h_cg, idx, rsvd),
> >>                     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);
> >>                 goto done;
> >>         }
> >> --
> >> 2.25.1.481.gfbce0eb801-goog
>
> Acked-by: Giuseppe Scrivano <gscrivan@redhat.com>
>
> Thanks,
> Giuseppe
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next] hugetlb_cgroup: fix illegal access to memory
  2020-03-13 22:39 [PATCH -next] hugetlb_cgroup: fix illegal access to memory Mina Almasry
  2020-03-13 22:48 ` Mina Almasry
@ 2020-03-24 18:24 ` Tejun Heo
  1 sibling, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2020-03-24 18:24 UTC (permalink / raw)
  To: Mina Almasry
  Cc: syzbot+cac0c4e204952cf449b1, Andrew Morton, linux-mm,
	linux-kernel, Giuseppe Scrivano, mike.kravetz, rientjes

On Fri, Mar 13, 2020 at 03:39:20PM -0700, Mina Almasry wrote:
> 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.
> 
> Signed-off-by: Mina Almasry <almasrymina@google.com>
> Reported-by: syzbot+cac0c4e204952cf449b1@syzkaller.appspotmail.com
> Fixes: commit faced7e0806cf ("mm: hugetlb controller for cgroups v2")
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Cc: Giuseppe Scrivano <gscrivan@redhat.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: mike.kravetz@oracle.com
> Cc: rientjes@google.com

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-24 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 22:39 [PATCH -next] hugetlb_cgroup: fix illegal access to memory Mina Almasry
2020-03-13 22:48 ` Mina Almasry
2020-03-14 18:20   ` Giuseppe Scrivano
2020-03-20 19:32     ` Mina Almasry
2020-03-24 18:24 ` Tejun Heo

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).