Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] scsi: target: iscsi: reject Text data on a continuation request
@ 2026-12-03 14:02 James Sawyer via B4 Relay
  2026-12-03 14:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Sawyer via B4 Relay @ 2026-12-03 14:02 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: linux-scsi, target-devel, linux-kernel, security, James Sawyer

From: James Sawyer <james@jamessawyer.co.uk>

A Text Request with TTT != 0xFFFFFFFF continues an earlier multi-PDU
SendTargets response. iscsit_find_cmd_from_itt() looks the command up by
ITT on conn->conn_cmd_list, so it returns a command that is already
linked there. Such a continuation is only valid when it is empty. If it
carries a "SendTargets=" payload, iscsit_process_text_cmd() runs a new
request on the reused command and calls list_add_tail(&cmd->i_conn_node,
&conn->conn_cmd_list) on it a second time.

A Text command stays on conn_cmd_list until the initiator's ExpStatSN
acknowledges it, so the initiator controls whether it is still listed,
and discovery sessions accept Text Requests without authentication by
default (iscsit_load_discovery_tpg()).

With another command after it (H -> X -> Y), re-adding X passes the
CONFIG_LIST_HARDENED checks and leaves H->next == X, X->next == H,
X->prev == Y. When X is later acknowledged and freed, list_del_init(X)
also passes the checks and H->next still points to the freed command,
so the next walk of conn_cmd_list uses freed memory. If X is the tail,
hardened kernels warn and skip the add; others create a self-loop.

Reject a data-carrying continuation in iscsit_setup_text_cmd(), before
the looked-up command is mutated, next to the existing Text rejects and
using the same mechanism. This covers iscsi_target, isert and cxgbit,
which all call iscsit_setup_text_cmd() before iscsit_process_text_cmd().

Found by source review only; no reproducer was built. Compile-tested
only (W=1, drivers/target/iscsi/iscsi_target.o, v7.4-rc1, no warnings);
no iSCSI traffic was run.

This issue was found and the fix written with AI assistance.

Fixes: e4f4e8016e68 ("iscsi/iser-target: Support multi-sequence sendtargets text response")
Signed-off-by: James Sawyer <james@jamessawyer.co.uk>
---
Notes for reviewers (not for the commit):
- Found by source review with AI assistance; not reproduced, compile-tested only.
- The looked-up command for a TTT != 0xFFFFFFFF continuation may still be
  in flight on the TX thread and may even be a non-Text command (the ITT
  lookup has no type check). This patch rejects before iscsit_setup_text_cmd()
  mutates it, via the existing iscsit_reject_cmd() path already used for the
  other Text rejects. The broader question of whether that reject path is
  itself safe on an in-flight or non-Text command is pre-existing and not
  addressed here; happy to follow up if you want it handled.

Changes in v3:
- v2 rejected the continuation in iscsit_process_text_cmd(), AFTER
  iscsit_setup_text_cmd() had already mutated the looked-up command and
  freed its text_in_ptr, then repurposed that command through
  iscsit_reject_cmd(). As the Sashiko review of v2 noted, that is unsafe:
  the command may be in flight, iscsit_add_reject_from_cmd() overwrites
  cmd->buf_ptr without freeing the prior buffer, and it drops a
  target_put_sess_cmd() reference if the ITT matched a SCSI/TMR command.
- v3 rejects in iscsit_setup_text_cmd() before any mutation, so the
  looked-up command is left untouched. The list_add_tail() guard from v1
  is no longer needed and is dropped.
- v1: https://lore.kernel.org/r/20261203-iscsi-text-double-listadd-v1-1-dff966a10cf0@jamessawyer.co.uk
- v2: https://lore.kernel.org/r/20261203-iscsi-text-double-listadd-v2-1-36ebee74657d@jamessawyer.co.uk
---
 drivers/target/iscsi/iscsi_target.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 124ff269b8e7..d33b563ee83e 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -2172,6 +2172,20 @@ iscsit_setup_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
 					(unsigned char *)hdr);
 	}
 
+	/*
+	 * A Text Request with TTT != 0xFFFFFFFF continues an earlier
+	 * SendTargets response and reuses the command found by ITT, which is
+	 * still linked on conn_cmd_list. Such a continuation must be empty.
+	 * Reject one that carries data here, before the looked-up command is
+	 * mutated, rather than process a new request on it.
+	 */
+	if (hdr->ttt != cpu_to_be32(0xFFFFFFFF) && payload_length) {
+		pr_err("Text data on a continuation request is not supported, TTT: 0x%08x\n",
+		       be32_to_cpu(hdr->ttt));
+		return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR,
+					 (unsigned char *)hdr);
+	}
+
 	pr_debug("Got Text Request: ITT: 0x%08x, CmdSN: 0x%08x,"
 		" ExpStatSN: 0x%08x, Length: %u\n", hdr->itt, hdr->cmdsn,
 		hdr->exp_statsn, payload_length);

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261203-iscsi-text-double-listadd-2030d9087986

Best regards,
--  
James Sawyer <james@jamessawyer.co.uk>



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

end of thread, other threads:[~2026-12-03 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 14:02 [PATCH v3] scsi: target: iscsi: reject Text data on a continuation request James Sawyer via B4 Relay
2026-12-03 14:26 ` sashiko-bot

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