Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: target: iscsi: do not re-add a listed command on Text continuation
@ 2026-12-03 11:59 James Sawyer via B4 Relay
  2026-12-03 12:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Sawyer via B4 Relay @ 2026-12-03 11:59 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 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@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), 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@jamessawyer.co.uk>



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

* Re: [PATCH] scsi: target: iscsi: do not re-add a listed command on Text continuation
  2026-12-03 11:59 [PATCH] scsi: target: iscsi: do not re-add a listed command on Text continuation James Sawyer via B4 Relay
@ 2026-12-03 12:23 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 12:23 UTC (permalink / raw)
  To: James Sawyer; +Cc: linux-scsi, target-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: target: iscsi: silent acceptance of non-empty Text
  continuations
--

commit fbebc5c9e35a6a434da55856a409f70ce970dbfd
Author: James Sawyer <james@jamessawyer.co.uk>

scsi: target: iscsi: do not re-add a listed command on Text continuation

This commit guards list_add_tail() in iscsit_process_text_cmd() with
list_empty(&cmd->i_conn_node) so a reused Text command on a continuation
request is not linked onto conn->conn_cmd_list a second time.

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 124ff269b8e75..1cbec5f1447fa 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:

[Severity: Medium]
Should iscsit_process_text_cmd() reject a non-empty Text continuation
instead of silently skipping list_add_tail() and proceeding on the reused
cmd?

Multi-sequence SendTargets continuations (hdr->ttt != 0xFFFFFFFF) are only
valid as empty requests taking the empty_sendtargets path.  Letting a
continuation with a SendTargets= payload run leaves the reused cmd in an
inconsistent state.

iscsit_setup_text_cmd() resets cmd->targ_xfer_tag to 0xFFFFFFFF, and the
non-empty path never restores hdr->ttt.  cmd->read_data_done also retains
the prior offset and skips bytes of the new SendTargets response.

iscsit_process_text_cmd() ORs ICF_SENDTARGETS_ALL or ICF_SENDTARGETS_SINGLE
into cmd->cmd_flags without clearing prior flags.  Switching from
SendTargets=iqn.x to SendTargets=All leaves ICF_SENDTARGETS_SINGLE set,
causing iscsit_build_sendtargets_response() to filter targets against "All".

Rejecting non-empty Text continuations before mutating cmd, using
iscsit_add_reject(), would prevent both the list corruption and the
corrupted SendTargets state.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-iscsi-text-double-listadd-v1-1-dff966a10cf0@jamessawyer.co.uk?part=1

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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:59 [PATCH] scsi: target: iscsi: do not re-add a listed command on Text continuation James Sawyer via B4 Relay
2026-12-03 12:23 ` sashiko-bot

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