Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrew Stellman" <bugs@stellman-greene.com>
Cc: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: target: iscsi: Free dropped Text commands on DataDigest errors
Date: Sun, 29 Nov 2026 14:08:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-239686@kernel.org> (raw)
In-Reply-To: <20261129135303.80812-1-bugs@stellman-greene.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: target: iscsi: inaccurate Fixes trailer for
  iscsit_handle_text_cmd()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] scsi: target: iscsi: TCP stream desynchronization in
  non-SCSI handlers [1]
--

commit 3e3312bd41bf89c36eb174a1346bc67aacc6f605
Author: Andrew Stellman <astellman@stellman-greene.com>

> scsi: target: iscsi: Free dropped Text commands on DataDigest errors
>
> At ErrorRecoveryLevel 1 and above, iscsit_handle_text_cmd() and
> cxgbit_handle_text_cmd() silently drop a Text Request whose DataDigest
> doesn't match. When the request starts a new exchange (TTT 0xffffffff),
> the receive path has already allocated a command and a session tag for
> it, but the drop path returns without linking the command to the
> connection or freeing it, so each such request leaks the command and
> its tag.
>
> Free the command on both drop paths when TTT is 0xffffffff, as the
> NOP-Out DataDigest error path already does. A Text Request that
> continues an existing exchange uses a command that is already on the
> connection list, so it's left alone. The PDU is still dropped silently.
>
> Tested over TCP on mainline in an arm64 QEMU guest with KASAN, ERL 1
> and DataDigest=CRC32C. Before the fix, after 140 Text Requests with a
> bad DataDigest the target logged 136 digest errors and a following
> NOP-Out got no NOP-In within 3 seconds; with the fix it got a NOP-In.
> The cxgbit change was compiled but not run.
>
> The issue was found by Claude Opus 5.5 running Quality Playbook, an
> LLM-driven code review tool:
> https://github.com/andrewstellman/quality-playbook
> The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
> Claude Opus 5.5, and both were reviewed by me.
>
> Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
> Fixes: 9730ffcb8957 ("cxgbit: add files for cxgbit.ko")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>

[Severity: Low]
In commit e48354ce078c ("iscsi-target: Add iSCSI fabric support for target
v4.1"), iscsit_handle_text_cmd() validated the DataDigest before calling
iscsit_allocate_cmd(), so the ERL >= 1 DataCRC drop path did not leak a
command.  The leak in iscsit_handle_text_cmd() was introduced when commit
64534aa79496 ("iscsi-target: Refactor ISCSI_OP_TEXT RX handling") hoisted
iscsit_allocate_cmd() into iscsi_target_rx_opcode().  Should the first
Fixes: tag be:

  Fixes: 64534aa79496 ("iscsi-target: Refactor ISCSI_OP_TEXT RX handling")

[ ... ]

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 2b4956f46c132..9810e3dfcc1ce 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -2300,6 +2300,8 @@ iscsit_handle_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
>  					" DataCRC error.\n", hdr->cmdsn);
>  					kfree(text_in);
>  					cmd->text_in_ptr = NULL;
> +					if (hdr->ttt == cpu_to_be32(0xFFFFFFFF))
> +						iscsit_free_cmd(cmd, false);
>  					return 0;
>  				}
>  			} else {

[Severity: Critical]
This problem wasn't introduced by this patch, but can an early failure in
iscsit_setup_text_cmd() desynchronize the TCP stream [1]?

drivers/target/iscsi/iscsi_target.c:iscsit_handle_text_cmd() {
	...
	rc = iscsit_setup_text_cmd(conn, cmd, hdr);
	if (rc < 0)
		return 0;

	rx_size = payload_length;
	if (payload_length) {
	...
}

When iscsit_setup_text_cmd() fails on a Text Request carrying a non-zero
payload_length (and similarly in iscsit_handle_nop_out() when
iscsit_setup_nop_out() fails), the handler returns 0 without reading
payload_length bytes from the socket.  The RX thread then parses the
unread payload as the next iSCSI Basic Header Segment, allowing crafted
payload bytes to inject arbitrary PDUs or crash the target.

[1] https://sashiko.dev/#/bug/linux-bc9d46c7-9320-42b5-85cc-7b0a1cddfeb4

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129135303.80812-1-bugs@stellman-greene.com?part=1

      reply	other threads:[~2026-11-29 14:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:53 [PATCH] scsi: target: iscsi: Free dropped Text commands on DataDigest errors Andrew Stellman
2026-11-29 14:08 ` 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-239686@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bugs@stellman-greene.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox