Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3920150pxb; Mon, 21 Feb 2022 08:19:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzW+aKdnSQU2wbafXzeMyFEzrZ79vcrYmlydpuhRAaA/KMb5Me1Xebrj5ekUbhhQ7kyBT1Z X-Received: by 2002:a17:903:244d:b0:14b:2c5f:b278 with SMTP id l13-20020a170903244d00b0014b2c5fb278mr19439744pls.13.1645460374317; Mon, 21 Feb 2022 08:19:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645460374; cv=none; d=google.com; s=arc-20160816; b=v+VFMxQSWCwixPlmDFW13TNkzf+iNH1ZhjmOnviuzKQ+o7KyIlH3OP4j6gdUSn09jx GX1PNviCSS2uzfRKsWSfoqwKQJkmggr0LqMWDn1OAiKlEkaWRWfZ3aGOBIniK1LECcKQ qn1m+00Y1E3b63EJIAK5Byfbx7PgrTxcL72RQMoC6nOXjHA7bZNg1HuCkwdC/jrd2hQi 8tF6g41m7y2MZTIccz0NcSlwVtHRugxsTYQ+xBHWaNa8vaxLuVfO7ljcwfQ6UkAetPAG jDf0z3ur2CtM9zNdm8VyvuKfUNRD0nmniPu/pG54MG+iGXcyUsCHC6li6l9g5fc7GuLM ZRmg== 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=0uEBABQlCXiFnCVuvIL5FAq+qUQwvgtAWmNHUi7VEI8=; b=GVyIIKd9+QoCmQCUNC73Wn5/ttHcI/gx8McumRtRJhNHciYmGYWW7XPZTmF4RugFoK 5t9dDGjks74UVtVF+wMnqXeUYRuVOqd2vdrhTS9dAtRupHQFvoxO1OxKR3tkSYscW+CY bfIaujqWsHhPpIh13e300352wxs+FZOyAqceI4dMPsjb9kKtinKrd+lRP5ht62+Um6A9 iaaOMAxugBA8hpEd1ZhGUgtjNuQ7Wsx+iNhu78sD8i3NWZo2+/49K7CmMd6mYAix7Qra 9dHWjeEZ0Ujz1NAN/8EgSul4x8c3VTjzdXNIIpeGijfBbE9tZ5QAMR4CBDShRQkiRoTb +yjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zrCcEp3r; 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 kk13si7507506pjb.65.2022.02.21.08.19.17; Mon, 21 Feb 2022 08:19:34 -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=zrCcEp3r; 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 S1348269AbiBUJLK (ORCPT + 99 others); Mon, 21 Feb 2022 04:11:10 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347432AbiBUJGZ (ORCPT ); Mon, 21 Feb 2022 04:06:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A2231205; Mon, 21 Feb 2022 00:59:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id D8E01B80EA1; Mon, 21 Feb 2022 08:59:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A583C340E9; Mon, 21 Feb 2022 08:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433984; bh=xbseft0bFThlkg8lFzuN/SR2wFUAQLzKHqgJRlH3A6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zrCcEp3rLBjL+P3IL8biltaDjTd1Gs7Ix/sZnvKug1x2SXJuvaw2pmHVUjHevccKl H0nji1Zyir1OzVviLbyvWUHz5HvNokBPj790bFG1O61hmuRcF+RnQ8uiIJeg4hLFCo pz2MLQSBSxO0jmj8n1oQWonE0kOqsdmTXAMP3SA8= 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.4 20/80] nvme-rdma: fix possible use-after-free in transport error_recovery work Date: Mon, 21 Feb 2022 09:49:00 +0100 Message-Id: <20220221084916.247334386@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@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 08a23bb4b8b57..4213c71b02a4b 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1110,6 +1110,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