From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4111143C7C2 for ; Fri, 21 Aug 2026 09:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787304623; cv=none; b=WHIAnCkZmDBxPlun0/vaukyhdmbBdLs59XF3f9BVhMj2FV0AmW9VHQ9X124MN8Qg2DVFmxBjg5iL9SpgTeGSuRCZnnAWmjeOic05YhN8LA2p8jYrfCqzZT8XCNB5NqWIlXLS8Mf5bypeViWjn93EOIwHXj7Ql5EHT5nD0U93Y7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787304623; c=relaxed/simple; bh=V1bezpXWYftDZ8btyC/pzVb5oYR+BWYibSX+kKpkbq0=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=PdruN8Jgwxg0C//F7lXTwse9hr91pVP1cB6LeQAjxk7zkyltC5gsIiUSKJnOA4HtkgG6CzXEQOrirO8vAXOMtUJhN/ms3RryPIgBS4NQMkkM3XHpRJRtpJdweY3WPlykxDp/R+y5eQv1Blb3HXHku/YlbPnBqozqBg2i7UgY7Wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=vi0OCFxA; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="vi0OCFxA" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1787304612; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; bh=HZnYtRurIbr7fGwafUtO6fhUxr1c5+/a2CN0wLnLomU=; b=vi0OCFxA5hU09PbZmhke6cv7716b73jFMJm5FP8sU2curYgXwtId+l0QbipT861IHhE+4UMa5VXQFgYSLhyOpnKctSI3qeJ9PGVyycrtfSi3L/CeJFpan2AZo0J7vJHvNZzBDVJp4W0AuDIfGw2REeijmiZ9Kxuipl40KZBctUY= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R901e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=chuyf26@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0X9LqlpK_1787304610; Received: from x31j07255.sqa.na131(mailfrom:Chuyf26@linux.alibaba.com fp:SMTPD_---0X9LqlpK_1787304610 cluster:ay36) by smtp.aliyun-inc.com; Fri, 21 Aug 2026 17:30:11 +0800 From: Chuyf26 To: kbusch@kernel.org Cc: axboe@kernel.dk, hch@lst.de, sagi@grimberg.me, roys@lightbitslabs.com, sashas@lightbitslabs.com, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-tcp: reject C2HData for a non-read command Date: Fri, 21 Aug 2026 17:28:32 +0800 Message-ID: <178730451245.442148.11684394617763960186@linux.alibaba.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A malicious or buggy controller can send C2HData PDUs in response to a WRITE command. nvme_tcp_handle_c2h_data() accepts them as long as the request has payload bytes and a current bio, which is true for writes, so the receive path ends up copying the incoming data into the request's iterator. That iterator was initialized from rq_data_dir(rq) in nvme_tcp_init_iter(), i.e. ITER_SOURCE for a write, and _copy_to_iter() refuses to copy into a source iterator: it triggers its WARN_ON_ONCE() and returns 0, the short copy fails with -EFAULT, and the connection is torn down into error recovery. The write never completes: every reconnect reissues it and a malicious target answers with C2HData again, keeping the controller in a permanent reset/reconnect loop. With panic_on_warn this is an outright crash. C2HData carries data transferred from the controller to the host and is only valid for commands that read data from the device; write data travels host to controller in H2CData PDUs solicited by R2T. This was reproduced against a target modified to reply to a WRITE with C2HData: the host logs WARNING: CPU: 0 PID: ... at lib/iov_iter.c _copy_to_iter Workqueue: nvme_tcp_wq nvme_tcp_io_work [nvme_tcp] and the controller cycles through reset/reconnect without the write ever completing. Reject C2HData for any non-read command. This is the symmetric case of commit 6efbc52237fa ("nvme-tcp: fix host memory disclosure on R2T for a read command"), which added the mirror-image direction check to nvme_tcp_handle_r2t(). Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver") Cc: stable@vger.kernel.org Reported-by: Abaci Assisted-by: abaci:qwen3.8-max Signed-off-by: Chuyf26 --- drivers/nvme/host/tcp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -685,6 +685,13 @@ } req = blk_mq_rq_to_pdu(rq); + if (unlikely(rq_data_dir(rq) != READ)) { + dev_err(queue->ctrl->ctrl.device, + "req %d unexpected c2hdata for a non-read command\n", + rq->tag); + return -EPROTO; + } + if (!blk_rq_payload_bytes(rq) || !req->curr_bio || !req->data_len) { dev_err(queue->ctrl->ctrl.device, "queue %d tag %#x unexpected data\n", -- 2.43.5