stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree
@ 2016-09-02 14:09 gregkh
  2016-09-12  7:39 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2016-09-02 14:09 UTC (permalink / raw)
  To: oleg, acme, acme, alexander.shishkin, alexei.starovoitov, bblanco,
	hannes, jolsa, mhocko, mingo, peterz, tglx, torvalds, vdavydov
  Cc: stable


The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

>From 6c4687cc17a788a6dd8de3e27dbeabb7cbd3e066 Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <oleg@redhat.com>
Date: Wed, 17 Aug 2016 17:36:29 +0200
Subject: [PATCH] uprobes: Fix the memcg accounting

__replace_page() wronlgy calls mem_cgroup_cancel_charge() in "success" path,
it should only do this if page_check_address() fails.

This means that every enable/disable leads to unbalanced mem_cgroup_uncharge()
from put_page(old_page), it is trivial to underflow the page_counter->count
and trigger OOM.

Reported-and-tested-by: Brenden Blanco <bblanco@plumgrid.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: stable@vger.kernel.org # 3.17+
Fixes: 00501b531c47 ("mm: memcontrol: rewrite charge API")
Link: http://lkml.kernel.org/r/20160817153629.GB29724@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index b7a525ab2083..8c50276b60d1 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -172,8 +172,10 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 	mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
 	err = -EAGAIN;
 	ptep = page_check_address(page, mm, addr, &ptl, 0);
-	if (!ptep)
+	if (!ptep) {
+		mem_cgroup_cancel_charge(kpage, memcg, false);
 		goto unlock;
+	}
 
 	get_page(kpage);
 	page_add_new_anon_rmap(kpage, vma, addr, false);
@@ -200,7 +202,6 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 
 	err = 0;
  unlock:
-	mem_cgroup_cancel_charge(kpage, memcg, false);
 	mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
 	unlock_page(page);
 	return err;


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

* Re: FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree
  2016-09-02 14:09 FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree gregkh
@ 2016-09-12  7:39 ` Michal Hocko
  2016-09-12 11:04   ` Oleg Nesterov
  2016-09-12 14:56   ` Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: Michal Hocko @ 2016-09-12  7:39 UTC (permalink / raw)
  To: gregkh
  Cc: oleg, acme, acme, alexander.shishkin, alexei.starovoitov, bblanco,
	hannes, jolsa, mingo, peterz, tglx, torvalds, vdavydov, stable

On Fri 02-09-16 16:09:57, Greg KH wrote:
> 
> The patch below does not apply to the 4.4-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

This should fix it
---
>From 714b2350cecc97085429a16a8de78f74804d477b Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <oleg@redhat.com>
Date: Wed, 17 Aug 2016 17:36:29 +0200
Subject: [PATCH] uprobes: Fix the memcg accounting

commit 6c4687cc17a788a6dd8de3e27dbeabb7cbd3e066 upstream.

__replace_page() wronlgy calls mem_cgroup_cancel_charge() in "success" path,
it should only do this if page_check_address() fails.

This means that every enable/disable leads to unbalanced mem_cgroup_uncharge()
from put_page(old_page), it is trivial to underflow the page_counter->count
and trigger OOM.

Reported-and-tested-by: Brenden Blanco <bblanco@plumgrid.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: stable@vger.kernel.org # 3.17+
Fixes: 00501b531c47 ("mm: memcontrol: rewrite charge API")
Link: http://lkml.kernel.org/r/20160817153629.GB29724@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 7dad84913abf..da0c09ff6112 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -171,8 +171,10 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 	mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
 	err = -EAGAIN;
 	ptep = page_check_address(page, mm, addr, &ptl, 0);
-	if (!ptep)
+	if (!ptep) {
+		mem_cgroup_cancel_charge(kpage, memcg);
 		goto unlock;
+	}
 
 	get_page(kpage);
 	page_add_new_anon_rmap(kpage, vma, addr);
@@ -199,7 +201,6 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 
 	err = 0;
  unlock:
-	mem_cgroup_cancel_charge(kpage, memcg);
 	mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
 	unlock_page(page);
 	return err;
-- 
2.9.3

-- 
Michal Hocko
SUSE Labs

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

* Re: FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree
  2016-09-12  7:39 ` Michal Hocko
@ 2016-09-12 11:04   ` Oleg Nesterov
  2016-09-12 14:56   ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2016-09-12 11:04 UTC (permalink / raw)
  To: Michal Hocko
  Cc: gregkh, acme, acme, alexander.shishkin, alexei.starovoitov,
	bblanco, hannes, jolsa, mingo, peterz, tglx, torvalds, vdavydov,
	stable

On 09/12, Michal Hocko wrote:
>
> On Fri 02-09-16 16:09:57, Greg KH wrote:
> >
> > The patch below does not apply to the 4.4-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.

Interestingly, I didn't receive this email...

> This should fix it

Yes, thanks a lot Michal!

Oleg.


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

* Re: FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree
  2016-09-12  7:39 ` Michal Hocko
  2016-09-12 11:04   ` Oleg Nesterov
@ 2016-09-12 14:56   ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2016-09-12 14:56 UTC (permalink / raw)
  To: Michal Hocko
  Cc: oleg, acme, acme, alexander.shishkin, alexei.starovoitov, bblanco,
	hannes, jolsa, mingo, peterz, tglx, torvalds, vdavydov, stable

On Mon, Sep 12, 2016 at 09:39:48AM +0200, Michal Hocko wrote:
> On Fri 02-09-16 16:09:57, Greg KH wrote:
> > 
> > The patch below does not apply to the 4.4-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
> 
> This should fix it
> ---
> >From 714b2350cecc97085429a16a8de78f74804d477b Mon Sep 17 00:00:00 2001
> From: Oleg Nesterov <oleg@redhat.com>
> Date: Wed, 17 Aug 2016 17:36:29 +0200
> Subject: [PATCH] uprobes: Fix the memcg accounting
> 
> commit 6c4687cc17a788a6dd8de3e27dbeabb7cbd3e066 upstream.

Thanks, now queued up.

greg k-h

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

end of thread, other threads:[~2016-09-12 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-02 14:09 FAILED: patch "[PATCH] uprobes: Fix the memcg accounting" failed to apply to 4.4-stable tree gregkh
2016-09-12  7:39 ` Michal Hocko
2016-09-12 11:04   ` Oleg Nesterov
2016-09-12 14:56   ` Greg KH

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