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=1796384067; b=bHQqUdlmGD8gwP/8c2d5NC98jxDD7BmD65W8XhliKtTIdfQuFa+1ruDGulrcmZzxc/Zr AVEN4QAf7GImh7mCV2vDCiRWT90egoViXchkzguud0qPEJ08PLct+mZf3w6qE+EUlRW9y aQ11+JXaGtlBDQFOPfikWoYaRQBxkpAgUl4iN8L83EJw+sb+5d7+Nr/MtRg4XYC/SPEig dwJDVcnepseGScH1gX+I+A17/HQPQHYgnR9krzg7CBafYf269rtHZAKkZDMCgv9UfIk0w MysAUaOuo5yhffm8WZ/TTgAXP2BxpccZ+f4S1QgiLCEOJrE6RPhNuyzJHTgTTgxo4Pg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384067; 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=RdIw996ic78+Q3p2zJdd1SSayUBQZZYRtzokdvHPgyQ=; b=jLL9ulr/osL9bSy0HABV4KaT2CZhZpMDUI7E9DsBNqkJuGiHdtHa090b/ZNj+asSR0cl su4g0RrOkhTnzeESSHxE0vmPW0kp95q62LBrrF9S4vAmFhXI3m5hpQc2MEou8z2ITy+6T z0qN5kecVkz4pg+Wv7TlM37RZ3LKnKs6srren7JszeuteB/W+O4xSQp1aObE49zSD8ap1 dWTQn/mNskVLSbth2QIm5gZBTQlK4PVqqwm2qW23RBcxt7iF0JMF78TU2H4pAT+Ur49lF XI51etyZWkpVvBAfANABBs2smtZKnExwCWiSsYw8BVFIjxV5XTM5xMeZaJlcMKjP4iw== 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=F1pMl7WU; 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 EBECB606A322; Fri, 4 Dec 2026 11:34:26 +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=F1pMl7WU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67D341F000CE; Fri, 4 Dec 2026 11:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384066; bh=RdIw996ic78+Q3p2zJdd1SSayUBQZZYRtzokdvHPgyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F1pMl7WU1DrVLGSmUTw9ZGhq9lNqGf/cxPDFZ7FDg+3Vj2EgQtPgzYK3xn2SwoYZF Uh9Goz1XWqCDuCyvw82xkqtjHywgJrCuLW8K6g2dVj0uGkbvuD+LJP1rMA6XGI4QRY XBw5X9eqWpQs97llh9iiNxaBqR2Y4LeFopE7V4cU= 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.12 481/555] nvmet-fc: reject duplicate queue IDs on Create Connection Date: Fri, 4 Dec 2026 19:08:44 +0900 Message-ID: <20261204100627.492216243@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 @@ -820,8 +820,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;