Received: by 10.213.65.68 with SMTP id h4csp3602419imn; Tue, 10 Apr 2018 01:25:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/9pLXC4JgG9fJUv98aVUBY5MAKQLqScnkTgJoIXcl/Q2iGSN41rl9rwylbqDFQPsXQKYL X-Received: by 10.101.67.6 with SMTP id j6mr1237768pgq.126.1523348754168; Tue, 10 Apr 2018 01:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523348754; cv=none; d=google.com; s=arc-20160816; b=V/0KHj73pzkK/yDEtDaijVdBcE/kwJM06xrbNyjyYLa/ZLH0zvYNfN8klNF8NEdEYv M3DJnzQRz060M5GkZNcImFYWYGwN6v74wXnYa3waFZNGpyoySlUPOAXDu+UYwH3d4fbq aQkAjuRjtRULPDIpFQXgNwydywvGoEbyQ9L6ckipTDzK1JiGyVsV8zr4SRXshbcjecwA IaSpA2sRHmqFMQvBXDllvxoZk2Pe5pa/+DxBbe8OAnpCuJsr5C5IUn1DQkeiPKKvCzgo VFfc6I6C/IPjx3jA1pF+Z21Aiu7zZ4tl+7+6yIOxu6Ex+H7L4K1zy+kqwDVZr9T+Zwrh 8HZw== 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=9pu+zTXcudz3sqdGkUko3+y/4Vjy9AtssmQjcCfSZj8=; b=0X5lFFEcPS2u7S2yIKbbh1IaixpHkg6xy1CNLZfw18t3iDfqOx0b2kECBIcjXvnewP KZ3KbV8v7JTkjDJHhC42NNxtTfBupkBBFrNbuJPLMPWKPLt4c0VN9M3Eb0s8Yt3LBV7s goFfc2GozhR5+e4jrH/IrVwvHCOBcuM/nVgVKrY5Fb/KLVbGGY2gQwEh+6RzS59SIFz/ /1WhcAWh61FyRFmJVwEEXfuHCq7iHFjX8vbByf/ZGvDh6ipr13mw0lZvYJMS6OoAjdru /otyXziJwGmnKNXh4G9DwLk536SdDg3usMt2rxsXvdajpbnFnMbcEOjClrY4mfnfzf2b V6/A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si2128262pla.133.2018.04.10.01.25.17; Tue, 10 Apr 2018 01:25:54 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752529AbeDJIWq (ORCPT + 99 others); Tue, 10 Apr 2018 04:22:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:43133 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752448AbeDJIWp (ORCPT ); Tue, 10 Apr 2018 04:22:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BAE9DAD0B; Tue, 10 Apr 2018 08:22:43 +0000 (UTC) Date: Tue, 10 Apr 2018 10:22:43 +0200 From: Michal Hocko To: Minchan Kim Cc: Andrew Morton , linux-mm , LKML , Johannes Weiner , Jan Kara , Chris Fries Subject: Re: [PATCH] mm: workingset: fix NULL ptr dereference Message-ID: <20180410082243.GW21835@dhcp22.suse.cz> References: <20180409015815.235943-1-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180409015815.235943-1-minchan@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 09-04-18 10:58:15, Minchan Kim wrote: > Recently, I got a report like below. > > [ 7858.792946] [] __list_del_entry+0x30/0xd0 > [ 7858.792951] [] list_lru_del+0xac/0x1ac > [ 7858.792957] [] page_cache_tree_insert+0xd8/0x110 > [ 7858.792962] [] __add_to_page_cache_locked+0xf8/0x4e0 > [ 7858.792967] [] add_to_page_cache_lru+0x50/0x1ac > [ 7858.792972] [] pagecache_get_page+0x468/0x57c > [ 7858.792979] [] __get_node_page+0x84/0x764 > [ 7858.792986] [] f2fs_iget+0x264/0xdc8 > [ 7858.792991] [] f2fs_lookup+0x3b4/0x660 > [ 7858.792998] [] lookup_slow+0x1e4/0x348 > [ 7858.793003] [] walk_component+0x21c/0x320 > [ 7858.793008] [] path_lookupat+0x90/0x1bc > [ 7858.793013] [] filename_lookup+0x8c/0x1a0 > [ 7858.793018] [] vfs_fstatat+0x84/0x10c > [ 7858.793023] [] SyS_newfstatat+0x28/0x64 > > v4.9 kenrel already has the d3798ae8c6f3,("mm: filemap: don't > plant shadow entries without radix tree node") so I thought > it should be okay. When I was googling, I found others report > such problem and I think current kernel still has the problem. > > https://bugzilla.redhat.com/show_bug.cgi?id=1431567 > https://bugzilla.redhat.com/show_bug.cgi?id=1420335 > > It assumes shadow entry of radix tree relies on the init state > that node->private_list allocated should be list_empty state. > Currently, it's initailized in SLAB constructor which means > node of radix tree would be initialized only when *slub allocates > new page*, not *new object*. So, if some FS or subsystem pass > gfp_mask to __GFP_ZERO, slub allocator will do memset blindly. > That means allocated node can have !list_empty(node->private_list). > It ends up calling NULL deference at workingset_update_node by > failing list_empty check. > > This patch should fix it. > > Fixes: 449dd6984d0e ("mm: keep page cache radix tree nodes in check") > Reported-by: Chris Fries > Cc: Johannes Weiner > Cc: Jan Kara > Signed-off-by: Minchan Kim Regardless of whether it makes sense to use __GFP_ZERO from the upper layer or not, it is subtle as hell to rely on the pre-existing state for a newly allocated object. So yes this makes perfect sense. Do we want CC: stable? Acked-by: Michal Hocko > --- > If it is reviewed and proved with testing, I will resend the patch to > Ccing stable@vger.kernel.org. > > Thanks. > > lib/radix-tree.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/radix-tree.c b/lib/radix-tree.c > index 8e00138d593f..afcbdb6c495f 100644 > --- a/lib/radix-tree.c > +++ b/lib/radix-tree.c > @@ -428,6 +428,7 @@ radix_tree_node_alloc(gfp_t gfp_mask, struct radix_tree_node *parent, > ret->exceptional = exceptional; > ret->parent = parent; > ret->root = root; > + INIT_LIST_HEAD(&ret->private_list); > } > return ret; > } > @@ -2234,7 +2235,6 @@ radix_tree_node_ctor(void *arg) > struct radix_tree_node *node = arg; > > memset(node, 0, sizeof(*node)); > - INIT_LIST_HEAD(&node->private_list); > } > > static __init unsigned long __maxindex(unsigned int height) > -- > 2.17.0.484.g0c8726318c-goog -- Michal Hocko SUSE Labs