Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] scsi: target: iscsi: reject Text continuations that carry data
@ 2026-12-03 12:34 James Sawyer via B4 Relay
  2026-12-03 12:56 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Sawyer via B4 Relay @ 2026-12-03 12:34 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
response and reuses the command found by ITT through
iscsit_find_cmd_from_itt(), which walks conn->conn_cmd_list, so that
command is already linked there. Only empty continuations are handled
(the empty_sendtargets path). If the PDU carries a "SendTargets="
payload, iscsit_process_text_cmd() processes it as 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.
Discovery sessions accept Text Requests and do not require
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.

Processing the payload also leaves the reused command inconsistent:
iscsit_setup_text_cmd() has reset targ_xfer_tag, and the
ICF_SENDTARGETS_* flags are OR-ed into cmd_flags without clearing the
previous ones.

Reject a Text continuation that carries data before it is processed.
iscsit_reject_cmd() does not link the command again. This covers
iscsi_target, isert and cxgbit, which all reach this function.

Found by source review only; no reproducer was built. The fix was
compile-tested only: built with W=1 (drivers/target/iscsi/iscsi_target.o)
on v7.4-rc1 without 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 and not reproduced: I did not
  build a trigger. The fix is compile-tested only. Please treat the list
  analysis in the commit message as reasoning, not observation.
- Related point I have not analysed: in a logged-in session the same
  ITT lookup can return a non-Text command (e.g. SCSI), and an empty
  continuation still runs the empty_sendtargets path on it. Rejecting the
  PDU unless cmd->iscsi_opcode == ISCSI_OP_TEXT in the TTT != 0xFFFFFFFF
  lookup (iscsi_target, isert, cxgbit) would close that too.

Changes in v2:
- Reject a Text continuation that carries data instead of only skipping
  the second list_add_tail(). The reused command was otherwise processed
  with stale targ_xfer_tag and accumulated ICF_SENDTARGETS_* flags
  (pointed out by the Sashiko review of v1).
- Link to v1: https://lore.kernel.org/r/20261203-iscsi-text-double-listadd-v1-1-dff966a10cf0@jamessawyer.co.uk
---
 drivers/target/iscsi/iscsi_target.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 124ff269b8e7..f542098e5d87 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -2207,6 +2207,17 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
 		}
 		goto empty_sendtargets;
 	}
+	/*
+	 * A Text Request with TTT != 0xFFFFFFFF continues an earlier
+	 * response and reuses the command found by ITT, which is still on
+	 * conn_cmd_list. Only an empty continuation is supported; a new
+	 * request must not be processed on that command.
+	 */
+	if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) {
+		pr_err("Text continuation with data is not supported, TTT: 0x%08x\n",
+		       be32_to_cpu(hdr->ttt));
+		goto reject;
+	}
 	if (strncmp("SendTargets=", text_in, 12) != 0) {
 		pr_err("Received Text Data that is not"
 			" SendTargets, cannot continue.\n");

---
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 12:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:34 [PATCH v2] scsi: target: iscsi: reject Text continuations that carry data James Sawyer via B4 Relay
2026-12-03 12:56 ` sashiko-bot

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