Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1544540imm; Thu, 19 Jul 2018 03:45:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcRawOIw1l+hpDBnkHvIPGlmRFyDj0yxwHiYqZzhszfOpDSPw21x6VRpBzxT/2GJwBphT2H X-Received: by 2002:a63:bd51:: with SMTP id d17-v6mr9780309pgp.42.1531997116238; Thu, 19 Jul 2018 03:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531997116; cv=none; d=google.com; s=arc-20160816; b=EjLKIzt1SsXKVNBqvWMxD2n22pALsXHAjJv5qArmn2bDFJWp9631PEGUYIturiYNny YErCTcAgxcPfNHd91BbEdbSbwi875IKWiSIuuZ8nJ3By9nTbeRgQak/Ec5Lj3ALHb/ie 8/1qY38zEs7CKo0z2pywO3RiMq2nrrDucodoj1P3/NstsdHktAG1T2+zlDbHCxfJtXMM S6a6O/4ujvIBJ4Xc1wWafBmZwGc/2sVzJtbDR0GUib+7V/UgmzP/gz7aHWr13uPYo1cK 5VYrThtEUcD23Td6gC81rzaTyL4ALlcrbvwEJSXAYPdRo7+gKMpnfLgRk05v0HLTEf5L txYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=lE9z3p/6Q7JyLVTS4qEj1znQW0UHfPetn1KxbtX/Jns=; b=fpmh+o6akzv5gxQnntkddVTuDAfO4dQGWxupeyNAUKbPDgyeYM7J56mEp7AsN6inLC 7wv1KLPvasUTalGV3bcZd4uO6iiZ1x/yWDvWZhjrlpBalbLS0Vyy0akFkf2p9JjttBWO x9hVUDnW8hBYfx2ul4sZM4macb0AQJ9ig2VQJekfefaGs3bBtj6XhXLhbPH/eGWeNhgj NAxtOcCwrXQpwrsQsq10BmimbJGvlci+RJFD6reRM/13Ps43HF4aadAFRjnF+2GRRIGD 6yhjYhBELZYHiPpYvJfFoVSPwSJ2EcDwj0i91hsJGTVkx3kZ6bQ0FOYLbwsecw0+Wjk2 Rv9w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1-v6si6210467plm.375.2018.07.19.03.45.01; Thu, 19 Jul 2018 03:45:16 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730521AbeGSL0W (ORCPT + 99 others); Thu, 19 Jul 2018 07:26:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:52162 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727285AbeGSL0W (ORCPT ); Thu, 19 Jul 2018 07:26:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B8193ADBE; Thu, 19 Jul 2018 10:43:47 +0000 (UTC) Date: Thu, 19 Jul 2018 12:43:45 +0200 From: Michal Hocko To: Jing Xia Cc: hannes@cmpxchg.org, vdavydov.dev@gmail.com, chunyan.zhang@unisoc.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Subject: Re: [PATCH] mm: memcg: fix use after free in mem_cgroup_iter() Message-ID: <20180719104345.GV7193@dhcp22.suse.cz> References: <1531994807-25639-1-git-send-email-jing.xia@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1531994807-25639-1-git-send-email-jing.xia@unisoc.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [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. 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