Received: by 10.192.165.156 with SMTP id m28csp335326imm; Tue, 10 Apr 2018 23:06:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+1RMBSeeNHjzJIrnoargTj6nKcUc9K9lb8GA5sjZBNutZmsVUro0mCHExjFVM2WPMu2Su X-Received: by 10.99.116.81 with SMTP id e17mr2469666pgn.437.1523426815181; Tue, 10 Apr 2018 23:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523426815; cv=none; d=google.com; s=arc-20160816; b=0JaKc5qHhKBx/UksYRXV1gOYuiOUCt0uaS2oHNPLyrcon2HZYnJDGhibADfivl/uUu dM2X2Y65KD3yFnthuu8xz7DjdxqPXH29u7iJacoNr43lKl1CTeK7MtCRsHqWOePTcXkW KEVHTZExWWXVaxWHC90lotdxoHuM0Z92BWo5MHF/BQh1utV9Au+W/ZO9Twt79xIssvrZ 2AdVRiHHjIDtQBotSAOy6iUHzg4y99jH+7+1bCS30RMGuyBjhZtW1xs9C9f+LqhMAqKv yHhKUuhzhIZI2q8GR/1VS+ItsLsHhodGZGZmA/zSlZuXEyLBjMuvGbpuv4ZuiCmqPwdu 9rnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Z8T8aforecbTBSlIDPMF5a/yuPPmDJaZvWuH3Q0VUk8=; b=yRS01GLWR9EtOnQXECLSx7kUlgcrzO2bBLhuj2mttHJYYe5ukIP4qLltX2KbOFQ3sp NTTiFXQ1zgijqUETJAZw7tWRHSafZbzsl0VRvYWE7+rB74rNRrTiHOg4yJp8OkVd8RmF 2gn3oYcpzofafkOqmYLjbVGE3RPLWySL/lGf3yocbIGzpZr3XdSgrTEzmAXzsHkjLky/ /GikUOmN+8tclgSlo1qAFX4jrd5AVGEI+xvsWbDpVXP1q0S6jGR8Am3TSr/3Akhk3QB6 VDaP7MSNF06Uw+FdylDJfJvxKR/Y2WTo3a7hma5UpBEhs2JbWdy014CgD3K02yh2Y7nh KbTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gV56E2bC; 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 i128si331714pfg.343.2018.04.10.23.06.18; Tue, 10 Apr 2018 23:06:55 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gV56E2bC; 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 S1752182AbeDKGDe (ORCPT + 99 others); Wed, 11 Apr 2018 02:03:34 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:47300 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751491AbeDKGD3 (ORCPT ); Wed, 11 Apr 2018 02:03:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z8T8aforecbTBSlIDPMF5a/yuPPmDJaZvWuH3Q0VUk8=; b=gV56E2bCPnWUfxc7I2EaAJonb rhz3syW0Uvz2ZizaFBRsNeSDpGnEbqUSDITgB79RM7CsdmWMRBUqgowODalLis49SbMQf8TZHFMQy c3DK2pmv8H/DLGrAO5TCai+pQJ4UAEx+hRIQ5r/IRanZ/0E5QqWwolsKJ2SQDpkz5mUo1S3yqm1Hw gEGvvGjaG7ZoPjVaAbZoiWI6I3TJrNBuGBwWU2Y9PKcGZzqTAwUEjCP8riUQHLrMK/TzKz3L0wgkp V+w9MMBoJ9riCv5rmAX03lnIMv80U1SFVPUgkq9wLGSapXSQSsWgJZK2Sx2DA5IVQticIWFwNcMG1 AQogibXHA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f68qp-0003m8-Hk; Wed, 11 Apr 2018 06:03:23 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Matthew Wilcox , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-kernel@vger.kernel.org, Jan Kara , Jeff Layton , Mel Gorman , stable@vger.kernel.org Subject: [PATCH v2 1/2] Fix NULL pointer in page_cache_tree_insert Date: Tue, 10 Apr 2018 23:03:19 -0700 Message-Id: <20180411060320.14458-2-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411060320.14458-1-willy@infradead.org> References: <20180411060320.14458-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox f2fs specifies the __GFP_ZERO flag for allocating some of its pages. Unfortunately, the page cache also uses the mapping's GFP flags for allocating radix tree nodes. It always masked off the __GFP_HIGHMEM flag, and masks off __GFP_ZERO in some paths, but not all. That causes radix tree nodes to be allocated with a NULL list_head, which causes backtraces like: [] __list_del_entry+0x30/0xd0 [] list_lru_del+0xac/0x1ac [] page_cache_tree_insert+0xd8/0x110 The __GFP_DMA and __GFP_DMA32 flags would also be able to sneak through if they are ever used. Fix them all by using GFP_RECLAIM_MASK at the innermost location, and remove it from earlier in the callchain. Fixes: 449dd6984d0e ("mm: keep page cache radix tree nodes in check") Reported-by: Chris Fries Debugged-by: Minchan Kim Signed-off-by: Matthew Wilcox Acked-by: Johannes Weiner Acked-by: Michal Hocko Reviewed-by: Jan Kara Cc: stable@vger.kernel.org --- mm/filemap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index c2147682f4c3..1a4bfc5ed3dc 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -785,7 +785,7 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask) VM_BUG_ON_PAGE(!PageLocked(new), new); VM_BUG_ON_PAGE(new->mapping, new); - error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); + error = radix_tree_preload(gfp_mask & GFP_RECLAIM_MASK); if (!error) { struct address_space *mapping = old->mapping; void (*freepage)(struct page *); @@ -841,7 +841,7 @@ static int __add_to_page_cache_locked(struct page *page, return error; } - error = radix_tree_maybe_preload(gfp_mask & ~__GFP_HIGHMEM); + error = radix_tree_maybe_preload(gfp_mask & GFP_RECLAIM_MASK); if (error) { if (!huge) mem_cgroup_cancel_charge(page, memcg, false); @@ -1574,8 +1574,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, if (fgp_flags & FGP_ACCESSED) __SetPageReferenced(page); - err = add_to_page_cache_lru(page, mapping, offset, - gfp_mask & GFP_RECLAIM_MASK); + err = add_to_page_cache_lru(page, mapping, offset, gfp_mask); if (unlikely(err)) { put_page(page); page = NULL; @@ -2378,7 +2377,7 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) if (!page) return -ENOMEM; - ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask & GFP_KERNEL); + ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask); if (ret == 0) ret = mapping->a_ops->readpage(file, page); else if (ret == -EEXIST) -- 2.16.3