Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2189970iof; Tue, 7 Jun 2022 22:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1c94izDFyIhvGmqysD/W2coeA0UbwOnM4Ik71Thgk+hkAsSQr0UgSAuVSiiu8Lblpz43y X-Received: by 2002:a17:90a:e7c5:b0:1e3:3cf1:6325 with SMTP id kb5-20020a17090ae7c500b001e33cf16325mr35493990pjb.178.1654666791719; Tue, 07 Jun 2022 22:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666791; cv=none; d=google.com; s=arc-20160816; b=l/aeM2YNol/2mrYqn0Gz5XnrQOq9ed2VHoA55hpATf6O05VC8UGyb89hqzObUMbvOX UfyI42OTs4l/I1RG0tSAFM+E39bBEO+dKdy4ik4zWsg992TH7eU7HHkkiwGUfoSWinxQ ue0ecuIuiDjH/KB4Bplh28tJcwu3EnvI4JF/A8JrRc5SmMl/Nc9HKkJhalp23t9vogDD Ss/M0eM7+fE8EtoNLAN/YSoQep3CHOdOjRG8udz0be1Lj2ocANMLtJi0bvTIZJayhdv5 2Au/OERJ9zYKRHCgcfmvxk0hAVt3rnWrByHufvBBjhUqAmZ6F5TflPKBAeFpJdVqUYfD H5OA== 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=zzGwmIZ1BIJwI6iQoBvPN7455wwwbqAstRn8n4An3Vk=; b=r+eqmMK33Az8TLLa+AugEO4RloCtLmK96kgxlV8ep8Q7knv5J9PnnjDr+s+y0lbFU+ 2NQJzMAnUQD5gLXyWitoWMe4xIP0YRECbMZjhgXRBeNmdN7TBRexuw3Wds05PO9yCpt1 141TFCZjFJ9wMFnvgCJTSKP01oYBjarlJicSInnvOZTi/0TlXkHUSdIj1G52DmrfdMjt b6qYlCL3CquZkymlgmcZTLaESf7x9bSQENwJBgC728cyCpubp1flZ4xEcr5nNKAwHeZt LoWiuV+R3ZlPA4Cn3ZD6fZdLDZw46RZQh+oQUqwz97pkKct46XMQbEqb5hWOB8akbcDH gnYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A2JOD7Wk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k18-20020a63d852000000b003f9dd67d2b7si27289942pgj.34.2022.06.07.22.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:39:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A2JOD7Wk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E9EB39027A; Tue, 7 Jun 2022 22:06:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383761AbiFGWGR (ORCPT + 99 others); Tue, 7 Jun 2022 18:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379546AbiFGVGE (ORCPT ); Tue, 7 Jun 2022 17:06:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E8B1CA5EA; Tue, 7 Jun 2022 11:49:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 23C58616B6; Tue, 7 Jun 2022 18:49:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31D30C385A5; Tue, 7 Jun 2022 18:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627782; bh=GfWpQ2f0XwiJpFMuX9ehdEugJEOsWkQR8NGeRHa91uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A2JOD7Wkxp7ce+bT/xFdzMJFgj4XFKMoQyQGhoz2geWa0bxofXjrSY3Ow/TbHfFkk 0QIsh1EudL+SNrZ+sLGlj9vjkjE8kgmN7rWLMIfP3Ubj+990yj9L0awWiRWUtjDDVI TGM9LShDvtnOTTD23d9JaKTKq8CwVO5xv0qxCnlA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Justin Tee , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.18 091/879] scsi: lpfc: Protect memory leak for NPIV ports sending PLOGI_RJT Date: Tue, 7 Jun 2022 18:53:29 +0200 Message-Id: <20220607165005.334825025@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart [ Upstream commit 672d1cb40551ea9c95efad43ab6d45e4ab4e015f ] There is a potential memory leak in lpfc_ignore_els_cmpl() and lpfc_els_rsp_reject() that was allocated from NPIV PLOGI_RJT (lpfc_rcv_plogi()'s login_mbox). Check if cmdiocb->context_un.mbox was allocated in lpfc_ignore_els_cmpl(), and then free it back to phba->mbox_mem_pool along with mbox->ctx_buf for service parameters. For lpfc_els_rsp_reject() failure, free both the ctx_buf for service parameters and the login_mbox. Link: https://lore.kernel.org/r/20220412222008.126521-10-jsmart2021@gmail.com Co-developed-by: Justin Tee Signed-off-by: Justin Tee Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_nportdisc.c | 10 ++++++++-- drivers/scsi/lpfc/lpfc_sli.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c index c4e1a07066a2..4b065c51ee1b 100644 --- a/drivers/scsi/lpfc/lpfc_nportdisc.c +++ b/drivers/scsi/lpfc/lpfc_nportdisc.c @@ -614,9 +614,15 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD; stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, - ndlp, login_mbox); - if (rc) + ndlp, login_mbox); + if (rc) { + mp = (struct lpfc_dmabuf *)login_mbox->ctx_buf; + if (mp) { + lpfc_mbuf_free(phba, mp->virt, mp->phys); + kfree(mp); + } mempool_free(login_mbox, phba->mbox_mem_pool); + } return 1; } diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c index 6adaf79e67cc..09a45f8ecf3f 100644 --- a/drivers/scsi/lpfc/lpfc_sli.c +++ b/drivers/scsi/lpfc/lpfc_sli.c @@ -12066,6 +12066,8 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, { struct lpfc_nodelist *ndlp = NULL; IOCB_t *irsp; + LPFC_MBOXQ_t *mbox; + struct lpfc_dmabuf *mp; u32 ulp_command, ulp_status, ulp_word4, iotag; ulp_command = get_job_cmnd(phba, cmdiocb); @@ -12077,6 +12079,21 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, } else { irsp = &rspiocb->iocb; iotag = irsp->ulpIoTag; + + /* It is possible a PLOGI_RJT for NPIV ports to get aborted. + * The MBX_REG_LOGIN64 mbox command is freed back to the + * mbox_mem_pool here. + */ + if (cmdiocb->context_un.mbox) { + mbox = cmdiocb->context_un.mbox; + mp = (struct lpfc_dmabuf *)mbox->ctx_buf; + if (mp) { + lpfc_mbuf_free(phba, mp->virt, mp->phys); + kfree(mp); + } + mempool_free(mbox, phba->mbox_mem_pool); + cmdiocb->context_un.mbox = NULL; + } } /* ELS cmd tag completes */ -- 2.35.1