From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3BB606A31A for ; Wed, 2 Dec 2026 13:35:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kLloZ+d3; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DJ8t2prl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=1g682OA60Kvd82ECyGKHTc0fDT8n5WF2oBAcLBoQwwI=; b=kLloZ+d3gLXYNuxeUP+nqwcXgz RT4pwmI6umYrZLMxcByvm58HNoQEtHAurUWdXw5dhS6jg3uuAj7q+7lNhPy9rlCy29lWlozxEE2cA hD4vCMRmLWCMBMe4iUPMXO0gXOh6zJaaVVfwHqSfRxQ6Pv9vgxQMRyHy+k+y2Pq71gUGexH6ZtRcE fTfF7NoAa79WQ0ceEeBN1pI417cwOKH5wdDX3jkayasi9VvW3xBSWapW+9C/KgSxER1TwJa2o8oaH PfjdCn//8EHnpO9bNo6YgCfI15kaNMX8FPnN7kqX3Uk14IWlsJ1Wtgos7aT2VLq2KY0tvavDBjGgh kQC6GyKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYkUJ-0000000Bbha-1rCc; Wed, 02 Dec 2026 13:35:11 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYkUH-0000000BbhQ-3h0K for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 13:35:09 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 1864D609EA; Wed, 2 Dec 2026 13:35:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6DF81F00893; Wed, 2 Dec 2026 13:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796218508; bh=1g682OA60Kvd82ECyGKHTc0fDT8n5WF2oBAcLBoQwwI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DJ8t2prlcBTPaj5hkBsDD9L4PlOacaDEQEYcm7KPW0WSjl3sd/OOxhgOgaXyY4m2/ sOzLuM1yHrkbY4aM1YLMNi4146MzCPaRYWGpTZx9/ktknEv7ksHPimLCJUJDKzXRXu G6oxt9pBY67i+irn4T4KI9BftzVP36IHXBK4yhKE24WNyA7MHKu0TUkZtdKJhdrJnc U0wQK8PNNXNw7IOiNKjvP/KVtIm5AYz2LAXhyVw3/rioF4zA2PHMOn0u1/IQaPM8C4 fPTglZctnZ+r7TdKpaTsQ946O+S5GCs1l/7ep8yGu3nRRILvJF+ueg5hKoTRC3rd7l NHIoYCVTMl6sQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/2] nvme-fabrics: do not leave a timed-out command's id resolvable To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202131909.2556796-3-yhlee@isslab.korea.ac.kr> References: <20261202131909.2556796-1-yhlee@isslab.korea.ac.kr> <20261202131909.2556796-3-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 13:35:08 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] nvme-tcp: UAF and double completion via nvme_cid_to_rq() after C2HData timeout - [High] nvme-tcp: race with active io_work in nvme_tcp_complete_timed_out() -- commit 718cdfd33ac400884137a2b0ab0be73d96fee9e7 Author: Yehyeong Lee nvme-fabrics: do not leave a timed-out command's id resolvable This commit increments the request generation counter in nvmf_complete_timed_out_request() so that late responses arriving for an abandoned command id are rejected by nvme_find_rq(). > diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h > index caf5503d08332..2e3a4a5af2d44 100644 > --- a/drivers/nvme/host/fabrics.h > +++ b/drivers/nvme/host/fabrics.h > @@ -202,10 +202,19 @@ static inline char *nvmf_ctrl_subsysnqn(struct nvme= _ctrl *ctrl) > return ctrl->subsys->subnqn; > } > =20 > +/* > + * This does not go through nvme_try_complete_req(), so advance the gene= ration > + * here: otherwise nvme_find_rq() keeps resolving the abandoned command = id onto > + * a request that is no longer in flight. > + */ > static inline void nvmf_complete_timed_out_request(struct request *rq) > { > if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) { > - nvme_req(rq)->status =3D NVME_SC_HOST_ABORTED_CMD; > + struct nvme_request *nr =3D nvme_req(rq); > + > + if (!(nr->ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN)) > + nr->genctr++; > + nr->status =3D NVME_SC_HOST_ABORTED_CMD; > blk_mq_complete_request(rq); > } > } [Severity: High] Can an in-progress C2HData transfer bypass this generation increment via nvme_cid_to_rq(), causing a use-after-free and double completion? When a 24-byte C2HData PDU header arrives before the timeout (for example, for an auth_receive command while NVME_TCP_Q_LIVE is not yet set), nvme_tcp_handle_c2h_data() validates pdu->command_id with nvme_find_rq() and sets queue->data_remaining, transitioning the queue to NVME_TCP_RECV_DATA. If the command times out before the payload or data digest arrives, nvme_tcp_complete_timed_out() increments nr->genctr and completes rq, freeing its bio, without resetting queue->data_remaining or queue->ddgst_remaining (and without stopping queue->io_work when NVME_TCP_Q_LIVE is clear). When the remaining bytes arrive, nvme_tcp_recv_data() and nvme_tcp_recv_ddgst() resolve pdu->command_id through nvme_cid_to_rq(), which strips the generation bits without checking nr->genctr, writing into the freed bio and calling nvme_tcp_end_request() a second time if NVME_TCP_F_DATA_SUCCESS is set. [Severity: High] Can nvmf_complete_timed_out_request() race with an active queue->io_work when NVME_TCP_Q_LIVE is not set? During in-band authentication, NVME_TCP_Q_LIVE is not yet set, so nvme_tcp_stop_queue_nowait() skips __nvme_tcp_stop_queue() and leaves queue->io_work running concurrently with nvme_tcp_complete_timed_out(): CPU0 (timeout) CPU1 (queue->io_work) nvme_tcp_complete_timed_out() nvme_tcp_stop_queue() /* NVME_TCP_Q_LIVE is 0 */ nvme_tcp_drop_queue_ref() nvme_tcp_try_recv() nvme_tcp_handle_r2t() nvme_find_rq() /* old genctr matches = */ llist_add(&req->lentry, &queue->req_list) nvmf_complete_timed_out_request() nr->genctr++ blk_mq_complete_request(rq) nvme_tcp_try_send() /* walks freed bio <-- use-after-free */ Similarly, if nvme_tcp_process_nvme_cqe() (or nvme_rdma_process_nvme_rsp() before NVME_RDMA_Q_LIVE is set) passes nvme_find_rq() just before CPU0 increments nr->genctr, nvme_try_complete_req() and nvmf_complete_timed_out_request() race without synchronization on nr->genctr++ and rq->state and both complete the request. In addition, nvme_tcp_stop_queue_nowait() clears queue->tls_enabled and NVME_TCP_Q_IO_CPU_SET outside the test_and_clear_bit(NVME_TCP_Q_LIVE) check, leaving queue->tls_enabled false if an authentication retry recovers on the same TLS socket. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202131909.2556= 796-1-yhlee@isslab.korea.ac.kr?part=3D2