Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3740382imm; Mon, 11 Jun 2018 00:35:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLZQJa0PvEahOqGtGQE7TjLtnmGJ7N46egY135lH7At4Asnx9RV4TmbZY00bmV3632c97GY X-Received: by 2002:a17:902:1127:: with SMTP id d36-v6mr6561907pla.267.1528702540494; Mon, 11 Jun 2018 00:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528702540; cv=none; d=google.com; s=arc-20160816; b=EWgAUoyWqW3VpBb4FL3OYkcwICqQTzMoapcRdt6zV4VMg7jUe9dwlp1CkfAv9gTwVf N655vfnHEv3w/zzX8V6nzWRQI9pcmXpp4YkYD5C+5Jnftihbm6V0IqKt7bYctY0Xkwf+ XphJ4eH6PsAdWu7qwUUATd2Ovw/pMegZQbEtRxjy36rSXxlWoaghkn6uMiqn+6xvKfi4 E0bycZl+S0j/ODUUXktjmIe/hde5embRqyo3+eT5wZTBvESJA+m5iT61gJXhMfWD9jp+ JXUvF+P1oDEjEqaRcH/T7YV/lZ6asybWW+wsRyXvYsKt8SatlGKxETX9/t69maXj2TK6 UQoQ== 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=y9CfaCLG0CkEEDDBGssxnVg4nxkuJ5Rpw2k/PvfcpyA=; b=sw8H959iw+zZ/EPQ7nOfcmjGeyUmIHnILwD1WxG448y1IQdi8ghYY34BkPAnfpv/Lg L6khziTWQwN/JRzMbceiW1zLg3Of670q0r53epwsusl23SoRxDtWVoBpXJdgtkHaiRpa j/Ir1Yrbkih1jwzkokdOoqZo4LA4pzFnGekKcRGzBF0F1eyeiez3ORYe2U3ctlikBo5d GM3RF9w2qqj5ds/FBIAXEBvIqHes2YtYLco2SRxeP1N/wrTWL/8D7zBn/6YlewAjTdbI FIWGarJGuvWpaSJhjC15zKpXexiSGH/0IkLyfpCUfKMsLlcm8qq0kxP29RhXuzhQIf4Q tMmQ== 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 cf13-v6si696557plb.175.2018.06.11.00.35.26; Mon, 11 Jun 2018 00:35:40 -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 S932328AbeFKHfB (ORCPT + 99 others); Mon, 11 Jun 2018 03:35:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:37497 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932230AbeFKHfA (ORCPT ); Mon, 11 Jun 2018 03:35:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 20326AD0B; Mon, 11 Jun 2018 07:34:59 +0000 (UTC) Date: Mon, 11 Jun 2018 09:34:58 +0200 From: Michal Hocko To: Roman Gushchin Cc: Andrew Morton , Shakeel Butt , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org, Johannes Weiner Subject: Re: [PATCH] mm: fix null pointer dereference in mem_cgroup_protected Message-ID: <20180611073458.GD13364@dhcp22.suse.cz> References: <20180608170607.29120-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180608170607.29120-1-guro@fb.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 08-06-18 18:06:07, Roman Gushchin wrote: > Shakeel reported a crash in mem_cgroup_protected(), which > can be triggered by memcg reclaim if the legacy cgroup v1 > use_hierarchy=0 mode is used: > > [ 226.060572] BUG: unable to handle kernel NULL pointer dereference > at 0000000000000120 > [ 226.068310] PGD 8000001ff55da067 P4D 8000001ff55da067 PUD 1fdc7df067 PMD 0 > [ 226.075191] Oops: 0000 [#4] SMP PTI > [ 226.078637] CPU: 0 PID: 15581 Comm: bash Tainted: G D > 4.17.0-smp-clean #5 > [ 226.086635] Hardware name: ... > [ 226.094546] RIP: 0010:mem_cgroup_protected+0x54/0x130 > [ 226.099533] Code: 4c 8b 8e 00 01 00 00 4c 8b 86 08 01 00 00 48 8d > 8a 08 ff ff ff 48 85 d2 ba 00 00 00 00 48 0f 44 ca 48 39 c8 0f 84 cf > 00 00 00 <48> 8b 81 20 01 00 00 4d 89 ca 4c 39 c8 4c 0f 46 d0 4d 85 d2 > 74 05 > [ 226.118194] RSP: 0000:ffffabe64dfafa58 EFLAGS: 00010286 > [ 226.123358] RAX: ffff9fb6ff03d000 RBX: ffff9fb6f5b1b000 RCX: 0000000000000000 > [ 226.130406] RDX: 0000000000000000 RSI: ffff9fb6f5b1b000 RDI: ffff9fb6f5b1b000 > [ 226.137454] RBP: ffffabe64dfafb08 R08: 0000000000000000 R09: 0000000000000000 > [ 226.144503] R10: 0000000000000000 R11: 000000000000c800 R12: ffffabe64dfafb88 > [ 226.151551] R13: ffff9fb6f5b1b000 R14: ffffabe64dfafb88 R15: ffff9fb77fffe000 > [ 226.158602] FS: 00007fed1f8ac700(0000) GS:ffff9fb6ff400000(0000) > knlGS:0000000000000000 > [ 226.166594] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 226.172270] CR2: 0000000000000120 CR3: 0000001fdcf86003 CR4: 00000000001606f0 > [ 226.179317] Call Trace: > [ 226.181732] ? shrink_node+0x194/0x510 > [ 226.185435] do_try_to_free_pages+0xfd/0x390 > [ 226.189653] try_to_free_mem_cgroup_pages+0x123/0x210 > [ 226.194643] try_charge+0x19e/0x700 > [ 226.198088] mem_cgroup_try_charge+0x10b/0x1a0 > [ 226.202478] wp_page_copy+0x134/0x5b0 > [ 226.206094] do_wp_page+0x90/0x460 > [ 226.209453] __handle_mm_fault+0x8e3/0xf30 > [ 226.213498] handle_mm_fault+0xfe/0x220 > [ 226.217285] __do_page_fault+0x262/0x500 > [ 226.221158] do_page_fault+0x28/0xd0 > [ 226.224689] ? page_fault+0x8/0x30 > [ 226.228048] page_fault+0x1e/0x30 > [ 226.231323] RIP: 0033:0x485b72 > > The problem happens because parent_mem_cgroup() returns a NULL > pointer, which is dereferenced later without a check. > > As cgroup v1 has no memory guarantee support, let's make > mem_cgroup_protected() immediately return MEMCG_PROT_NONE, > if the given cgroup has no parent (non-hierarchical mode is used). > Fixes: bf8d5d52ffe8 ("memcg: introduce memory.min") I guess. > Reported-by: Shakeel Butt > Signed-off-by: Roman Gushchin > Cc: Johannes Weiner > Cc: Michal Hocko > Cc: Andrew Morton Acked-by: Michal Hocko I really do not see why the whole min limit thing had to be rushed into mainline. It has clearly not been tested for all configurations. Sigh... > --- > mm/memcontrol.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 6c9fb4e47be3..6205ba512928 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5750,6 +5750,9 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > elow = memcg->memory.low; > > parent = parent_mem_cgroup(memcg); > + if (!parent) > + return MEMCG_PROT_NONE; > + This deserves a comment. /* No parent means a non-hierarchical mode on v1 memcg */ > if (parent == root_mem_cgroup) > goto exit; > > -- > 2.14.3 -- Michal Hocko SUSE Labs