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

* Re: [PATCH v2] scsi: target: iscsi: reject Text continuations that carry data
  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
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 12:56 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:
- [Critical] scsi: target: iscsi: late reject in
  iscsit_process_text_cmd() races live cmd
--

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

scsi: target: iscsi: reject Text continuations that carry data

This commit rejects iSCSI Text Request continuations (TTT != 0xFFFFFFFF)
that carry a text_in payload in iscsit_process_text_cmd() by branching to
iscsit_reject_cmd().

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 124ff269b8e75..f542098e5d877 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;
> +	}

[Severity: Critical]
Can rejecting a reused command this late in iscsit_process_text_cmd() race
with the TX thread and corrupt or leak cmd->buf_ptr?

By the time this check runs, iscsit_setup_text_cmd() has already mutated the
live cmd in place and freed cmd->text_in_ptr.  iscsit_add_reject_from_cmd()
then replaces cmd->buf_ptr with a 48-byte kmemdup() buffer, writes
cmd->i_state without cmd->istate_lock, and re-queues cmd on the response list.

An unauthenticated discovery initiator can pipeline a data-carrying Text
continuation while the TX thread is sending the prior Text response:

RX thread                         TX thread
iscsit_find_cmd_from_itt()
iscsit_setup_text_cmd()
  kfree(cmd->text_in_ptr)
                                  iscsit_send_text_rsp()
                                    iscsit_build_sendtargets_response()
                                      /* sets buf_ptr, up to 32 KiB */
iscsit_process_text_cmd()
  goto reject
    iscsit_add_reject_from_cmd()
      cmd->buf_ptr = kmemdup(...)
                                    iscsit_xmit_pdu(..., cmd->buf_ptr,
                                                    text_length)
                                      <-- out-of-bounds read (up to 32 KiB)

This causes a use-after-free of cmd->text_in_ptr in
iscsit_build_sendtargets_response() under ICF_SENDTARGETS_SINGLE, or a slab
out-of-bounds read or DMA map past the 48-byte kmemdup() buffer.

Even without a race, iscsit_add_reject_from_cmd() overwrites cmd->buf_ptr
without freeing the prior SendTargets buffer (leaking up to 32 KiB per PDU),
and on kmemdup() failure it calls iscsit_free_cmd(cmd, false) while cmd is
still linked on conn->conn_cmd_list.

If hdr->itt matches an active SCSI or TMR command (cmd->se_cmd.se_tfo !=
NULL), iscsit_add_reject_from_cmd() also calls target_put_sess_cmd() and
drops a reference it does not own.

On iSER, re-queuing ISTATE_SEND_REJECT reuses isert_cmd->tx_desc and
comp_work while a prior send or completion may still be in flight, and
leaving ISCSI_FLAG_TEXT_CONTINUE set in tx_desc.iscsi_header causes
isert_put_cmd() to keep cmd stuck on conn->conn_cmd_list.

Should data-carrying Text continuations be rejected before mutating the
looked-up command and without repurposing it through iscsit_reject_cmd()
(using iscsit_add_reject() in iscsi_target and cxgbit, and a fresh
isert_allocate_cmd() reject or connection reinstatement in isert)?

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

^ permalink raw reply	[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