Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4672679pxj; Wed, 12 May 2021 10:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyAyRRTdITiQjw7X5n+nm+ZRj05Lz14wYqCHuiqjbRZxyg54ZNQ7bMmJMcDDQ5iGc/MpLW X-Received: by 2002:a05:6402:16db:: with SMTP id r27mr42793945edx.375.1620840813494; Wed, 12 May 2021 10:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620840813; cv=none; d=google.com; s=arc-20160816; b=UBb5E89KfJtOfuNxQf5I0+0OiWvkJoj2550nt79UFi1FjUvrQWByVvRRRHEMrc82Id 0vlQgKvqopjeOO/fxrEXw9NWBgE8w549waZelfXHpqtE8ZE0authaxOplriv0Ue0orwl CxrccvIW3vLhq4v44zPCc/NUZbd5PbUeCeQasrd1piuXr0Qn0DQ8JDQCR3rIH50NVVVC kx+RF5uQ7XjwcghPAEAViHiKygd+NuihhdQ4zBPCehqtA8OYLZI5bPGJBVobY+fhHM6M 1QNYwUhZ70wKnoTcab1MFT1db0PU26YXSTUgwXfjJyBpmF0WBb3lEIuTP4t0XV34JP3U X4BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c9v2wo3Bg/A+nakPXMjdD1zw3L6yIoFChEH4dHb/yl8=; b=oMSbKVI1e2LlnHqKYI7XYNQEt7qNYPVWDv09SR7fRFz2p8L1pQqMbcKQSIexAQ8b4a 4n0IwR4y6n7b2WLLzUiLlcHTKO2Q77Ey6j6vV0D5iSzvdGYu4EMwFzL7UkJBmTgGSNjC 8KSFTUJzhauMw9/8HGFjFbp/dMeAFZmXB3IyUGtPHYsob2U1QsmEu62Jn7lpOYCdf+Kh h/n0cu6O8CcNyuk05FqWOGsCVacEkoDubZMC6ZqBTjF6R1QHPoTp7/I6jSP6D2uh782a MSn+fFkLBTBp18nRrjGYQ3+XFnUS5qUz6qCkPgUjH79uB7ldoRvqPmZOJPpT7EpbPEoN +hHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p2RFP3wC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si536692ejb.212.2021.05.12.10.33.09; Wed, 12 May 2021 10:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p2RFP3wC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348067AbhELRa0 (ORCPT + 99 others); Wed, 12 May 2021 13:30:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:34478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239315AbhELQHv (ORCPT ); Wed, 12 May 2021 12:07:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A4E1361D12; Wed, 12 May 2021 15:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833845; bh=xAtxgmhbkGFKmiSTUgWWI6oVIHIo8vIfPp73W4BZKFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2RFP3wC1Dn2fTzPIma+x81t5NB3Wn90LjZbhGXEJq/yehnOezn/eFT9OKVV1LgmG ksk/v9i5ZtF+1u+rtAA/LGaZ8BgZXY6lE05Cn/VJ5Fl6ZxqKxD8XEzQGgqSJxcM9zP y58hZvqIYMtpeI2o8yaVP45Lcat8pqKkyh/61P/g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dick Kennedy , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.11 311/601] scsi: lpfc: Fix null pointer dereference in lpfc_prep_els_iocb() Date: Wed, 12 May 2021 16:46:28 +0200 Message-Id: <20210512144838.063678528@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart [ Upstream commit 8dd1c125f7f838abad009b64bff5f0a11afe3cb6 ] It is possible to call lpfc_issue_els_plogi() passing a did for which no matching ndlp is found. A call is then made to lpfc_prep_els_iocb() with a null pointer to a lpfc_nodelist structure resulting in a null pointer dereference. Fix by returning an error status if no valid ndlp is found. Fix up comments regarding ndlp reference counting. Link: https://lore.kernel.org/r/20210301171821.3427-10-jsmart2021@gmail.com Fixes: 4430f7fd09ec ("scsi: lpfc: Rework locations of ndlp reference taking") Co-developed-by: Dick Kennedy Signed-off-by: Dick Kennedy Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_els.c | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index 2dce17827504..7359d4f118df 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -1,7 +1,7 @@ /******************************************************************* * This file is part of the Emulex Linux Device Driver for * * Fibre Channel Host Bus Adapters. * - * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term * + * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term * * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * * Copyright (C) 2004-2016 Emulex. All rights reserved. * * EMULEX and SLI are trademarks of Emulex. * @@ -2041,13 +2041,12 @@ out_freeiocb: * This routine issues a Port Login (PLOGI) command to a remote N_Port * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. - * This routine constructs the proper feilds of the PLOGI IOCB and invokes + * This routine constructs the proper fields of the PLOGI IOCB and invokes * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. * - * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp - * will be incremented by 1 for holding the ndlp and the reference to ndlp - * will be stored into the context1 field of the IOCB for the completion - * callback function to the PLOGI ELS command. + * Note that the ndlp reference count will be incremented by 1 for holding + * the ndlp and the reference to ndlp will be stored into the context1 field + * of the IOCB for the completion callback function to the PLOGI ELS command. * * Return code * 0 - Successfully issued a plogi for @vport @@ -2065,29 +2064,28 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) int ret; ndlp = lpfc_findnode_did(vport, did); + if (!ndlp) + return 1; - if (ndlp) { - /* Defer the processing of the issue PLOGI until after the - * outstanding UNREG_RPI mbox command completes, unless we - * are going offline. This logic does not apply for Fabric DIDs - */ - if ((ndlp->nlp_flag & NLP_UNREG_INP) && - ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && - !(vport->fc_flag & FC_OFFLINE_MODE)) { - lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, - "4110 Issue PLOGI x%x deferred " - "on NPort x%x rpi x%x Data: x%px\n", - ndlp->nlp_defer_did, ndlp->nlp_DID, - ndlp->nlp_rpi, ndlp); - - /* We can only defer 1st PLOGI */ - if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) - ndlp->nlp_defer_did = did; - return 0; - } + /* Defer the processing of the issue PLOGI until after the + * outstanding UNREG_RPI mbox command completes, unless we + * are going offline. This logic does not apply for Fabric DIDs + */ + if ((ndlp->nlp_flag & NLP_UNREG_INP) && + ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && + !(vport->fc_flag & FC_OFFLINE_MODE)) { + lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, + "4110 Issue PLOGI x%x deferred " + "on NPort x%x rpi x%x Data: x%px\n", + ndlp->nlp_defer_did, ndlp->nlp_DID, + ndlp->nlp_rpi, ndlp); + + /* We can only defer 1st PLOGI */ + if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) + ndlp->nlp_defer_did = did; + return 0; } - /* If ndlp is not NULL, we will bump the reference count on it */ cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, ELS_CMD_PLOGI); -- 2.30.2