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 A21D5606A320 for ; Mon, 30 Nov 2026 11:17:48 +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=Jum8cxUf; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CeGOH19b 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=z5axWYiSAn2S3zPtdv5CySawwQiSL/qyCzYve4nBips=; b=Jum8cxUf+j97Xr2c2/orl/7C+R SDqhBcr0Yd/hnQn+8pubTZsB/9oUyMGxjwAKVPOHB16BsEmrhuwOGp0piQKQuEev2VeWxMIns8DtO SZ7n5vAR2R4CTyCCNwK7lz4OZEXPY1JssQh6fQhGuwZjh4F3Ke1ostgj8I14XiQHSYWRxEk/zUf4h ylwjz9iFnM4O8g4R9sZ/PqM/fwWBdMF5/ZRNqk8Dt0Mp5BKW5uaV/eO3sSL0db3QBomv9CpCgVUoZ TC17qC6k5BgH9zHKdZOo7gnteMhVaMbLcWXEXk4upTvyZXnaKOBY10Yd0maF3OpLONo4oa71/fFX9 i5DueKbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXzOD-00000004ISK-2ef8; Mon, 30 Nov 2026 11:17:45 +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 1xXzOC-00000004IRr-0lfF for linux-nvme@lists.infradead.org; Mon, 30 Nov 2026 11:17:44 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8D29560F7C; Mon, 30 Nov 2026 11:17:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B31C21F000C1; Mon, 30 Nov 2026 11:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796037462; bh=z5axWYiSAn2S3zPtdv5CySawwQiSL/qyCzYve4nBips=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CeGOH19b/Xq0i0Rbo9NRh2oEehAu7aubepJmTrfK9ZNgMkI58Fc8Nkk1xH3SSye99 pqNdYICnurQHHKFcrmTgA7gGPMVDYorqDATou39g4bjn9LAHL4xnhUJIDLfZb/+X+u j1d+fjWOB7GkFUA4tTYnFtjiHyaP3DLSsjamFVUOf76Fz51XKex1BvIQ8Bu+8Fm82C bhsfwMuAV6LIn/pzHEcz0CU70zL8Pc7Gm1Ug0lOIw7n9BhzZf/cDTt2ly6jZ3oD/1G xpifdrXxiCtMsOFJ2QkuZzTcwpVA7E3PnsT9VZJe4d33OQmp4vjBPC4aBiCWM9vEl4 aZLanpLAj7drg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] nvme-tcp: do not refer to a timed-out request after completing it To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261130104426.2140231-1-yhlee@isslab.korea.ac.kr> References: <20261129031537.1993449-1-yhlee@isslab.korea.ac.kr> <20261130104426.2140231-1-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 11:17:42 +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: missing queue stop in nvme_tcp_stop_queue_nowait() before LIVE - [High] nvme-tcp: race in nvme_tcp_complete_timed_out() before dropping queue ref -- commit 525e6d2baaccfcee477c6959e45a7456d4788b99 Author: Yehyeong Lee nvme-tcp: do not refer to a timed-out request after completing it This commit clears queue->rd_enabled when stopping a queue and drops the queue's send references to a timed-out request in nvme_tcp_complete_timed_out() before completing it. > diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c > index 62a594b8ab9bf..e0a2fa1d8d355 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -2303,6 +2303,21 @@ static void nvme_tcp_stop_queue_nowait(struct nvme= _ctrl *nctrl, int qid) > } > =20 > mutex_lock(&queue->queue_lock); > + > + /* > + * Stop receiving, whether or not this queue got as far as LIVE. > + * SHUT_RD below does not discard what the socket has already > + * received, and the receive path nvme-tcp uses - read_sock() - > + * does not look at the shutdown state, so residual bytes stay > + * readable; rd_enabled is what keeps nvme_tcp_recv_skb() from > + * consuming them. Clearing it here, before anything else, means > + * neither an io_work that is running now nor one armed after the > + * cancel_work_sync() below can resolve a command id on a queue > + * that is being stopped. nvme_tcp_start_queue() sets it again, > + * next to the receive context, on the next connect. > + */ > + queue->rd_enabled =3D false; > + > if (test_and_clear_bit(NVME_TCP_Q_LIVE, &queue->flags)) > __nvme_tcp_stop_queue(queue); > /* Stopping the queue will disable TLS */ [Severity: High] Does clearing queue->rd_enabled without calling __nvme_tcp_stop_queue() leave io_work running and queue->sock open when a command times out before NVME_TCP_Q_LIVE is set? nvme_tcp_start_queue() enables rd_enabled, installs socket callbacks, and runs nvmf_connect_admin_queue() or nvmf_connect_io_queue() (including in-band authentication) before setting NVME_TCP_Q_LIVE. If a Connect or auth command times out there, test_and_clear_bit(NVME_TCP_Q_LIVE, ...) is false, so __nvme_tcp_stop_queue() is skipped until connect returns. Because nvme_tcp_recv_skb() checks queue->rd_enabled only once at entry before its while (len) loop, an already running receive or zero-copy send in io_work is not fenced by cancel_work_sync(): CPU0 (timeout) CPU1 (io_work) nvme_tcp_Start_queue() nvmf_connect_admin_queue() ... nvme_tcp_complete_timed_out(rq) nvme_tcp_recv_skb() if (!queue->rd_enabled) while (len) { nvme_tcp_stop_queue() queue->rd_enabled =3D false; /* NVME_TCP_Q_LIVE not set, * __nvme_tcp_stop_queue() * skipped */ nvme_tcp_drop_queue_ref(req) nvmf_complete_timed_out_request(rq) /* rq completed, buffer freed */ nvme_tcp_recv_pdu() / nvme_tcp_recv_data() <-- double completion or use-after-free In addition, nvme_auth_submit() submits auth commands with NVME_SUBMIT_RETRY, so completing a timed-out auth request with NVME_SC_HOST_ABORTED_CMD retries it onto the still-open socket after nvme_tcp_stop_queue_nowait() has cleared queue->rd_enabled and queue->tls_enabled. That bypasses the !nvme_tcp_queue_tls(queue) guard in nvme_tcp_queue_request() (risking inline kTLS send under blk-mq set->srcu) and drops the reply because rd_enabled is false, hanging each retry for the full command timeout. > @@ -3031,12 +3046,46 @@ static void nvme_tcp_submit_async_event(struct nv= me_ctrl *arg) > nvme_tcp_queue_request(&ctrl->async_req, true); > } > =20 > +/* > + * The timeout handler below completes the request itself, which ends it= and > + * frees its bio. The queue the request was being sent on can still hol= d a > + * reference to it: as queue->request if a send was in progress, or link= ed on > + * the queue's send_list or req_list if it was waiting its turn. Stoppi= ng the > + * queue cancels io_work but drops none of those references, and nothing= else > + * drops them either - only the send path does, and that is what was jus= t shut > + * down. If the queue is handed work again the send path picks the requ= est up > + * and walks the bio this completion is about to free. > + * > + * Drop the queue's references to the request before completing it. > + */ > +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; > + > + /* > + * req_list is a lockless list, so a single entry cannot be removed > + * from it; splice it onto send_list first, as the send path does. > + */ > + 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); > +} > + > 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 between kernel_sock_shutdown() in nvme_tcp_stop_queue() and nvme_tcp_drop_queue_ref(req)? __nvme_tcp_stop_queue() calls kernel_sock_shutdown(queue->sock, SHUT_RDWR) before cancel_work_sync(&queue->io_work) and without holding queue->send_mutex, and nvme_tcp_wait_queue() then sleeps for up to 100ms before nvme_tcp_drop_queue_ref() is reached. If io_work or a direct send from nvme_tcp_queue_request() runs during that window while req is still on the queue, sock_sendmsg() returns -EPIPE and nvme_tcp_fail_request() completes rq with NVME_SC_HOST_PATH_ERROR: CPU0 (timeout) CPU1 (io_work / direct send) nvme_tcp_complete_timed_out(rq) nvme_tcp_stop_queue() kernel_sock_shutdown() nvme_tcp_try_send() sock_sendmsg() -> -EPIPE nvme_tcp_fail_request(req) nvme_try_complete_req(rq) cancel_work_sync() nvme_tcp_wait_queue() nvme_tcp_drop_queue_ref(req) /* softirq or sync waiter frees * or requeues rq -> MQ_RQ_IDLE */ nvmf_complete_timed_out_request(rq) blk_mq_request_started(rq) /* sees MQ_RQ_COMPLETE */ !blk_mq_request_completed(rq) /* sees MQ_RQ_IDLE */ blk_mq_complete_request(rq) <-- double completion If the request is retryable, nvme_complete_rq() can also requeue and re-dispatch rq during nvme_tcp_wait_queue() (setting rq->state back to MQ_RQ_IN_FLIGHT), causing nvmf_complete_timed_out_request(rq) to abort the newly restarted request. Dropping the queue reference under send_mutex before shutting down the socket, or preventing nvme_tcp_try_send() from failing requests once the queue is stopping, would close this window. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130104426.2140= 231-1-yhlee@isslab.korea.ac.kr?part=3D1