[PATCH] scsi: target: iscsi: do not re-add a listed command on Text continuation
From: James Sawyer via B4 Relay
Date: Thu Dec 03 2026 - 06:59:36 EST
From: James Sawyer <james@xxxxxxxxxxxxxxxxx>
A Text Request with TTT != 0xFFFFFFFF 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. If the PDU carries a
"SendTargets=" payload, iscsit_process_text_cmd() calls
list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list) on it again.
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.
Only link the command if it is not already on the list. i_conn_node is
initialised in iscsit_allocate_cmd() and every removal uses
list_del_init(), so list_empty() is a valid test. 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@xxxxxxxxxxxxxxxxx>
---
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), which
iscsit_setup_text_cmd() then re-initialises. Rejecting the PDU unless
cmd->iscsi_opcode == ISCSI_OP_TEXT in the TTT != 0xFFFFFFFF branch
(iscsi_target, isert, cxgbit) would close that too.
---
drivers/target/iscsi/iscsi_target.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 124ff269b8e7..1cbec5f1447f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -2226,8 +2226,13 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
goto reject;
}
+ /*
+ * A Text Request with TTT != 0xFFFFFFFF reuses the command found by
+ * ITT, which is already on conn_cmd_list. Only link new commands.
+ */
spin_lock_bh(&conn->cmd_lock);
- list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list);
+ if (list_empty(&cmd->i_conn_node))
+ list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list);
spin_unlock_bh(&conn->cmd_lock);
empty_sendtargets:
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261203-iscsi-text-double-listadd-2030d9087986
Best regards,
--
James Sawyer <james@xxxxxxxxxxxxxxxxx>