Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4315758pxb; Mon, 21 Feb 2022 17:45:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJw59XO+Amd7GK1DndsVp4JVStSvPQmDwDuojw8EMsGPA2TESjGrTkZLrGU5RhFMDWj1jvuE X-Received: by 2002:a17:90b:250f:b0:1b8:f257:c39 with SMTP id ns15-20020a17090b250f00b001b8f2570c39mr1639975pjb.135.1645494353098; Mon, 21 Feb 2022 17:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645494353; cv=none; d=google.com; s=arc-20160816; b=dfBOBMGG/6e/lDL3In8kAWw154J99BSflRUrcgYpkgzAZhNfY7CBhDUhdIIcS916Rr oJe3zYkm7icGh5XHhbyJU/Rm+KK4dgpW9C5R8BSKvLpmupUQFvMTMQ+Sl3KiJzOG8TMi rOzkFYL4HDZyVOHxPu4g6mloZwzPhs1kr5ZgWVZTbLrv0xMSfJMNCgR50/wdALi0eF1v QFodnKa7KRDJ6AhhuqZpNszNSXMN/bRh21lCBO+DPrGlC56U9HI1KMqD5tTxPG0WN3y9 0ttxttVwSLdZGQtQVbO4Kd5ofsIyjBtB0fewId25WvXFVAWrjegdlsuB/2v4BLhi3MtT bs3Q== 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=CN1TgepjUBrmnL+a1R/NPPyRwbSC7ptmROEXP+5E2Gk=; b=06kBliDoUzXJQyeeEIns2BkEvuAIwf2RRIMfnSi9eV4904ynyjnHRPTvlmOUdeL6RU /4xkDxK9jxHZ2kKWeQicJWE2GHB1awJrh3r+JiZYieEhJ4Vk0UAhLqfU06kQ0zV8TQup /KNOwj8EpbpGkeEQcfqwNNkezrGEBbnEnocCRqrHGBE2/UvNjYqL7UCMr7DSL0g+Yv5w YUHTxjJ2MgrAeiJ6Zy0X2jMDikI1Tc4gkVdYY0qMRledq3nFUjYh16W1fBbpfw072zfi LdR0N7bFQdotaqo8lwQ6QyM57cc0hXHG3cTGd1dZPNKvH+iWj/QRA7yTQsKyat4rtr0Z s3Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vHGwT+O2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14si36749572plh.157.2022.02.21.17.45.38; Mon, 21 Feb 2022 17:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vHGwT+O2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1350822AbiBUJvg (ORCPT + 99 others); Mon, 21 Feb 2022 04:51:36 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352246AbiBUJrQ (ORCPT ); Mon, 21 Feb 2022 04:47:16 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2623F4162F; Mon, 21 Feb 2022 01:19:14 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 970BDCE0E92; Mon, 21 Feb 2022 09:19:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE1BC340E9; Mon, 21 Feb 2022 09:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435151; bh=uOGHB0PhJWRjRJyytDv6xrbR6xnITxBkeN0s7zIIQGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vHGwT+O2xFhPS8bv8rHRublq1r55XaTHtLFUEtkGQGc578xnMSCuPrDFIWA0HKXuL Au4w3BJvSk0tdfmoxPx+yyCFHzIOQQtigAOpsaYZqFSQvUHw2UfJeJdHNvq3j+tT1N 6X/V4wz3+aMfCTBer8sOlXaBFkrMk50X0Otu0hQ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sagi Grimberg , Sasha Levin Subject: [PATCH 5.16 062/227] nvme-rdma: fix possible use-after-free in transport error_recovery work Date: Mon, 21 Feb 2022 09:48:01 +0100 Message-Id: <20220221084936.938754076@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Sagi Grimberg [ Upstream commit b6bb1722f34bbdbabed27acdceaf585d300c5fd2 ] While nvme_rdma_submit_async_event_work is checking the ctrl and queue state before preparing the AER command and scheduling io_work, in order to fully prevent a race where this check is not reliable the error recovery work must flush async_event_work before continuing to destroy the admin queue after setting the ctrl state to RESETTING such that there is no race .submit_async_event and the error recovery handler itself changing the ctrl state. Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 850f84d204d05..9c55e4be8a398 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1200,6 +1200,7 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work) struct nvme_rdma_ctrl, err_work); nvme_stop_keep_alive(&ctrl->ctrl); + flush_work(&ctrl->ctrl.async_event_work); nvme_rdma_teardown_io_queues(ctrl, false); nvme_start_queues(&ctrl->ctrl); nvme_rdma_teardown_admin_queue(ctrl, false); -- 2.34.1