[PATCH 6.1.y] nvme-tcp: sanitize request list handling
Dickson Wu via B4 Relay
devnull+dickson.wu.certik.com at kernel.org
Sat Nov 28 06:17:55 PST 2026
From: Hannes Reinecke <hare at 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 at kernel.org>
Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
Signed-off-by: Christoph Hellwig <hch at lst.de>
[ adapted to 6.1.y: open-code absent llist node helpers ]
Signed-off-by: Dickson Wu <dickson.wu at 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 at certik.com>
More information about the Linux-nvme
mailing list