[RHEL7,COMMIT] uprobes: Fix the memcg accounting

Submitted by Konstantin Khorenko on June 28, 2018, 2:35 p.m.


Message ID 201806281435.w5SEZaum020022@finist_ce7.work
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko June 28, 2018, 2:35 p.m.
The commit is pushed to "branch-rh7-3.10.0-862.3.2.vz7.61.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.3.2.vz7.61.6
commit 83b49d1c8ac49f9e31feea3ece5d674a3157b3d3
Author: Oleg Nesterov <oleg@redhat.com>
Date:   Thu Jun 28 17:35:36 2018 +0300

    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>
    (cherry picked from commit 6c4687cc17a788a6dd8de3e27dbeabb7cbd3e066)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 kernel/events/uprobes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 64d8e350db56..a04ed7f94d8d 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -135,8 +135,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;
+	}
 	page_add_new_anon_rmap(kpage, vma, addr);
@@ -163,7 +165,6 @@  static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
 	err = 0;
-	mem_cgroup_cancel_charge(kpage, memcg);
 	mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
 	return err;