From patchwork Tue Apr 26 08:25:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiabing Wan X-Patchwork-Id: 12826634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C872C4332F for ; Tue, 26 Apr 2022 08:26:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 791986B0073; Tue, 26 Apr 2022 04:26:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 741266B0074; Tue, 26 Apr 2022 04:26:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BA1E6B0075; Tue, 26 Apr 2022 04:26:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 4D20B6B0073 for ; Tue, 26 Apr 2022 04:26:16 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 1CA7B80AEA for ; Tue, 26 Apr 2022 08:26:16 +0000 (UTC) X-FDA: 79398347952.19.4EE5EA0 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2126.outbound.protection.outlook.com [40.107.215.126]) by imf01.hostedemail.com (Postfix) with ESMTP id E335440040 for ; Tue, 26 Apr 2022 08:26:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bcFJhbzWsoI6F+6NYxYYNJv0+/w6Hdms+3mppbUVdJFLp/uTUjEh8AdQBx1LYX5JbX3151MhATMX0lhT1byVtb824Zvb0Lgb770xs7CrvQBWIb9KmD48S1TE1iO+deK3uViJrIItvTLGFrekO13I1BJVrXyLT8FFd37gVVH7daVFC0Llpq+uLbwQpWoxUKNzVeDeZ73nq74fE9FWkXLRfN3+i/QQRm0nLUZ6MKmrnTV3zgUTTvMNupYT2LrubiVbiaca371wRZC2m3xUv1VRWq+bxkwBVxBa1qtYgDbiOvUUFTB4pgs5QP5OPFP5tnTyZ3ZjRedNMfAo7kP1eKB9jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lFqXuY219pQYqdcnExefYu3BoAMa/pMzNdZVT5eZxrU=; b=ms3U5QcZXLpPYFYJqdqknkeqBqvOx96fiDNcbbKMCNCvQeDsNpc6ZPcfULyNxJxCK3bD+cOtKiOtlQjmo9hzK1hyajNGhJTZCU/dl+yjLPYv9+G2xMgPXLHG8p3qXAgD1LBxxSGtFLBnVgCifEJFnIhkSvm3vIjWV/8DGi5CKTgx53hYjrDJJALkLk8RddV6BCpRfkHR3LB8xOPc4myweqSZfaRnGEHzyFB500TU2/AS6PUA5eCXxyg0b8bZcUtsk5TDiGDYQncEwF1udKIxThKoNe61e7+UiXtWebvh7lcyd7PBln8JNHwt0/oWrvqkhIdv0vtgM5IA5Hx9B3gHcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo0.onmicrosoft.com; s=selector2-vivo0-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lFqXuY219pQYqdcnExefYu3BoAMa/pMzNdZVT5eZxrU=; b=dW5Ot29LSIcdKdhAXEcdH+fFPs1yPCloAQNiE4H/62cfhKq4bNB62Gj5l0WOBhZXUO/8CYde4xC2/WC/g/eokSGzFLJ3p/d4ClRZ/cWCehzA8Cki52nfjsSys1CRJ+AblWR8wbuWMfBCi4VgJWEMfORYsv2CxWWTdUygJ3nbZDk= Received: from SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) by TYZPR06MB3952.apcprd06.prod.outlook.com (2603:1096:400:6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Tue, 26 Apr 2022 08:26:10 +0000 Received: from SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c]) by SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c%7]) with mapi id 15.20.5186.021; Tue, 26 Apr 2022 08:26:09 +0000 From: Wan Jiabing To: Andrew Morton , "Matthew Wilcox (Oracle)" , Vlastimil Babka , David Howells , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Wan Jiabing Subject: [PATCH] mm/filemap: Fix NULL pointer dereference in pagecache_get_page Date: Tue, 26 Apr 2022 16:25:48 +0800 Message-Id: <20220426082549.590899-1-wanjiabing@vivo.com> X-Mailer: git-send-email 2.35.3 X-ClientProxiedBy: HK0PR01CA0069.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::33) To SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdec9c02-e6d4-4b3a-8996-08da275e6a72 X-MS-TrafficTypeDiagnostic: TYZPR06MB3952:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lmTCgQR1BPJktKI97vqL1Hx0FTWJT+5zsCWd7Yi+7g6nloknufiy0nSPUYiK2/5fM+l3EMDjG0HmpbojTj04f4X0PxP13laXvWOkRsmKXKQzuHQREiCNWbIkBwVGJ5ZZbnMHI6XgNy+Yaj1pCu4imOJd85Cn79SL26GIrnANPitjHY9EmHSleoterG18RI4WHZzh6LDOsuWYJ/sM09c0uQV/uPthD87iFzSGXnujOBqAdTpMj4g3m+ugNIWbRtnJQfD80MplMQ728cq1pmEVkF9k8pYtad7POfBkyde6ltEKfgw41Hq89GrEQ52hW7x02YkXNt5W5ovs9jTxavBjS7wofsm8s/uDYIET05D0HaVDBOZm3QbUCv7H5PtEkF2QKWk9VUuIjDadPV5bA/KrCU+fqoacQp+1eDI93YN20d4YE6YXP9vS4EBJD9n7WLNy/zy28pgXlN9TPtof3xZEJ9qYxJYDvv+9PtbfRTbdWvfEYs+r2kFssYJHwc4fhROxiLLD7j/e2uaclXrYkEc/oPujjEdt12P6M53jkY8Tb/Bu85ccNH9UDqW6JvlLcXjPxWJpPL2OMAcNkCmFRmGYsA187Gzrn4DOnXx2zSjuYdYPdymLXq5NggQlZO4hS4+uCQOkAPSyKIGtxSnq+TpHnZP2RjXhnDLbPfYi5fRRXiNHq1O9suDN9Wk9wCfZBo9GXycBeOFiA1zFcIgdPa5EBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3367.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(52116002)(6666004)(66476007)(66556008)(66946007)(4326008)(8676002)(4744005)(38350700002)(38100700002)(8936002)(6486002)(6512007)(6506007)(508600001)(86362001)(186003)(26005)(83380400001)(36756003)(5660300002)(2906002)(107886003)(316002)(110136005)(2616005)(1076003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fk73PeyQcVh5/TrjXIOCRrIa7x0uSShtF4cxddDyzc9aKxtWVP2z6nH1UxgDWWwKr74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Qo9M/JOSobIBWdZIy6kEeSBTjrpA+gwis+M6uJBt+btpByV4fTFFmem12OCaTGeT5NulvBh5eLk+WDxFz7tM+raHp2iur687dEX3Djxxive2RYBfeF8GVKbNBDouv4wZK0LWLJlGLYmfyOyQMzanzU0Ga3NB5UnbreevlWS/plEJNTyyLPDPtx0YSE4tFzMRXkRm/oqvNhbd/FuG37X1ScDp1k+8i+BSB/SExuqUX/8NXtzWSX/YLTtFHkrzZ3jPhgs8zYT75ielE48Lt/eeqxxt5ycahpSsS6FrLIa3iixc3QQFuRaL5l0xSr1UGjjv5fLWR3AhFlpTxlG9GUhoZglIOtCRr7W4EwC9CNAWe9b0CM6vgbVgIb8DiN0Z5ZiT96IRowXl1kNzDMntYqmn/xFnSzMRKb4X9Pf/sx3DG1XdQOmrZgGZWbkfA7b5vBZLDGq/u+IJgBt2SBAFc2a5uBg+MZ39yuN3gB8L+lYC9LJwh1AmdWCVeilhnVMTpXG7a+2pvWZV8nw/dxIQmyfprL3PziTwL4W45SKnHylu/Yd3V37z6FL+P1O6U2jZ1VW8SafsJqhZhRDgVyxkQZE6Lpjg== X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdec9c02-e6d4-4b3a-8996-08da275e6a72 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3367.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2022 08:26:09.5615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /25ix0cXy5j2yhGsjdwyfW0ECH/BVw8g9IrdXtlmvm4sFy2N81B5jNnNvU8lG1fW8dtPl5PGsVwxN13ee3YNLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3952 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E335440040 X-Stat-Signature: snupzuuqcjrwjy5486maugo9u1c1f1un X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=vivo0.onmicrosoft.com header.s=selector2-vivo0-onmicrosoft-com header.b=dW5Ot29L; spf=pass (imf01.hostedemail.com: domain of wanjiabing@vivo.com designates 40.107.215.126 as permitted sender) smtp.mailfrom=wanjiabing@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com X-HE-Tag: 1650961570-239184 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fix following coccicheck error: mm/folio-compat.c:128:17-21: ERROR: folio is NULL but dereferenced. 'folio' would be NULL when getting a reference to a folio failed. Add a NULL check before dereferring 'folio'. Fixes: 3f0c6a07fee6 ("mm/filemap: Add filemap_get_folio") Signed-off-by: Wan Jiabing --- mm/folio-compat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 46fa179e32fb..54b17c1246c4 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -124,7 +124,9 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, struct folio *folio; folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio)) + if (!folio) + return NULL; + if ((fgp_flags & FGP_HEAD) || xa_is_value(folio)) return &folio->page; return folio_file_page(folio, index); }