Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2278538imb; Mon, 4 Mar 2019 00:34:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzz1nU/J1gddVqgXcmMSUoyghf5DSXJR668QRYFYtC+7S34CyryqypctbQR02Y6DxZx/zfA X-Received: by 2002:a17:902:2a47:: with SMTP id i65mr19527637plb.237.1551688487837; Mon, 04 Mar 2019 00:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551688487; cv=none; d=google.com; s=arc-20160816; b=jjIr41PAie7SqDG/mF8hvlbPaMvO6zw5uw+vgeU8HQFV1R/sEdiy+70GFZoj5Ikhhg +duQoKy2t1vb1yD2so9gm6xlwkcwfgiFjSxGDFocIrn2MJ/AVbmNPUa2Eyvtg+6p58yr Xg7v3YnkYRfvRwV5PfuPKfxsMoLLiRW4iTFtR6jwNrWndf6xgUHcmga5g7HOlwvHmlf+ n+vqRrncs0z+V3nH8AxhbG+UiSKYL54YVBRbcvn6EsdEH5aRSAkljigfKZ3eP29cE2AY Q5u8CCncbv6NF/5MB0etGOpuN/oLSoZzj3t0C3D2gv3rszeLdrKQ6EqmrSJIAjDc574u m+Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vsUXKFh6ZN21s+eUs01M0rHzSE1r4JlZMgu09vFqGjo=; b=U36yqLdCS9r6iz8zV7C4rGZgbG5KwN9dlG8UE9QRmR44G/T4bhSNFMuo3nOK1sL7ee VEvoKSgfZ1eE4DB7MqlLtFzcUPxODp8qzGWawVSvj+/tBOpE/r2D9LuH0Qkl4qFk15jk PvtawuZOpxDB5yzFu1YIXYHWX/6kAH/JcYsmLlJoEc1wo2O+R26LkXLM8r2C766ipJmF flP5uGvt1pGFa2SnkKmKjSQzZ63UFt0dMzQ2OCr09eqRhmDKTy9MU2oPpGUd1HRkP6yX EI3QM2NCaSMpyEu1Ac8w+sgjfEZrwvBWTCXd9QtjyBcRRYsfCL5KczLYyCn1eHe5NVch OOVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kdgItVKf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9si2713777pgn.358.2019.03.04.00.34.32; Mon, 04 Mar 2019 00:34:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kdgItVKf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728252AbfCDIeO (ORCPT + 99 others); Mon, 4 Mar 2019 03:34:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:39662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbfCDIeK (ORCPT ); Mon, 4 Mar 2019 03:34:10 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A1E8820823; Mon, 4 Mar 2019 08:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688449; bh=KH2HEWqZB1p1MDITrIUNbFYsAvJKTR/Oz/Sed/XdKdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kdgItVKfxgUaxFFe8guo1pIZ49b2gs5fTXUr8kkjIVjlLV71q2HMHLrq3DAygyUFw YhSYj94Y/BjVoKKKma84ftnHzpqMGwKus9KPqH145to9NNxHM7N82ggnNvZPTmLDAN RL94bacqW6QkvVAg4df7gweBvlsTt4e+W11EI3mA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Ewan D. Milne" , James Smart , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.20 47/88] scsi: lpfc: nvmet: avoid hang / use-after-free when destroying targetport Date: Mon, 4 Mar 2019 09:22:30 +0100 Message-Id: <20190304081632.419080774@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081630.610632175@linuxfoundation.org> References: <20190304081630.610632175@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c41f59884be5cca293ed61f3d64637dbba3a6381 ] We cannot wait on a completion object in the lpfc_nvme_targetport structure in the _destroy_targetport() code path because the NVMe/fc transport will free that structure immediately after the .targetport_delete() callback. This results in a use-after-free, and a hang if slub_debug=FZPU is enabled. Fix this by putting the completion on the stack. Signed-off-by: Ewan D. Milne Acked-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_nvmet.c | 8 +++++--- drivers/scsi/lpfc/lpfc_nvmet.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c index 6245f442d784b..95fee83090eb7 100644 --- a/drivers/scsi/lpfc/lpfc_nvmet.c +++ b/drivers/scsi/lpfc/lpfc_nvmet.c @@ -1003,7 +1003,8 @@ lpfc_nvmet_targetport_delete(struct nvmet_fc_target_port *targetport) struct lpfc_nvmet_tgtport *tport = targetport->private; /* release any threads waiting for the unreg to complete */ - complete(&tport->tport_unreg_done); + if (tport->phba->targetport) + complete(tport->tport_unreg_cmp); } static void @@ -1692,6 +1693,7 @@ lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) struct lpfc_nvmet_tgtport *tgtp; struct lpfc_queue *wq; uint32_t qidx; + DECLARE_COMPLETION_ONSTACK(tport_unreg_cmp); if (phba->nvmet_support == 0) return; @@ -1701,9 +1703,9 @@ lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) wq = phba->sli4_hba.nvme_wq[qidx]; lpfc_nvmet_wqfull_flush(phba, wq, NULL); } - init_completion(&tgtp->tport_unreg_done); + tgtp->tport_unreg_cmp = &tport_unreg_cmp; nvmet_fc_unregister_targetport(phba->targetport); - wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); + wait_for_completion_timeout(&tport_unreg_cmp, 5); lpfc_nvmet_cleanup_io_context(phba); } phba->targetport = NULL; diff --git a/drivers/scsi/lpfc/lpfc_nvmet.h b/drivers/scsi/lpfc/lpfc_nvmet.h index 1aaff63f1f419..0ec1082ce7ef6 100644 --- a/drivers/scsi/lpfc/lpfc_nvmet.h +++ b/drivers/scsi/lpfc/lpfc_nvmet.h @@ -34,7 +34,7 @@ /* Used for NVME Target */ struct lpfc_nvmet_tgtport { struct lpfc_hba *phba; - struct completion tport_unreg_done; + struct completion *tport_unreg_cmp; /* Stats counters - lpfc_nvmet_unsol_ls_buffer */ atomic_t rcv_ls_req_in; -- 2.19.1