From: Zhenwen Liang <zhenwenliang@google.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Cc: Shao Mingyin <shao.mingyin@zte.com.cn>,
linux-nvme@lists.infradead.org, stable@vger.kernel.org
Subject: [PATCH v2 1/2] nvme-tcp: avoid overflow in the R2T length check
Date: Tue, 24 Nov 2026 05:10:40 +0000 [thread overview]
Message-ID: <20261124051041.3099796-2-zhenwenliang@google.com> (raw)
In-Reply-To: <20261124051041.3099796-1-zhenwenliang@google.com>
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@vger.kernel.org
Signed-off-by: Zhenwen Liang <zhenwenliang@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
next prev parent reply other threads:[~2026-11-24 5:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 5:10 [PATCH v2 0/2] nvme-tcp: fix the R2T send/receive race Zhenwen Liang
2026-11-24 5:10 ` Zhenwen Liang [this message]
2026-11-24 5:10 ` [PATCH v2 2/2] nvme-tcp: set up R2T data transfer in the send path Zhenwen Liang
2026-11-24 5:35 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124051041.3099796-2-zhenwenliang@google.com \
--to=zhenwenliang@google.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=shao.mingyin@zte.com.cn \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox