Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs
       [not found] <2026082755-stucco-champion-2bb9@gregkh>
@ 2026-08-27 19:24 ` Shivam Kumar
  2026-08-27 21:51   ` Keith Busch
  2026-08-30 21:15   ` Sagi Grimberg
  0 siblings, 2 replies; 3+ messages in thread
From: Shivam Kumar @ 2026-08-27 19:24 UTC (permalink / raw)
  To: Greg KH; +Cc: security, hch, sagi, kch, linux-nvme, kumar.shivam43666, stable

nvmet_tcp_handle_h2c_data_pdu() accepts an H2CData PDU after only checking
that its TTAG is a valid in-range command index and that the command's
data buffers are mapped. It never checks that the target has actually
solicited that data by sending an R2T for the command.

A remote host can abuse this. It submits a write command that takes the
R2T path and, before the target transmits the R2T, sends an H2CData PDU
for that command's tag. The data completes the command early, and when
the command then fails synchronously (e.g. a length mismatch caught by
nvmet_check_transfer_len()), it is completed a second time. Each
completion calls nvmet_tcp_queue_response(), so the same command is added
to queue->resp_list twice while it is still linked; the second llist_add()
makes the node point to itself (lentry->next == lentry).

nvmet_tcp_process_resp_list() then walks that self-referential node and
adds the command to resp_send_list twice. With CONFIG_DEBUG_LIST this
trips the "list_add double add" check (kernel BUG); without it the loop
never terminates and the nvmet_tcp workqueue wedges (soft-lockup). It is
remotely triggerable and needs no authentication on an allow_any_host
subsystem.

Track whether an R2T has been transmitted for a command and reject an
H2CData PDU that arrives before it. The flag is cleared on command reuse
(nvmet_tcp_get_cmd() zeroes cmd->flags) and stays set across the multiple
H2CData PDUs of a single solicited transfer.

Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Cc: stable@vger.kernel.org
Signed-off-by: Shivam Kumar <kumar.shivam43666@gmail.com>
---
 drivers/nvme/target/tcp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index e4f603b2ace7..328b075300a6 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -103,6 +103,7 @@ enum nvmet_tcp_recv_state {
 
 enum {
 	NVMET_TCP_F_INIT_FAILED = (1 << 0),
+	NVMET_TCP_F_R2T_SENT	= (1 << 1),
 };
 
 struct nvmet_tcp_cmd {
@@ -776,6 +777,7 @@ static int nvmet_try_send_r2t(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
 		return -EAGAIN;
 
 	cmd->queue->snd_cmd = NULL;
+	cmd->flags |= NVMET_TCP_F_R2T_SENT;
 	return 1;
 }
 
@@ -1009,6 +1011,12 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
 		cmd = &queue->connect;
 	}
 
+	if (unlikely(!(cmd->flags & NVMET_TCP_F_R2T_SENT))) {
+		pr_err("queue %d: unsolicited H2CData (ttag %u)\n",
+		       queue->idx, data->ttag);
+		goto err_proto;
+	}
+
 	if (le32_to_cpu(data->data_offset) != cmd->rbytes_done) {
 		pr_err("ttag %u unexpected data offset %u (expected %u)\n",
 			data->ttag, le32_to_cpu(data->data_offset),
-- 
2.53.0



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

* Re: [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs
  2026-08-27 19:24 ` [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs Shivam Kumar
@ 2026-08-27 21:51   ` Keith Busch
  2026-08-30 21:15   ` Sagi Grimberg
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-08-27 21:51 UTC (permalink / raw)
  To: Shivam Kumar; +Cc: Greg KH, security, hch, sagi, kch, linux-nvme, stable

On Thu, Aug 27, 2026 at 03:24:55PM -0400, Shivam Kumar wrote:
> nvmet_tcp_handle_h2c_data_pdu() accepts an H2CData PDU after only checking
> that its TTAG is a valid in-range command index and that the command's
> data buffers are mapped. It never checks that the target has actually
> solicited that data by sending an R2T for the command.

Thanks, looks correct. Applied to nvme-7.3.


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

* Re: [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs
  2026-08-27 19:24 ` [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs Shivam Kumar
  2026-08-27 21:51   ` Keith Busch
@ 2026-08-30 21:15   ` Sagi Grimberg
  1 sibling, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2026-08-30 21:15 UTC (permalink / raw)
  To: Shivam Kumar, Greg KH; +Cc: security, hch, kch, linux-nvme, stable

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


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

end of thread, other threads:[~2026-08-30 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2026082755-stucco-champion-2bb9@gregkh>
2026-08-27 19:24 ` [PATCH] nvmet-tcp: reject unsolicited H2CData PDUs Shivam Kumar
2026-08-27 21:51   ` Keith Busch
2026-08-30 21:15   ` Sagi Grimberg

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