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 61850606A322 for ; Fri, 4 Dec 2026 15:08:06 +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=Tk3+Kww6; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ouS/L15Z 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=HVr4s3VLx3/ONMJwdjbBTbCYJhHcx8NkIsrRchYlwCo=; b=Tk3+Kww6LtpV0ZbtNxYZaM8lyE Xk+dov7l1VE7jddEx6WnuB0TnVy1YKEoVFFWRA8UVaRG7lNnM03G4Oc/euoX4VJe4trt7g2IB+4ai ipsyWU+aR0bbPOUF7Gzv06+WWam/nNcjy5LVAZx70kvwpv5YqKUtluacKj4zhJ/bRHJ8bvIGcptjF 7QHj1vCSdEKLfK1CyEJEmRL5DpfLNAnmrdqg3NTaZ1jtOkxglxqBottAxzhwE0TG3TZwB00zp053L jqfIfgZm+4PQn755/9lHQd8Fv7D5AmrQshoEgSmMEyYbFZkYU1GIqi60jW9qvJPaO4tgxq5ompgJl y1OMzGIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZUtI-00000000hVq-31i3; Fri, 04 Dec 2026 15:08:04 +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 1xZUrv-00000000hSe-2Vca for linux-nvme@lists.infradead.org; Fri, 04 Dec 2026 15:07:10 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8016360D28; Fri, 4 Dec 2026 15:06:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17B881F000C2; Fri, 4 Dec 2026 15:06:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796396798; bh=HVr4s3VLx3/ONMJwdjbBTbCYJhHcx8NkIsrRchYlwCo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ouS/L15ZXrlwJnYBvpVeR23oQuCOId+dYdg7TBYUrlqA4gZ6HmREDQcK7CeHozk0P CGDJJE4oXGILigJyV1piJnZdK5+onxd3droDUiN4q3rnuCa3FrEXml1pR+sA6ojv6a BpZU5wqojKG/p2bOi0mvW/LUGhqPK+QN7I/xwHuCljj+x2TMUbcBVD81Mufh9FORep DHi21X0HZquR6cdvbcr04QM0btb2m1gwFGAlXsLHMYGnCUw3PaNmOXPVUNp9oDZ9Hj hO+/kIwuA/evBSs6Lyvqflyg+X2LxpDKAJdpoEsLCI0KwMWoWf6xEZc1jNCUIqurWT G+CJH1NeTr4vg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 2/2] nvme-tcp: do not leave a timed-out request reachable from its queue To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261204135345.2994739-3-yhlee@isslab.korea.ac.kr> References: <20261204135345.2994739-1-yhlee@isslab.korea.ac.kr> <20261204135345.2994739-3-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:06:37 +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=-11.3 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 8 potential issues to consider: - [High] nvme-tcp: UAF and NULL deref of sock and pdu in nvme_tcp_complete_timed_out() - [High] nvme-tcp: TCP PDU framing corruption in nvme_tcp_drop_recv_ctx()/queue_ref() - [High] nvme-tcp: nvme_tcp_complete_timed_out() races with nvme_tcp_poll() R2T - [High] nvme-tcp: nvme_tcp_stop_queue() before drop_queue_ref() races with send - [Medium] nvme-tcp: unlocked data race on genctr in nvme_tcp_complete_timed_out() - [Medium] nvme-tcp: nvme_tcp_drop_queue_ref() can self-loop req_list on auth retry - [Medium] nvme-tcp: nvme_tcp_drop_queue_ref() can corrupt req_list into a self-loop - [Medium] nvme-tcp: nvme_tcp_drop_queue_ref() drains req_list without kicking io_work -- commit b2059b42e13e2c0cc53cb55c6db5edeebea6d283 Author: Yehyeong Lee nvme-tcp: do not leave a timed-out request reachable from its queue This commit updates nvme_tcp_complete_timed_out() to retire the command ID, stop the queue, cancel io_work, unlink the request from the queue's send state under send_mutex, and reset any matching receive context before completing the request under lock_sock(). > diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c > index 62a594b8ab9bf..b89d763372b5c 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -3031,13 +3031,59 @@ static void nvme_tcp_submit_async_event(struct nv= me_ctrl *arg) > nvme_tcp_queue_request(&ctrl->async_req, true); > } > =20 > +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); [Severity: Medium] Can init_llist_node(&req->lentry) here turn queue->req_list into a self-loop if a retryable in-band authentication command is re-queued concurrently? On a queue that has not yet set NVME_TCP_Q_LIVE, nvme_tcp_stop_queue() leav= es the socket open and its callbacks armed. If a re-armed io_work fails sendi= ng an auth command (submitted with NVME_SUBMIT_RETRY in nvme_auth_submit()), nvme_retry_req() re-dispatches the same request onto queue->req_list locklessly without waiting for blk_mq_timeout_work(): CPU0 CPU1 nvme_tcp_drop_queue_ref() mutex_lock(&queue->send_mutex) nvme_tcp_process_req_list(queue) blk_mq_requeue_work() nvme_tcp_queue_rq() nvme_tcp_queue_request() llist_add(&req->lentry, &queue->req_list) init_llist_node(&req->lentry) <-- self-loop in queue->req_list The next nvme_tcp_process_req_list() then spins forever holding queue->send_mutex while repeatedly adding req->entry to queue->send_list. = If llist_add() instead runs right after nvme_tcp_drop_queue_ref() returns, nvmf_complete_timed_out_request() can complete the retried request while it= is still on queue->req_list. [Severity: Medium] Can the same init_llist_node(&req->lentry) also race with nvme_tcp_handle_r2t() and corrupt queue->req_list into a self-loop? Because nvme_tcp_drop_queue_ref() runs without lock_sock(sk) and non-LIVE sockets keep sk_data_ready armed, a concurrent nvme_tcp_io_work() that fails mutex_trylock(&queue->send_mutex) proceeds directly into nvme_tcp_try_recv(= ): CPU0 CPU1 nvme_tcp_drop_queue_ref() mutex_lock(&queue->send_mutex) nvme_tcp_process_req_list(queue) nvme_tcp_io_work() mutex_trylock(&queue->send_mutex) /* fails, continues to recv */ nvme_tcp_try_recv() nvme_tcp_handle_r2t() llist_add(&req->lentry, &queue->req_list) init_llist_node(&req->lentry) <-- self-loop in queue->req_list If a target sends an R2T PDU matching the incremented 4-bit generation counter for a Connect or auth_send request, queue->req_list becomes circular and the next nvme_tcp_process_req_list() hangs holding send_mutex and corrupts queue->send_list. > + > + mutex_unlock(&queue->send_mutex); > +} [Severity: Medium] Can draining queue->req_list in nvme_tcp_drop_queue_ref() without re-queuing io_work strand other requests on queue->send_list? Previously only nvme_tcp_fetch_request() called nvme_tcp_process_req_list() and immediately drove transmission. Here, nvme_tcp_complete_timed_out() cancels io_work and then moves all pending requests from queue->req_list on= to queue->send_list while only unlinking req. Because nvme_tcp_commit_rqs() only checks !llist_empty(&queue->req_list), and a concurrent nvme_tcp_queue_request() can see both lists empty mid-drain, other requests sharing the queue (such as commands submitted after a late Connect completi= on sets NVME_TCP_Q_LIVE) can sit on queue->send_list until they time out. Re-queuing io_work when nvme_tcp_queue_has_pending(queue) is true avoids stranding them. > + > +/* the data and digest paths resolve this id without a generation check = */ > +static void nvme_tcp_drop_recv_ctx(struct nvme_tcp_request *req) > +{ > + struct nvme_tcp_queue *queue =3D req->queue; > + struct nvme_tcp_data_pdu *pdu =3D (void *)queue->pdu; > + > + if (nvme_tcp_recv_state(queue) =3D=3D NVME_TCP_RECV_PDU) > + return; > + > + if (nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id) !=3D > + blk_mq_rq_from_pdu(req)) > + return; > + > + nvme_tcp_init_recv_ctx(queue); > +} [Severity: High] Does resetting the receive state to NVME_TCP_RECV_PDU here desynchronize TCP PDU framing? When nvme_tcp_recv_state(queue) is NVME_TCP_RECV_DATA or NVME_TCP_RECV_DDGS= T, the C2HData header has already been consumed and the next unread bytes on t= he socket are payload or digest bytes. Because neither nvme_tcp_stop_queue() nor nvme_tcp_drop_recv_ctx() clears queue->rd_enabled, subsequent reads on a non-LIVE open socket (or leftover skbs in sk_receive_queue after kernel_sock_shutdown()) feed those payload bytes into nvme_tcp_recv_pdu() as PDU headers. On the transmit side, clearing queue->request =3D NULL in nvme_tcp_drop_queue_ref() on a non-LIVE queue whose socket remains open also abandons a partially sent PDU, corrupting TX framing when a retryable in-ba= nd auth command is retried on the same socket. > + > 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; > + struct sock *sk =3D req->queue->sock->sk; [Severity: High] Can req->queue->sock->sk be NULL or freed before lock_sock(sk) and nvme_tcp_drop_recv_ctx() run? nvme_tcp_complete_timed_out() reads req->queue->sock->sk without queue->queue_lock, without checking NVME_TCP_Q_ALLOCATED or queue->sock, and without taking a reference on sk. It then sleeps in nvme_tcp_stop_queue(), cancel_work_sync(), and mutex_lock(&queue->send_mutex) before calling lock_sock(sk), reading queue->pdu in nvme_tcp_drop_recv_ctx(), and calling release_sock(sk). None of the teardown or error paths (such as nvme_tcp_configure_admin_queue= () on reconnect failure or nvme_tcp_setup_io_queues()) call blk_sync_queue() on ctrl->fabrics_q or ctrl->connect_q before nvme_tcp_free_queue(): CPU0 CPU1 nvme_tcp_complete_timed_out() sk =3D req->queue->sock->sk nvme_tcp_stop_queue() /* command completes concurrently */ nvme_tcp_configure_admin_queue() nvme_tcp_free_admin_queue() nvme_tcp_free_queue() __fput_sync(queue->sock->file) queue->sock =3D NULL kfree(queue->pdu) lock_sock(sk) <-- use-after-free nvme_tcp_drop_recv_ctx() <-- reads freed queue->pdu If nvme_tcp_free_queue() runs before the initial read, req->queue->sock->sk is a NULL pointer dereference; if it runs afterward, lock_sock(sk), release_sock(sk), and queue->pdu in nvme_tcp_drop_recv_ctx() hit use-after-free. > + > + if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) > + nvmf_retire_timed_out_command(rq); [Severity: Medium] Does calling nvmf_retire_timed_out_command(rq) here introduce an unlocked data race on nvme_req(rq)->genctr? nvmf_retire_timed_out_command() performs a plain non-atomic nr->genctr++ while the socket is still live and neither io_work nor lock_sock(sk) has be= en fenced. Meanwhile, nvme_tcp_io_work() or nvme_tcp_poll() (holding only lock_sock(sk)) can concurrently read genctr in nvme_find_rq() and increment it in nvme_try_complete_req(), risking a lost increment or spurious generation mismatch errors. > =20 > nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); [Severity: High] Can calling nvme_tcp_stop_queue() before nvme_tcp_drop_queue_ref() race with an active send and cause double completion or abort a retried request? __nvme_tcp_stop_queue() calls kernel_sock_shutdown(queue->sock, SHUT_RDWR) without send_mutex and nvme_tcp_wait_queue() can sleep up to 100 ms before nvme_tcp_drop_queue_ref() unlinks req. Because nvme_tcp_try_send() does not check genctr, an already-running io_work or inline send hits -EPIPE and completes rq with NVME_SC_HOST_PATH_ERROR: CPU0 CPU1 nvme_tcp_complete_timed_out() nvme_tcp_stop_queue() kernel_sock_shutdown(..., SHUT_RDWR) nvme_tcp_try_send() /* sock_sendmsg() returns -EPIPE */ nvme_tcp_fail_request(req) blk_mq_end_request(rq) /* rq->state =3D MQ_RQ_COMPLETE= */ ... nvmf_complete_timed_out_request() blk_mq_request_started(rq) /* sees MQ_RQ_COMPLETE */ blk_mq_free_request(rq) /* rq->state =3D MQ_RQ_IDLE */ !blk_mq_request_completed(rq) /* sees MQ_RQ_IDLE */ blk_mq_complete_request(rq) <-- double completion Because nvmf_complete_timed_out_request() reads rq->state twice, the transition from MQ_RQ_COMPLETE to MQ_RQ_IDLE lets both checks pass and triggers a second completion. For a retryable request (such as non-multipa= th I/O or an auth command), blk_mq_requeue_work() can also re-dispatch rq back to MQ_RQ_IN_FLIGHT during nvme_tcp_wait_queue(), causing nvme_tcp_drop_queue_ref() and nvmf_complete_timed_out_request() to strip and abort the newly retried request. > + > + cancel_work_sync(&req->queue->io_work); > + nvme_tcp_drop_queue_ref(req); > + > + /* the receive path holds this across read_sock() */ > + lock_sock(sk); > + nvme_tcp_drop_recv_ctx(req); > nvmf_complete_timed_out_request(rq); > + release_sock(sk); > } [Severity: High] Can nvme_tcp_poll() re-add req to queue->req_list after nvme_tcp_drop_queue_ref() returns and cause a use-after-free on its bio? On a poll queue, nvme_tcp_poll() checks NVME_TCP_Q_LIVE locklessly and calls nvme_tcp_try_recv() directly under lock_sock(sk) outside queue->io_work. Because cancel_work_sync(&req->queue->io_work) does not wait for nvme_tcp_poll() and nvme_tcp_drop_queue_ref() runs before lock_sock(sk), a polling thread processing a buffered R2T PDU can re-queue req right after send references were dropped: CPU0 CPU1 nvme_tcp_poll() /* passes NVME_TCP_Q_LIVE check */ nvme_tcp_try_recv() lock_sock(sk) nvme_tcp_handle_r2t() nvme_find_rq() /* resolves rq */ nvme_tcp_complete_timed_out() nvmf_retire_timed_out_command(rq) nvme_tcp_stop_queue() cancel_work_sync(&queue->io_work) nvme_tcp_drop_queue_ref(req) lock_sock(sk) /* blocks */ llist_add(&req->lentry, &queue->req_list) queue_work_on(..., &io_work) release_sock(sk) /* acquires lock_sock(sk) */ nvmf_complete_timed_out_request(rq) /* frees rq->bio */ release_sock(sk) nvme_tcp_io_work() nvme_tcp_try_send_data() <-- use-after-free Retiring the command ID and dropping the receive context under lock_sock(sk) before calling nvme_tcp_drop_queue_ref() would fence nvme_tcp_poll(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204135345.2994= 739-1-yhlee@isslab.korea.ac.kr?part=3D2