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 C91FB606A323 for ; Sun, 29 Nov 2026 03:46:18 +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=DiEyHIdp; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JomGSGvH 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=fb+SvNk76Ov7V8SPevZLM8g4lTRAFyNCO4CSrPYQFbA=; b=DiEyHIdpz53QnESZNQcQ2ItRdv TpNRyIlwYOpDWUSNlzNhazVvtr/hXdRwZPl7CjZmYsi1yaUnVyhBYiM6vaZi1KBFXay1HBfk8EgIQ GkLEB0CpEr68e4wgwNb9yFI2DUJg/MMNIugQPmg3s5GoQ/ocq0OoYAP99wZlesxvwkbczyLrPUc5+ RwQrght5JFnXCN4QlxtjzX6v7vMoQx7Za5zbiKsv5pwSIKHLhKYpsFGjVuhdL6kNs5DcuxWyVU7p6 3/YrqS6KE1rPUNyX8rKfQ1Y0K016nYesydrCt3u1+6BeTiO1A4eQtHXHDn2LcoB00kA6gUCH6mueD AAu4VTow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXVrl-00000001YJe-0QCv; Sun, 29 Nov 2026 03:46:17 +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 1xXVri-00000001YJY-3tYd for linux-nvme@lists.infradead.org; Sun, 29 Nov 2026 03:46:15 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 0E11A602A8; Sun, 29 Nov 2026 03:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41DF1F000C1; Sun, 29 Nov 2026 03:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795923973; bh=fb+SvNk76Ov7V8SPevZLM8g4lTRAFyNCO4CSrPYQFbA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JomGSGvHTphB3CcL8T/kfpVvSeHdLlblT7z3ncLo2/J6g61uCbbmhAegpvbwPx5s2 TxdFV51qZoaIyYZU0FZXzguM3ve4gG6+aWsuyHsA9DZdXx04Aoc/O34lGxBEA6wyxB uzUKzxXcI/RJ+MaUi0yOfoeNoaf+gTKjq1Mv/jkKTwHSpPx58dI3rZM3zh72eoe3mD 8O5uk8Qn/+5GJuFv90ULp7mTvn+otondj8s9tSKLUL57dl/XbdAXpBaDWZ65TwHB2Q uvpPXmSw2Vr0As7nvBTJMuu8KPupd5MYEAwpfTgBONeWJMgwY7Fj0L+HXelq+hcGjz k2ZV7qL1rYFCQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] nvme-tcp: drop the queue's reference to a timed-out request To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261129031537.1993449-1-yhlee@isslab.korea.ac.kr> References: <20261129031537.1993449-1-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 03:46:13 +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: residual recv state and genctr in nvme_tcp_complete_timed_out() - [High] nvme-tcp: race in nvme_tcp_complete_timed_out() before dropping queue ref -- commit 3e4a03d71fdd623bf2fb0e79370c509e4168fd7a 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) 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..ca3a63d260ed8 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -3031,12 +3031,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); > +} [Severity: High] Can the receive path still reference the completed request when io_work is re-armed on the stopped queue? Neither __nvme_tcp_stop_queue() nor nvme_tcp_drop_queue_ref() clears queue->rd_enabled or resets the receive context with nvme_tcp_init_recv_ctx(), and kernel_sock_shutdown(queue->sock, SHUT_RDWR) leaves already-queued packets in sk->sk_receive_queue. When a new request is later dispatched to the stopped queue and re-arms io_work, nvme_tcp_io_work() reaches nvme_tcp_try_recv(): - If the timed-out command was a read in NVME_TCP_RECV_DATA or NVME_TCP_RECV_DDGST, nvme_tcp_recv_data() looks up rq directly via nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id), copies payload into req->iter / req->curr_bio (writing to the freed bio's pages), and completes rq a second time on NVME_TCP_F_DATA_SUCCESS. - If the queue is in NVME_TCP_RECV_PDU, nvmf_complete_timed_out_request() does not increment nvme_req(rq)->genctr, so nvme_find_rq() still matches a buffered nvme_tcp_rsp or nvme_tcp_r2t for rq's command_id. nvme_tcp_process_nvme_cqe() then completes rq a second time, or nvme_tcp_handle_r2t() sees the reinitialized req->lentry and req->entry and queues the completed req back onto queue->req_list. > + > 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 requeue rq while nvme_tcp_stop_queue() is shutting down the socket, allowing rq to be re-dispatched onto queue->req_list before nvmf_complete_timed_out_request() completes it? timeout work kworker nvme_tcp_complete_timed_out(rq) nvme_tcp_stop_queue() __nvme_tcp_stop_queue() kernel_sock_shutdown() nvme_tcp_io_work() nvme_tcp_try_send() sock_sendmsg() -> -EPIPE nvme_tcp_fail_request(req) ... nvme_retry_req(rq) blk_mq_requeue_request() cancel_work_sync() nvme_tcp_wait_queue() nvme_tcp_drop_queue_ref(req) blk_mq_requeue_work() ... nvme_tcp_queue_rq(rq) nvme_start_request(rq) nvme_tcp_queue_request(req) nvmf_complete_timed_out_request(rq) blk_mq_complete_request(rq) <-- req still on queue->req_list When sock_sendmsg() fails on the shut-down socket, nvme_tcp_fail_request() completes rq with NVME_SC_HOST_PATH_ERROR. For retryable commands that do not use multipath (such as fabrics auth commands during NVME_CTRL_CONNECTING, or I/O when multipath is disabled), __nvme_complete_rq() calls nvme_retry_req(), which resets rq->state to MQ_RQ_IDLE and clears RQF_TIMED_OUT. Once nvme_tcp_queue_rq() re-dispatches rq, rq->state is MQ_RQ_IN_FLIGHT again, so nvmf_complete_timed_out_request() completes rq and frees its bio while req is back on queue->req_list with io_work armed, causing the same use-after-free in nvme_tcp_try_send_data() and double completion. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129031537.1993= 449-1-yhlee@isslab.korea.ac.kr?part=3D1