Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1887037imm; Thu, 19 Jul 2018 09:24:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdCBtgrmZcnqLv8GLyx7WZw+Gsf/FvvtVn4gSn4Eh6wJI7SU2U2k5nyKMSq9YA7gv+ItY95 X-Received: by 2002:a63:d15:: with SMTP id c21-v6mr10818153pgl.322.1532017451633; Thu, 19 Jul 2018 09:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532017451; cv=none; d=google.com; s=arc-20160816; b=o0B391B89uiXcE+f/FxYaWp+viZNPV0/rH4g+h3TTKn5JaxXI6ff6y/EcJLwW8Az1J vuz7XLwqDADb6dL62GSFdoLxv/nyE59X1IaxXGf4N03kNDPwj/Q9O8izwYY/LqPDOYfm BfEUxDCH4kCiCEhJJy2MyL7z0nDk+T9b2ub+3lddg+jq8R0eHHbn+zYVwEhri7dpo28O GYt9qUeg8skChPkSfPhKgUZe9E/PbCA9H1sE79g7rPEhmhe6fW3oYM6NWbRjk3n9dL3T TX59/prQU9/PopXlBgzAGTSzv7XdlnaoZMeJnWjyvGsgnLENnnbk+AmdqL98Z+NSlRfJ PQQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=eBoiAf+fwwTWl+wiFp1yO3mt7hvFDEp3X8YtzX7kZP0=; b=jztfNZKFaACbZkWj8oX53n1XdTDiOViaqfvijHO6WG62pgf8iCgWqqNlPY5+BxqxWO a9LjRZpEFyeZOx7+NSXcZ/pb1RbBaC+Mj7n5YiNtR32mHQff2tmu2nT9iHQ65rYdDd3L SwrjqFX0lCPU9dG3QhQT0tM8cVt9ApCX7AJtTLRHsXOOcBw8z8UUK81t3I8NKSIxKNZX 4X/DEMu++WMiFHDtlEqcN9utZPHC7roHWlO2OBXqCfdtMuTHgfVYXP2jDqyka5z+EE7a JF2j3+y9LLPpzMW8SmDqcV8/jmVGF+559TeI9nhZ1vmhRuttwkH30z5TnPcsO24aYY5U RTNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AYVALAM1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x128-v6si7001326pgx.156.2018.07.19.09.23.56; Thu, 19 Jul 2018 09:24:11 -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=@google.com header.s=20161025 header.b=AYVALAM1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731979AbeGSRHS (ORCPT + 99 others); Thu, 19 Jul 2018 13:07:18 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40593 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727575AbeGSRHS (ORCPT ); Thu, 19 Jul 2018 13:07:18 -0400 Received: by mail-wm0-f68.google.com with SMTP id z13-v6so7012910wma.5 for ; Thu, 19 Jul 2018 09:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eBoiAf+fwwTWl+wiFp1yO3mt7hvFDEp3X8YtzX7kZP0=; b=AYVALAM1T0pbUtNSDPlYcIIu3Banr3Wr6fsxxrrZR5Z0HyCn4h2o7wnzhVHr0PZZia iW0IyRnrkuIQZgQHeJk7qnxSPNRPgL8LhwpYv/lyQitQt33A9IEOtfzlZIQKafAaKKn8 +HDOM9YG5nP5Eo99YFwWr33tZ+b3kJ7ONZkbvO1no1r/ioUcIUMU0FTiYbIVp269aMRX 9IzxX1BMj73Pz+LO4oblsZLrP5UDjae7X9ajKWobRUxGADIGligITIPKcfvAQz9K9ygI qK5W41HeW9CF0smBfA60bIRhflnyeIqys6j0XAA/IyKFz/OaZptPyElYKD6rsrOp6sW8 qluQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eBoiAf+fwwTWl+wiFp1yO3mt7hvFDEp3X8YtzX7kZP0=; b=NvASMvTgaHOsdG0pH3YOT599J0N0bBSJnV3RmQbOKE8oxQxV0NtmMJFCEfJ4mWcIv/ tpH1NKs+SJkvNn8Ja4/QxOgUYVX76Ttgc07HgwrucAQeCLs3KNMpz/uShBml7FTcm4uc XTDlO1VHGi75T9xOl56J0tUhSQTKAvFBGYLdhcHNTHIG0MrfiIfgcnTNzAuAj8U49z+M 0QZ1F1AghhYmBX5d++CXqUJGWDUD2ABMoKsprFdtbJf9buvLguQ2WLhYuhWaPD4c2OB0 uKukkn6JbMXST6XBHPa/iN2J11tftkkurDJU1CedE7Wh60OhxPtU7s4OWy7ptpUja2j6 2Arg== X-Gm-Message-State: AOUpUlGup4dW9QyufSS/bV+3FLzyFyS4CC5lMJmNqk3Uw/D24hGZlOlA wpE0hP1LzGBRBZao4hcukHQzDdxF1AVycL7ePRBIfg== X-Received: by 2002:a1c:9a15:: with SMTP id c21-v6mr4990459wme.112.1532017401874; Thu, 19 Jul 2018 09:23:21 -0700 (PDT) MIME-Version: 1.0 References: <1531994807-25639-1-git-send-email-jing.xia@unisoc.com> <20180719104345.GV7193@dhcp22.suse.cz> In-Reply-To: <20180719104345.GV7193@dhcp22.suse.cz> From: Shakeel Butt Date: Thu, 19 Jul 2018 09:23:10 -0700 Message-ID: Subject: Re: [PATCH] mm: memcg: fix use after free in mem_cgroup_iter() To: Michal Hocko Cc: jing.xia.mail@gmail.com, Johannes Weiner , Vladimir Davydov , chunyan.zhang@unisoc.com, Cgroups , Linux MM , LKML , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 19, 2018 at 3:43 AM Michal Hocko wrote: > > [CC Andrew] > > On Thu 19-07-18 18:06:47, Jing Xia wrote: > > 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. > > Well, spotted! > > I suspect > Fixes: 6df38689e0e9 ("mm: memcontrol: fix possible memcg leak due to interrupted reclaim") > > but maybe it goes further into past. I also suggest > Cc: stable > > even though the non-hierarchical mode is strongly discouraged. Why not set root_mem_cgroup's use_hierarchy to true by default on init? If someone wants non-hierarchical mode, they can explicitly set it to false. > A lack of > reports for 3 years is encouraging that not many people really use this > mode. > > > Signed-off-by: Jing Xia > > Acked-by: Michal Hocko > > Thanks! > > --- > > 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 > > -- > Michal Hocko > SUSE Labs > -- > To unsubscribe from this list: send the line "unsubscribe cgroups" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html