Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5478966imm; Sun, 22 Jul 2018 23:45:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJgk0+LLNpSt+5Y+S4f+sLL5tFuZVk0V0GbR0WFq8h2wZ5ZXU49ah0mENC+00g+m68BZv6 X-Received: by 2002:a62:ec41:: with SMTP id k62-v6mr11925421pfh.206.1532328348453; Sun, 22 Jul 2018 23:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532328348; cv=none; d=google.com; s=arc-20160816; b=LF8vtFfRl1sVi3nNrYD+Ga5NF6mhVUz/FxSQdlwtO5w2W45q/PFx7zBTAObss3HFdV WZQ2webCtMtTSyjNpTvk0g0SchHI9KaYZ0/Z/CcVqwmc0o4C/h04o1DjLaCVSsQcZDLQ lCcDJCxYLF284NQ33FTxK0V5pz20UMm8MG1CIO7XOxOBgK93et3L4XhLa3RlJYUcHnCW 8Kz2TckMvmDj+q04xhWX0Y0z6SXhuowWyraxTKDK1xKwdlHuhnTIAaL4DI6AOW8c4UUv 5hks8nZ8JxvqJxh0Y1o/hwJ4FHeJ+Gkx76RqenDgYALjOF+cnHofD8KCLUo8UjDQDH8I EccQ== 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=L9luaqFH+hETudVSb0Xf6wl/vTiEndGecJ249Jv9Sxg=; b=ZjwBD7Wv7Ftt7swn2T+msgFYtmOAaTofWl7u8cxheIsXbApvxWduenBYqTJrF9G3Hv /rRSX6e8HTUVzjYnjDHHygyrn5ZDIcbDLLBIOHJXb+pk0Toi46ahVzkW3ja7V/D+gy/A pv4ltKojC5AYnzhbzPew57iO9eRGUyQWUtbNuHmINqQxYdD+/0lfCRNzXqndthgplqgJ mTUWY6ZD+oDqRVp5tfDyU/lrFsdQZLoQFRFA3O3cZ1inrl/XTzbQqW4mnVnFMEVsqh/0 bQOxGpYn/FdX6qqmHCdvW5TIBrN+sadxGGesMUQdrOIZUUuD6QbdjG3WLTUuwR0gxFYH 4auQ== 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 y6-v6si7524474pgk.474.2018.07.22.23.45.33; Sun, 22 Jul 2018 23:45:48 -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 S2387962AbeGWHoZ (ORCPT + 99 others); Mon, 23 Jul 2018 03:44:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:36340 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387892AbeGWHoZ (ORCPT ); Mon, 23 Jul 2018 03:44:25 -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 0AF41AE6B; Mon, 23 Jul 2018 06:44:43 +0000 (UTC) Date: Mon, 23 Jul 2018 08:44:41 +0200 From: Michal Hocko To: Shakeel Butt Cc: jing.xia.mail@gmail.com, Johannes Weiner , Vladimir Davydov , chunyan.zhang@unisoc.com, Cgroups , Linux MM , LKML , Andrew Morton Subject: Re: [PATCH] mm: memcg: fix use after free in mem_cgroup_iter() Message-ID: <20180723064441.GA17905@dhcp22.suse.cz> References: <1531994807-25639-1-git-send-email-jing.xia@unisoc.com> <20180719104345.GV7193@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Thu 19-07-18 09:23:10, Shakeel Butt wrote: > 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. We do not change defaults under users feet usually. -- Michal Hocko SUSE Labs