Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 6.1.y] nvme-tcp: sanitize request list handling
@ 2026-11-28 14:17 Dickson Wu via B4 Relay
  2026-11-29 18:59 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-28 14:17 UTC (permalink / raw)
  To: stable
  Cc: Hannes Reinecke, Sagi Grimberg, Christoph Hellwig, Keith Busch,
	Jens Axboe, linux-nvme

From: Hannes Reinecke <hare@kernel.org>

commit 0bf04c874fcb1ae46a863034296e4b33d8fbd66c upstream.

Validate the request in nvme_tcp_handle_r2t() to ensure it's not part of
any list, otherwise a malicious R2T PDU might inject a loop in request
list processing.

Signed-off-by: Hannes Reinecke <hare@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
[ adapted to 6.1.y: open-code absent llist node helpers ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
This one went into 6.6.y and 6.12.y but never made it to 6.1.y,
since 6.1 doesn't have init_llist_node() or llist_on_list(). The
backport open-codes them as node->next = node and node->next != node,
which is all the helpers do, at the same four sites as upstream.

Tested on 6.1.193: W=1 build of drivers/nvme/host/tcp.o, base vs
patched, no new warnings. Both kernels booted under KVM with nvme-tcp
built in. Build and boot only - I didn't send a malicious R2T, so the
new check itself wasn't exercised.

The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
 drivers/nvme/host/tcp.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index d434c24e035d..b9abd25d9bff 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -386,7 +386,8 @@ nvme_tcp_fetch_request(struct nvme_tcp_queue *queue)
 			return NULL;
 	}
 
-	list_del(&req->entry);
+	list_del_init(&req->entry);
+	req->lentry.next = &req->lentry;
 	return req;
 }
 
@@ -494,6 +495,8 @@ static int nvme_tcp_init_request(struct blk_mq_tag_set *set,
 	req->queue = queue;
 	nvme_req(rq)->ctrl = &ctrl->ctrl;
 	nvme_req(rq)->cmd = &pdu->cmd;
+	req->lentry.next = &req->lentry;
+	INIT_LIST_HEAD(&req->entry);
 
 	return 0;
 }
@@ -740,6 +743,14 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue,
 		return -EPROTO;
 	}
 
+	if (req->lentry.next != &req->lentry ||
+	    !list_empty(&req->entry)) {
+		dev_err(queue->ctrl->ctrl.device,
+			"req %d unexpected r2t while processing request\n",
+			rq->tag);
+		return -EPROTO;
+	}
+
 	req->pdu_len = 0;
 	req->h2cdata_left = r2t_length;
 	req->h2cdata_offset = r2t_offset;
@@ -2376,6 +2387,8 @@ static void nvme_tcp_submit_async_event(struct nvme_ctrl *arg)
 	ctrl->async_req.offset = 0;
 	ctrl->async_req.curr_bio = NULL;
 	ctrl->async_req.data_len = 0;
+	ctrl->async_req.lentry.next = &ctrl->async_req.lentry;
+	INIT_LIST_HEAD(&ctrl->async_req.entry);
 
 	nvme_tcp_queue_request(&ctrl->async_req, true, true);
 }

---
base-commit: 1ca1436ccc68275d0b43b6a730b3940fcc46b7c2
change-id: 20261128-nvme-r2t-61-c6ddfd5327c3

Best regards,
--  
Dickson Wu <dickson.wu@certik.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 14:17 [PATCH 6.1.y] nvme-tcp: sanitize request list handling Dickson Wu via B4 Relay
2026-11-29 18:59 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox