Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1515923imm; Thu, 19 Jul 2018 03:08:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe9Alq+IhdePVXQndkAvu6XkOb2qVcWcfbyXcP6261njA0nigH+Ak6RDHckX86y8dtrOmRq X-Received: by 2002:a17:902:a24:: with SMTP id 33-v6mr9471008plo.88.1531994936082; Thu, 19 Jul 2018 03:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531994936; cv=none; d=google.com; s=arc-20160816; b=1AzX87lqhGJjNP3/dboLRnL17DWAHwxrcdae1kL/mHOwqDbZAYRlWPUTEnB5RkL5B6 N9+4MCg9mI/X467hG8r18h2uG7mHf5AlChrrBHGADvRZWVCQDnYnZbtqyfHj4F7EHI9v HvtTt/Cte/iTM+2AR7v77dlINaBReE5k5sqIBj26sqyBaKpaCYGlb4xmqFJMGm7Y176H D6b8F2s1Vkfot9J0cQYt0Xk8+tuOIPR9Fq5WDUjhOhVMVRr3Mggcf/LxAHHuIZDEW/uY GWQwJDy89ldzkOCuh3+ZIt32gnYU34TSJ+nkKMrxFdzf81teDRo1ulLsU2bcucVxvR6U +6Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=RJhJrPg5vB3sWmzaN5lFkpQiPrD9UBbb70hv06tTUJ4=; b=rCUtZj64iaXmKwolrFTAk++5dThkeZR1cVpzV/W1C6Qu7UAxoLQ7Ki3nDZ3K2+uWSQ DrEhwaJqL95D+e0M0i/xAEWay78A3DcWnQhP6tzwoffM2aV9I4o5zLE4nDxjnkYt496Z KIjs4OAU4jjvMlpUTGeVjO85hBLWxIMlOsyd3S24TvHEjOCJ/+PzdBi/J9ZejLNGqEPy lmhW/TjevLwG/3C2OSFERRs97inALF16iiFPGy1BeC38P55fUyfQ9gKjADlWXwAbuhF7 3kW/qRTqljt7RQsNUvmUi45mpVV+sJQ1KqgNyU0r0ED2QpJuksWZxjajRPezGFbrPCy+ pN4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LGi5d0Bh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j20-v6si5533492pgl.594.2018.07.19.03.08.41; Thu, 19 Jul 2018 03:08:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LGi5d0Bh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731166AbeGSKtc (ORCPT + 99 others); Thu, 19 Jul 2018 06:49:32 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42693 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726640AbeGSKtb (ORCPT ); Thu, 19 Jul 2018 06:49:31 -0400 Received: by mail-pg1-f196.google.com with SMTP id y4-v6so3414637pgp.9; Thu, 19 Jul 2018 03:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RJhJrPg5vB3sWmzaN5lFkpQiPrD9UBbb70hv06tTUJ4=; b=LGi5d0BhcB4tPQcG26h5D5OhpGUIlojIG4lB+mcxmmVOvO9fCPITFBLoriP8vcRM7W SsWSt7yC/SnEFr/o6aB/TXMiOQmREPLLkqVa5BQFvTDvHSqGJWKSHaGIIoOkVWSwLQe1 KrU0wVvvDtdKlLueIiTTlwC8f9qMVPrqUMQjeYLuW5iTo4fpjHZNHexVbV+EM0LVpTOq uIMpyC1AYUc5TB2AyPETwm+MSx45Xw6DmgVOf4eeZ0KblVQ0eJ01Cl3zaeH6bgLE6HIA JN//NmrgXYw978tqx4SOoLj6fblWI+Afadq0lwGc9HEvu2zDHC5F0Xe7PUecthW5qKvg GJgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RJhJrPg5vB3sWmzaN5lFkpQiPrD9UBbb70hv06tTUJ4=; b=tZ8dL0VZfLfoRpl+prX/jMiA3X/TxJlw/thXiMSZ5TzGV57vww4TTV+gWl2Fhlc9Da PI05jVFZjcxbc0rdMRBVz3Xa/bnhtjfaRzADuJOWR9K0WEbhcGk97VBDErCLF5fk0Lfu jzFXS5hsFWG27YWtgvlKZS4dv+vP150s60EmrBJPtUmIXMRqmr/DsgrB715cVsaT2VpG 5Cq6T6u10OAzzIzVrk2U029rq1A4HdJiR/mSdBKLYS2BTPQiCv4Y5pwuQ9F33SDdhFCb 3e3QspPBe5oFY7RkeyhkYpfqAi3149ZE4ykwk3BIzZEhOV0WDfuo7yn+G8aGdsombYyf BceQ== X-Gm-Message-State: AOUpUlFpoeMDzNo1adzU6kJWGeC9oHNlxAv/HtUKKEWoWGrWWaS0oYyN JsPro3Eduqzh5m0AEtHqpXE= X-Received: by 2002:a65:62d8:: with SMTP id m24-v6mr9447904pgv.307.1531994827602; Thu, 19 Jul 2018 03:07:07 -0700 (PDT) Received: from localhost ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id r25-v6sm19077908pfj.42.2018.07.19.03.07.06 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 19 Jul 2018 03:07:07 -0700 (PDT) From: Jing Xia X-Google-Original-From: Jing Xia To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com Cc: chunyan.zhang@unisoc.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: memcg: fix use after free in mem_cgroup_iter() Date: Thu, 19 Jul 2018 18:06:47 +0800 Message-Id: <1531994807-25639-1-git-send-email-jing.xia@unisoc.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It was reported that a kernel crash happened in mem_cgroup_iter(), which can be triggered if the legacy cgroup-v1 non-hierarchical mode is used. Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b8f ...... Call trace: mem_cgroup_iter+0x2e0/0x6d4 shrink_zone+0x8c/0x324 balance_pgdat+0x450/0x640 kswapd+0x130/0x4b8 kthread+0xe8/0xfc ret_from_fork+0x10/0x20 mem_cgroup_iter(): ...... if (css_tryget(css)) <-- crash here break; ...... The crashing reason is that mem_cgroup_iter() uses the memcg object whose pointer is stored in iter->position, which has been freed before and filled with POISON_FREE(0x6b). And the root cause of the use-after-free issue is that invalidate_reclaim_iterators() fails to reset the value of iter->position to NULL when the css of the memcg is released in non- hierarchical mode. Signed-off-by: Jing Xia --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e6f0d5e..8c0280b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -850,7 +850,7 @@ static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg) int nid; int i; - while ((memcg = parent_mem_cgroup(memcg))) { + for (; memcg; memcg = parent_mem_cgroup(memcg)) { for_each_node(nid) { mz = mem_cgroup_nodeinfo(memcg, nid); for (i = 0; i <= DEF_PRIORITY; i++) { -- 1.9.1