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=1796381292; b=wfDLLSARtc0c/HPh7JmnMX4XeihPPHvF7hP8EfGG3n+ivRQjzsRA/erZEYFC8UKBj/eX xrDftPA3feejR0RI8Zf4mc/VGHMbC4rqO3v6O5miqtVtezR6xUJuz+q9WeRl8pd4rx1rX JPiPgeDDQHFSWZYw7OvIZWtQ6xhczGWPrK7nGPhYAyuGIR9dJP2cL+a6errZ7NONTCNdQ 782K9x4NGEXFJ+hskXU3YShstsEnzE5dZJnLWNDpsjFCVgs1Vyziz/JyWskPpw4by+KHv cWc7dwdYwBAJ3/IkwWQ0eFHmqcqK/XMFzSh0I//ffuBW6j/eWKJdS9Bdj1F3QGq8dZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381292; 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=RS5GBv6hiX2nizeF0exaqKg3Ogp8X8aq2uDNnBTdft0=; b=Gi8A/dWd0etXihZt1gyR8wp5CySshRvEOLhMltDDcNnXizlIGdzh1gQFZ+d5LsTRZdXg qJXF6qXEucfEDR1fDB86ZPie7B34c7kGo1ed/eVz4AYGWNBP61kVz1u4oXY6RTDSHhHfu Flp28eZfoRzjbHQXG5L+JX7l7+5WF1wZmvmkyTm62vULuwq4fwHBkdfEX2KhHC8t05KBh rncFC1gpHgt2JS+nzxzg/e98UVlhoCsQxDNcsqSEl/wTK4pet9BVFEydu+czoaXBmt5eY oHwkYcRFwyA333wGQA5LoqRdcFQ9ctQWMMNHL6kc0BSiTZiXlw4gmr8vgDQ3bevPVmw== 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=2PET7flo; 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 D4849606A322; Fri, 4 Dec 2026 10:48:12 +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=2PET7flo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1610C1F00935; Fri, 4 Dec 2026 10:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381292; bh=RS5GBv6hiX2nizeF0exaqKg3Ogp8X8aq2uDNnBTdft0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2PET7floZ+KXozEANmu98v6cZjpeFi178PmpopcgZenwe1UnTaupyg+yoTKTLiFrS mrHUnZSufyTke0z8zku9RYBBbBMGgT3pBj7tn2zV6m98CeLIo/ffE4oqtiEDOC4f5+ mnT3pNQoiiK4lID2n/N+G7rFQu2U/x8jAtyb9gZo= 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 7.3 641/742] nvmet-fc: reject duplicate queue IDs on Create Connection Date: Fri, 4 Dec 2026 19:08:25 +0900 Message-ID: <20261204100652.120094591@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 @@ -818,8 +818,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;