From patchwork Mon Nov 27 13:52:30 2017 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: 10076959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF9C06028E for ; Mon, 27 Nov 2017 14:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A290E28C69 for ; Mon, 27 Nov 2017 14:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9624D28E7F; Mon, 27 Nov 2017 14:16:49 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 398C828C79 for ; Mon, 27 Nov 2017 14:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752713AbdK0OQr (ORCPT ); Mon, 27 Nov 2017 09:16:47 -0500 Received: from gateway36.websitewelcome.com ([50.116.124.69]:24415 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752682AbdK0OQq (ORCPT ); Mon, 27 Nov 2017 09:16:46 -0500 X-Greylist: delayed 1446 seconds by postgrey-1.27 at vger.kernel.org; Mon, 27 Nov 2017 09:16:46 EST Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway36.websitewelcome.com (Postfix) with ESMTP id B2C31400F16DC for ; Mon, 27 Nov 2017 07:52:39 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id JJpvenALxFKV0JJpvezEsf; Mon, 27 Nov 2017 07:52:39 -0600 Received: from [189.175.122.225] (port=45866 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.89) (envelope-from ) id 1eJJpu-0035Yc-1q; Mon, 27 Nov 2017 07:52:38 -0600 Date: Mon, 27 Nov 2017 07:52:30 -0600 From: "Gustavo A. R. Silva" To: James Smart , Dick Kennedy , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] scsi: lpfc: Fix potential NULL pointer dereference in lpfc_nvme_fcp_io_submit Message-ID: <20171127135230.GA4546@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 - vger.kernel.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.175.122.225 X-Source-L: No X-Exim-ID: 1eJJpu-0035Yc-1q X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.175.122.225]:45866 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pnvme_lport is being dereferenced before it is null checked, hence there is a potential null pointer dereference. Fix this by null checking pnvme_lport before it is dereferenced. Addresses-Coverity-ID: 1423709 ("Dereference before null check") Fixes: b7672ae681f8 ("scsi: lpfc: Fix crash in lpfc_nvme_fcp_io_submit during LIP") Signed-off-by: Gustavo A. R. Silva --- Also, I wonder if the right pointer to check at line: if (!pnvme_rport || !freqpriv) { is pnvme_fcreq instead of freqpriv drivers/scsi/lpfc/lpfc_nvme.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c index 517ae57..68cba7d 100644 --- a/drivers/scsi/lpfc/lpfc_nvme.c +++ b/drivers/scsi/lpfc/lpfc_nvme.c @@ -1251,6 +1251,11 @@ lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport, uint64_t start = 0; #endif + if (!pnvme_lport) { + ret = -ENODEV; + goto out_fail; + } + lport = (struct lpfc_nvme_lport *)pnvme_lport->private; vport = lport->vport; phba = vport->phba; @@ -1261,7 +1266,7 @@ lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport, } /* Validate pointers. */ - if (!pnvme_lport || !pnvme_rport || !freqpriv) { + if (!pnvme_rport || !freqpriv) { lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_IOERR | LOG_NODE, "6117 No Send:IO submit ptrs NULL, lport %p, " "rport %p fcreq_priv %p\n",