From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382699; b=1zRdyh1h1EFP73NBs4zXxITHnldBjgoGI4sPQN0lnozY8ybdfZ3gWNtIP5GQmnHxl+LV 4xY/c7hFJj2/LxCaR1gHuL0L5s5TVdtgltcgG09Et+Rftidnui4LUzDTEUIBq8Re+Uan7 wQcMH7dNX12ToSs8altmyYzQ3GFbL0PgNKp5X6U0rpBL96FJv4YZrPaTi34RgFwmESoT3 RoFwA5KSQR9hwrleN1mtfF8sdM+Zb9KiHRyCxlSZ8pOsVjEOtI4d5RF7Iy0EZsutVykKB RlNDty3s/cAb6DZ1KovvBnJPUrDi+UFZIHwmMLe6C16yG88Zwb/IEJPCuRbrZH2OoJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382699; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Rxpr0w665kn1WTJyxv3sZxI2Ek6yRvHkHeJvupthWAc=; b=I4lrJsLyL6eytRUUJ33rmd2OYtnSYhgBoSDW6k/zDHfp2zGb48mNuEcL5kTHKtdRndVU G9TlFTTxOkA5s6C1VkkFpEpamAuDA71aaXSZ33W+QCFtBDEQ3F/PgTKXEUOScrG0MQX8b OwVgHI00fpg4KIlnrY4lcNFrhdRijdF5LqIDfscRhxaWP7a94q3wJq6ZSH0JVt7AM8PXi yEmHF6sgHw78rvwoFtGMc41m7eM7alJ+IaJ5Ia6GDjH0aammMe9jPdyzUa1SCHwj4TibK libXTo67j1wMTjvD9SOhN1x+Z33WPbVRystGJr+cuzq+kXnRovU3Lkvu4EoUwtELZow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="Np6/qxrH"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61A2F606A322; Fri, 4 Dec 2026 11:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Np6/qxrH Received: by smtp.kernel.org (Postfix) with ESMTPSA id D44F51F000C2; Fri, 4 Dec 2026 11:11:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382699; bh=Rxpr0w665kn1WTJyxv3sZxI2Ek6yRvHkHeJvupthWAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Np6/qxrH65vjrpZFH4Tv9HgoFmi6KyLq1nUsdFLplQg4aRoNSMMez4O6Qvq9CfmQy qRcSk3Si13d6vfUPc3P2GCuAk3FrheBvu+NnS+gp9+8oU8HJVYWlGB19NrWO+wRsz9 GdieW6zjg6/fYPDCwvHX5Z+8NfOL6KuX20gZjZUw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Hellwig , Shao Mingyin , Keith Busch Subject: [PATCH 6.18 566/703] nvmet-fc: reject duplicate queue IDs on Create Connection Date: Fri, 4 Dec 2026 19:07:45 +0900 Message-ID: <20261204100642.825304928@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shao Mingyin commit 153eac284ebf68be74993643e9b2fe2f9b2b1d88 upstream. nvmet_fc_alloc_target_queue() stores the new queue with WARN_ON(assoc->queues[qid]); assoc->queues[qid] = queue; The queue ID comes straight from the Create Connection LS and is only checked against NVMET_NR_QUEUES. A remote initiator can send a second Create Connection for a queue ID that already exists, or send queue ID 0 which was already created as the admin queue by Create Association. The WARN fires and the old pointer is overwritten: the old queue's base reference is never put, so its workqueue, nvmet_sq and nvmet_cq are never released. For the admin queue this also leaves the controller reference unreachable from nvmet_fc_delete_target_assoc(), so the controller and its subsystem reference leak permanently. Publish the queue with cmpxchg() and destroy the newly created queue if the slot is already taken, returning the normal queue allocation error to the initiator. This keeps the existing error path and makes both duplicate and admin queue IDs fail cleanly. Fixes: c53432030d86 ("nvme-fabrics: Add target support for FC transport") Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Shao Mingyin Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/target/fc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -821,8 +821,17 @@ nvmet_fc_alloc_target_queue(struct nvmet if (ret) goto out_fail_iodlist; - WARN_ON(assoc->queues[qid]); - assoc->queues[qid] = queue; + /* + * Publish the queue only if the slot is still free. A Create + * Connection may arrive twice for the same queue ID, or with the + * admin queue ID that was created by Create Association; replacing + * the old pointer would leak that queue and its controller + * reference forever. + */ + if (cmpxchg(&assoc->queues[qid], NULL, queue)) { + nvmet_sq_destroy(&queue->nvme_sq); + goto out_fail_iodlist; + } return queue;