Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp207065imj; Thu, 14 Feb 2019 18:41:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IYikHu1B6A/GdpdP6IZBqVn/GOCor3QrqfmRJ5jpi1tElCCQv5lXc5OR0Ayn7CwKhT2U/px X-Received: by 2002:a17:902:8a8a:: with SMTP id p10mr7762634plo.50.1550198513045; Thu, 14 Feb 2019 18:41:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550198513; cv=none; d=google.com; s=arc-20160816; b=uUWkG3BrKRq/oUBtAVymPIg6bNtVTPiQoaEl1QqdxPqOoXeipKjZ0Vd2c5KOoSg/TV hkGCqChkNqADekg01u8TkgjUfX+UQv/6LQOLAHOSJDh9Ux49Cc7u7IrxDxi+YcgTyC3y mY75nJBwMnPbnufuaKY2I6DIolk+nNsMPjEYxcuqeGJWK+EUf8gtNFkj6VsryY2FXLGR WKlpOUq2N8lJ/HhoLtDvnQ7oViHRxAwlEqgyXulI5by4+TVuiFGVg0ZqxZ7Mo4d8ukPw ExHl63tdP2GlBzLzL19cHp1pUJajN9b0ue4yDQiXwoGSPU84w6g9bKbWaaCtGxn4t+Hx oznA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kwDMYHHA0kMVF4MLt++SMxnkb4szvwATvkJnXaB0P8A=; b=n6MKLYvJInJKugeqUUISf/UPGCReUbEb5HwNDSLCdsxuaKkp7uLSrlV5qKPRR7oTii 47eis1xSPZjd9ABPN2UffN2XrhVOI5JOlRjjZAX9nBgyprEtDeEvGWkuptLdugH5zche 1vn74FtJjrnZqbxos8IXo/RJqP1RTs9YJl8rz4jTKCCino6x2Cz4M6u3OY+e61xkUO7q LxUHw9FsQu2Yvize3na8cb0BbDfk2wuFxc9n8sikslMg5ioNp8JMkO4W/JiFYe+wRrLg MZpsWfKOBS+a3V+MLlvSqGjeO7mc9raFozc3I0VMwlEVzSohiVr4zqae9/7CI8erKK8M +HtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T4fzvYOi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e129si3859154pgc.333.2019.02.14.18.41.37; Thu, 14 Feb 2019 18:41:53 -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=T4fzvYOi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729574AbfBOCij (ORCPT + 99 others); Thu, 14 Feb 2019 21:38:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:50528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390334AbfBOCKY (ORCPT ); Thu, 14 Feb 2019 21:10:24 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5D8E921B68; Fri, 15 Feb 2019 02:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196624; bh=dRklQz0aq5dKE1usUj0gV5+J6HY/pFo3wyV1njM54K0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4fzvYOiO7XfkGVIAWcJuFHcYtMQ5emQwQWi5gBqBKiRK/JYF4QaE7AtuaT3whVOX yPXOx/2pMn/9phqJN8k12cTiUbEgA17cC3eyaw+YmDrgbzUvRM2wrP3woBJkXtzGyV dajrD/lrPatU6jRpxUGvLT5Xkm6PXRYDcXIh0kGo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Ewan D. Milne" , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 52/77] scsi: lpfc: nvmet: avoid hang / use-after-free when destroying targetport Date: Thu, 14 Feb 2019 21:08:30 -0500 Message-Id: <20190215020855.176727-52-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Ewan D. Milne" [ 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 6245f442d784..95fee83090eb 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 1aaff63f1f41..0ec1082ce7ef 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