[PATCH v2 1/2] nvme-tcp: avoid overflow in the R2T length check
Zhenwen Liang
zhenwenliang at google.com
Mon Nov 23 21:10:40 PST 2026
nvme_tcp_handle_r2t() checks the R2T length with
if (unlikely(req->data_sent + r2t_length > req->data_len))
data_sent is a size_t, which is 32 bits wide on 32-bit architectures,
and r2t_length comes from the controller. A large r2t_length can make
the sum wrap around and pass the check. Compare against the remaining
length instead; data_sent never exceeds data_len, so the subtraction
cannot underflow.
The same check was already in the original driver (on pdu_len, then
filled from the R2T); commit 1d3ef9c3a39e ("nvme-tcp: validate R2T PDU
in nvme_tcp_handle_r2t()") moved it to r2t_length.
Reported by the Sashiko review bot on v1 of "nvme-tcp: set up R2T data
transfer in the send path". The patch and this description were
written with AI assistance and reviewed by a human. Build-tested only
(32-bit not tested).
Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver")
Cc: stable at vger.kernel.org
Signed-off-by: Zhenwen Liang <zhenwenliang at google.com>
---
drivers/nvme/host/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 62a594b8ab9b..4fa4b0199dee 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -847,7 +847,7 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue,
return -EPROTO;
}
- if (unlikely(req->data_sent + r2t_length > req->data_len)) {
+ if (unlikely(r2t_length > req->data_len - req->data_sent)) {
dev_err(queue->ctrl->ctrl.device,
"req %d r2t len %u exceeded data len %u (%zu sent)\n",
rq->tag, r2t_length, req->data_len, req->data_sent);
--
2.56.1.809.ga0b61035b5-goog
More information about the Linux-nvme
mailing list