From patchwork Tue Jul 24 13:40:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10542181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38AD914BC for ; Tue, 24 Jul 2018 13:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 253EE288DA for ; Tue, 24 Jul 2018 13:40:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 238142891B; Tue, 24 Jul 2018 13:40:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6497288DA for ; Tue, 24 Jul 2018 13:40:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 58D67210C1B68; Tue, 24 Jul 2018 06:40:11 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Permerror (SPF Permanent Error: Two or more type TXT spf records found.) identity=mailfrom; client-ip=192.185.51.228; helo=gateway24.websitewelcome.com; envelope-from=gustavo@embeddedor.com; receiver=linux-nvdimm@lists.01.org Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.51.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 04FC6210C1251 for ; Tue, 24 Jul 2018 06:40:09 -0700 (PDT) Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway24.websitewelcome.com (Postfix) with ESMTP id A89369F615B for ; Tue, 24 Jul 2018 08:40:07 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id hxXrf8vG879N3hxXrfU6lB; Tue, 24 Jul 2018 08:40:07 -0500 X-Authority-Reason: nr=8 Received: from [189.250.70.148] (port=46678 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fhxXq-001Ac5-T8; Tue, 24 Jul 2018 08:40:06 -0500 Date: Tue, 24 Jul 2018 08:40:06 -0500 From: "Gustavo A. R. Silva" To: Keith Busch , Dan Williams , Ross Zwisler , Vishal Verma , Dave Jiang Subject: [PATCH] libnvdimm: fix NULL pointer dereference Message-ID: <20180724134006.GA2775@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - lists.01.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.70.148 X-Source-L: No X-Exim-ID: 1fhxXq-001Ac5-T8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.70.148]:46678 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 12 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP ndd is being dereferenced before it is null checked, hence there is a potential null pointer dereference. Fix this by moving the pointer dereference after ndd has been properly null checked at line 554: if (!ndd) Addresses-Coverity-ID: 1472020 ("Dereference before null check") Fixes: 42218e643bd2 ("libnvdimm: Use max contiguous area for namespace size") Signed-off-by: Gustavo A. R. Silva --- drivers/nvdimm/dimm_devs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 9e977cb..1dc3125 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -546,7 +546,7 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region, struct nd_mapping *nd_mapping) { struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); - struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); + struct nvdimm_bus *nvdimm_bus; resource_size_t max = 0; struct resource *res; @@ -554,6 +554,8 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region, if (!ndd) return 0; + nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); + if (reserve_free_pmem(nvdimm_bus, nd_mapping)) return 0; for_each_dpa_resource(ndd, res) {