From: sashiko-bot@kernel.org
To: "James Sawyer" <james@jamessawyer.co.uk>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH v3] scsi: target: iscsi: reject Text data on a continuation request
Date: Thu, 03 Dec 2026 14:26:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-247965@kernel.org> (raw)
In-Reply-To: <20261203-iscsi-text-double-listadd-v3-1-75dd3ef9ce30@jamessawyer.co.uk>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] scsi: target: iscsi: iscsit_setup_text_cmd() hijacks live
cmd on reject
- [High] scsi: target: iscsi: early Text reject leaves unread TCP
payload
--
commit 16b6a243b5153b553b7782bb0663c15e0f491e40
Author: James Sawyer <james@jamessawyer.co.uk>
scsi: target: iscsi: reject Text data on a continuation request
This commit adds a check in iscsit_setup_text_cmd() to reject Text Requests
that carry a non-zero payload when TTT != 0xFFFFFFFF, before the rest of
iscsit_setup_text_cmd() updates the looked-up command.
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 124ff269b8e75..d33b563ee83eb 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);
> + }
[Severity: Critical]
Does passing the looked-up cmd to iscsit_reject_cmd() really leave it
untouched?
When hdr->ttt != 0xFFFFFFFF, all three transports obtain cmd via
iscsit_find_cmd_from_itt(), which returns any live command on
conn->conn_cmd_list matching that ITT regardless of opcode or state.
iscsit_reject_cmd() calls iscsit_add_reject_from_cmd(), which mutates it:
drivers/target/iscsi/iscsi_target.c:iscsit_add_reject_from_cmd() {
...
const bool do_put = cmd->se_cmd.se_tfo != NULL;
...
cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL);
if (!cmd->buf_ptr) {
...
iscsit_free_cmd(cmd, false);
return -1;
}
...
cmd->i_state = ISTATE_SEND_REJECT;
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
if (do_put) {
...
target_put_sess_cmd(&cmd->se_cmd);
}
}
If the ITT matches an active SCSI or TMR command, target_put_sess_cmd()
drops a reference it does not own, causing a use-after-free while target
core and conn->conn_cmd_list still reference cmd.
Overwriting cmd->buf_ptr also leaks any existing buffer (such as a
SendTargets response), and if TX is concurrently running
iscsit_send_text_rsp() it can read text_length bytes past the 48-byte
allocation. On OOM, iscsit_free_cmd(cmd, false) frees a linked cmd.
Writing cmd->i_state without cmd->istate_lock and queueing a second
response entry can also race with iscsit_ack_from_expstatsn() freeing cmd
with check_queues false, leaving a use-after-free on response_queue_list.
Finally, iscsit_build_reject() ORs ISCSI_FLAG_CMD_FINAL into the reused
header without zeroing it, leaving stale ISCSI_FLAG_TEXT_CONTINUE set.
On iSER this prevents isert_put_cmd() from releasing cmd, and
isert_put_reject() reuses isert_cmd->tx_desc while a send may be active.
Rejecting a data-carrying continuation with a newly allocated reject
command (or closing the connection) instead of reusing cmd would leave
the looked-up command untouched.
[Severity: High]
Can returning early here leave the Text payload unread on the TCP socket?
On TCP, iscsit_get_rx_pdu() reads only the 48-byte BHS header before
calling iscsit_handle_text_cmd(), leaving ALIGN(payload_length, 4) bytes
(plus optional DataDigest) unread until rx_data(). When this check
triggers, payload_length is non-zero, yet the error return is swallowed:
drivers/target/iscsi/iscsi_target.c:iscsit_handle_text_cmd() {
...
rc = iscsit_setup_text_cmd(conn, cmd, hdr);
if (rc < 0)
return 0;
...
}
Because iscsi_target_rx_opcode() then returns 0, iscsit_get_rx_pdu()
continues its loop and parses the unread Text payload bytes as the next
iSCSI PDU header, desynchronizing the TCP stream and keeping the
connection open for repeated pr_err() log flooding and buffer leaks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-iscsi-text-double-listadd-v3-1-75dd3ef9ce30@jamessawyer.co.uk?part=1
prev parent reply other threads:[~2026-12-03 14:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:02 [PATCH v3] scsi: target: iscsi: reject Text data on a continuation request James Sawyer
2026-12-03 14:02 ` James Sawyer via B4 Relay
2026-12-03 14:26 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-247965@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=james@jamessawyer.co.uk \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.