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 0599F606A323 for ; Wed, 2 Dec 2026 13:48:16 +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=SsaV+uac; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VmlsrJuE 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=glSdToCVhSBZwcLXOPKd40vdEp19Lii0S6l2SumV/mo=; b=SsaV+uac6RaSmyBzep7bdeOcJ0 6qUdduYG1sUIuPUoW+7S/q9kflDAQxY/gjHVL6Blyollr7avBt5XkN/l5o2GiESlFFKAdbovSjqB6 4WeKLao6VZJIfBWXo+E0dd9318Qucpt6ZidX8swob7oQRivoSMpxqZ8TXR0RlK39ZruTDCA4CDQNZ rn/2qQUkucUkWPKRNUFlEE334jqxpVyGKO8saN6Ghed88pYceyYJ8Lmk2hzf460t6191+pZO4MxWt Tv5sjplku7TgiAarKMX3oHcVBWDIdlHYfg9Dnehr6o3hR1EmAGApIZMuqpS8SZy7O9DP2eURhuluw mrV34rBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYkgw-0000000Bd5r-1DeF; Wed, 02 Dec 2026 13:48:14 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYkgv-0000000Bd5V-0Ffa for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 13:48:13 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 55B81618E9; Wed, 2 Dec 2026 13:48:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82A711F00893; Wed, 2 Dec 2026 13:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796219291; bh=glSdToCVhSBZwcLXOPKd40vdEp19Lii0S6l2SumV/mo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VmlsrJuEaQicxWZunmspTDj6jPSl65ejOod/f8tsz2HCExoCfK63c9u+KdXcJQvyq yMiR7j5GxRojV0Ot/wDCpBMj4+8H1DiJslKqO4vIQD3UvT/9khAi136EqXBCfIAmOx xgdKWr7v447fG+eAyhyfNCV2ex6cz9BYqaMdZNpZfkFKGza4B5dU52yg8NwK9KgUGH 2nfn2z+yZqpij2GlJcV1946sdoenRLkP2OObuQKj1/zipMQgf08+hWEkD5Bgdi1srP lPHBod5mngUKQMjPrPLgb15vB7BO4C/UvzA3O+5Be8pBonuOHEy2lCbBc8nCll832r 6UjbxrK2WLKBA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 1/2] nvme-tcp: drop the queue's reference to a timed-out request To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202131909.2556796-2-yhlee@isslab.korea.ac.kr> References: <20261202131909.2556796-1-yhlee@isslab.korea.ac.kr> <20261202131909.2556796-2-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 13:48:11 +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 in nvme_tcp_recv_data() after timeout - [High] nvme-tcp: race in nvme_tcp_complete_timed_out() before dropping queue ref -- commit aeeaaf545efa2b40c5cf8bc8268997a438e0fbcb Author: Yehyeong Lee nvme-tcp: drop the queue's reference to a timed-out request This commit drops the queue's send-path references (queue->request, send_list, and req_list) under queue->send_mutex in nvme_tcp_complete_timed_out() before completing a timed-out request. > diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c > index 62a594b8ab9bf..5320375d6f691 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -3031,12 +3031,36 @@ static void nvme_tcp_submit_async_event(struct nv= me_ctrl *arg) > nvme_tcp_queue_request(&ctrl->async_req, true); > } > =20 > +/* > + * Completing the request below frees its bio, but the queue can still r= efer to > + * it - as queue->request, or linked on send_list or req_list - and only= the > + * send path drops those, which stopping the queue has just shut down. > + */ > +static void nvme_tcp_drop_queue_ref(struct nvme_tcp_request *req) > +{ > + struct nvme_tcp_queue *queue =3D req->queue; > + > + mutex_lock(&queue->send_mutex); > + > + if (queue->request =3D=3D req) > + queue->request =3D NULL; > + > + /* a single entry cannot be unlinked from a lockless list */ > + nvme_tcp_process_req_list(queue); > + if (!list_empty(&req->entry)) > + list_del_init(&req->entry); > + init_llist_node(&req->lentry); > + > + mutex_unlock(&queue->send_mutex); > +} [Severity: High] Does nvme_tcp_drop_queue_ref() leave the receive context pointing at the timed-out request when a read command times out after its C2H Data PDU header has already been parsed? When nvme_tcp_handle_c2h_data() validates the header before the timeout, it stores the PDU in queue->pdu and sets queue->data_remaining, moving the queue into NVME_TCP_RECV_DATA (or NVME_TCP_RECV_DDGST). Neither __nvme_tcp_stop_queue() nor nvme_tcp_drop_queue_ref() clears queue->rd_enabled or calls nvme_tcp_init_recv_ctx(), and kernel_sock_shutdown(queue->sock, SHUT_RDWR) does not flush bytes already queued in sk->sk_receive_queue. Once the controller transitions to NVME_CTRL_LIVE and a new request is dispatched to the stopped queue, nvme_tcp_io_work() fails nvme_tcp_try_send() with -EPIPE, breaks out of the loop, and re-queues io_work; on the next run nvme_tcp_try_send() returns 0 and nvme_tcp_try_recv() executes: drivers/nvme/host/tcp.c:nvme_tcp_recv_data() { struct nvme_tcp_data_pdu *pdu =3D (void *)queue->pdu; struct request *rq =3D nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); struct nvme_tcp_request *req =3D blk_mq_rq_to_pdu(rq); Because nvme_tcp_recv_data() and nvme_tcp_recv_ddgst() resolve pdu->command_id directly with nvme_cid_to_rq() rather than nvme_find_rq(), they bypass genctr validation, copy incoming data into req->iter and req->curr_bio after the timed-out request's bio has been freed, and call nvme_tcp_end_request() to complete rq a second time. > + > static void nvme_tcp_complete_timed_out(struct request *rq) > { > struct nvme_tcp_request *req =3D blk_mq_rq_to_pdu(rq); > struct nvme_ctrl *ctrl =3D &req->queue->ctrl->ctrl; > =20 > nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); > + nvme_tcp_drop_queue_ref(req); > nvmf_complete_timed_out_request(rq); > } [Severity: High] Can nvme_tcp_try_send() fail and complete req while nvme_tcp_stop_queue() runs before nvme_tcp_drop_queue_ref()? __nvme_tcp_stop_queue() shuts down the socket before cancelling io_work and without holding queue->send_mutex, and nvme_tcp_stop_queue() then sleeps in nvme_tcp_wait_queue() while req is still on queue->request, send_list, or req_list: CPU0 (timeout) CPU1 (io_work / .queue_rq) nvme_tcp_complete_timed_out(rq) nvme_tcp_stop_queue() kernel_sock_shutdown(SHUT_RDWR) nvme_tcp_try_send() sock_sendmsg() -> -EPIPE nvme_tcp_fail_request(queue->request) nvme_tcp_end_request(rq, ...) cancel_work_sync(&queue->io_work) nvme_tcp_wait_queue() msleep(2) blk_mq_requeue_work() nvme_tcp_queue_rq(rq) nvme_tcp_drop_queue_ref(req) nvmf_complete_timed_out_request(rq) <-- aborts or double-completes rq If rq is retryable (such as an in-band authentication command submitted with NVME_SUBMIT_RETRY), nvme_tcp_fail_request() requeues it with delay 0. While nvme_tcp_wait_queue() sleeps, blk_mq_requeue_work() can re-dispatch rq back to MQ_RQ_IN_FLIGHT on the queue, after which nvme_tcp_drop_queue_ref() strips the re-dispatched request from the queue and nvmf_complete_timed_out_request() aborts it. Even without a retry, if the concurrent completion moves rq->state from MQ_RQ_COMPLETE to MQ_RQ_IDLE between the two READ_ONCE(rq->state) checks in blk_mq_request_started(rq) && !blk_mq_request_completed(rq), nvmf_complete_timed_out_request() calls blk_mq_complete_request(rq) a second time. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202131909.2556= 796-1-yhlee@isslab.korea.ac.kr?part=3D1