From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74EEAC433EF for ; Tue, 30 Nov 2021 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3BFpi8vyf/vWgmFdUuPXQuS/VC4owiDE6GAOmIN/FeA=; b=NUd/soM/CoXaMNlD6XnKk4BHfb Dl0xcBzi3a5soah9l3lguRbFKeCUevUXEqz2n0FRDUM1m+gtkDMElNcBJeC3jMJa6x8r4RnptQ30i NHrTwIav5YwwXP/ne1cKl9wHOmt6MsAH88VXrQUso4eDaZNyCxkAGDQPYKyE26PP8a1tTW/nxiaX8 iLqU0UJ+11ioWhvqN7FyjtlGqMJmRQ1JdKioIUI717AVSR/wemcCgMcmFzieaMPLjSkE/FjNIbePd lVKx6latVkZe2WIIsxRn2WaUtoy0dFQmge8W8p7WlpR+nPhXTKRBEWsRILn66HfjwS0bYF20GATZK Cp2wnG6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ms4oH-005ona-CL; Tue, 30 Nov 2021 15:12:45 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ms4Uf-005huB-NX for linux-nvme@lists.infradead.org; Tue, 30 Nov 2021 14:52:31 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 73281B81A5B; Tue, 30 Nov 2021 14:52:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32210C8D184; Tue, 30 Nov 2021 14:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638283948; bh=ICUdGkqYwSHrugGh9rrnC4N6Hn5WnSLJOgTy/dDQIMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YJJj2/yU4wDHY29ypvRrp1JOlEaHjXBE53YdzcMif8GO2dJzVycMF1gQlr8ghu+nO JwzNlAbI6R24ZxUDGHKJ3BM6PP4xcCGTwHxCpT+DqCy9AOTnrpbqtVIxXATMpdDPo9 no9sTGo9YjMA88hk6lvbiLd3OP28fL8rcwEnbt/mbKkCkX65DyxGHU5ioEf8pNeQ6x PsO6GJCNcOEY19CGkpLkyvP4FiwMHeMCG5MoAj82/XNfNpjNHX3RfcfgKg/6D2yBA8 hEuvHUzOOXkQX+AWWrirwZBNAlGyFea7pN7GjNxwSTfDZ17iXVYPWr6stg7eTgIXUc vNvuHKsRKZlfA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maurizio Lombardi , Keith Busch , Sagi Grimberg , John Meneghini , Christoph Hellwig , Sasha Levin , kch@nvidia.com, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 16/25] nvmet-tcp: fix a race condition between release_queue and io_work Date: Tue, 30 Nov 2021 09:51:46 -0500 Message-Id: <20211130145156.946083-16-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211130145156.946083-1-sashal@kernel.org> References: <20211130145156.946083-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211130_065229_947134_26BE5BA0 X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Maurizio Lombardi [ Upstream commit a208fc56721775987c1b86e20d86d7e0d017c0b2 ] If the initiator executes a reset controller operation while performing I/O, the target kernel will crash because of a race condition between release_queue and io_work; nvmet_tcp_uninit_data_in_cmds() may be executed while io_work is running, calling flush_work() was not sufficient to prevent this because io_work could requeue itself. Fix this bug by using cancel_work_sync() to prevent io_work from requeuing itself and set rcv_state to NVMET_TCP_RECV_ERR to make sure we don't receive any more data from the socket. Signed-off-by: Maurizio Lombardi Reviewed-by: Keith Busch Reviewed-by: Sagi Grimberg Reviewed-by: John Meneghini Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index fac1985870765..b3e82b0889f0b 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1352,7 +1352,9 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w) mutex_unlock(&nvmet_tcp_queue_mutex); nvmet_tcp_restore_socket_callbacks(queue); - flush_work(&queue->io_work); + cancel_work_sync(&queue->io_work); + /* stop accepting incoming data */ + queue->rcv_state = NVMET_TCP_RECV_ERR; nvmet_tcp_uninit_data_in_cmds(queue); nvmet_sq_destroy(&queue->nvme_sq); -- 2.33.0