Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Andrew Stellman <bugs@stellman-greene.com>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: Mike Christie <michael.christie@oracle.com>,
	target-devel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: [PATCH v3 scsi-fixes 1/2] scsi: target: iscsi: Reserve tags on standalone Rejects
Date: Sun, 29 Nov 2026 10:52:51 -0500	[thread overview]
Message-ID: <20261129155252.2217-1-bugs@stellman-greene.com> (raw)
In-Reply-To: <20261129001755.78909-1-bugs@stellman-greene.com>

From: Andrew Stellman <astellman@stellman-greene.com>

iscsit_add_reject() allocates a zeroed command, so the Reject's ITT and
TTT are both 0, and the command stays on conn_cmd_list until the
initiator acknowledges its StatSN. When a Data-Out's DataSegmentLength
is greater than MaxXmitDataSegmentLength, iscsit_check_dataout_hdr()
queues such a Reject and iscsit_handle_data_out() returns 0, so the
connection stays up. A following Data-Out with ITT 0 then matches the
Reject and is dumped as a Data-Out for a non-WRITE command. A following
NOP-Out with ITT 0xffffffff and TTT 0 matches it in
iscsit_find_cmd_from_ttt(), and iscsit_process_nop_out() queues it as
ISTATE_REMOVE. The TX thread services the immediate queue first and
frees the Reject header before sending it:

  BUG: KASAN: slab-use-after-free in _copy_from_iter+0x770/0x10d0
  Read of size 48 at addr ffff0000e8094780 by task iscsi_ttx/381
   iscsit_xmit_pdu+0x62c/0xbb8
   iscsit_response_queue+0xa84/0x1340
  Allocated by task 382:
   kmemdup_noprof+0x34/0x60
   iscsit_add_reject+0x94/0x210
   iscsit_check_dataout_hdr+0x294/0x350
  Freed by task 381:
   iscsit_release_cmd+0xbc/0x2c8
   iscsit_free_cmd+0x100/0x14c
   iscsit_immediate_queue+0x104/0x8ac

Set the Reject's ITT to RESERVED_ITT and its TTT to 0xffffffff, as
iscsit_add_nopin() does for a NOP-In that wants no response. This
changes existing behaviour for every iscsit_add_reject() caller: while
the Reject is queued, a Data-Out with ITT 0 is dumped as an unknown ITT
and a NOP-Out with TTT 0 is an unknown TTT.

Tested on arm64 QEMU with KASAN, iSCSI over TCP on loopback, ERL=1,
DataDigest=CRC32C and InitialR2T=No, with a test-only 100 ms delay in
the TX thread before it services its queues. The initiator sent a
Data-Out with DataSegmentLength 16777215 and no payload, a Data-Out
with ITT 0 and a NOP-Out with ITT 0xffffffff and TTT 0. Without this
patch KASAN reported the above. With it the target logged both tags as
unknown and closed the connection, with no KASAN, refcount or WARNING
report. A valid WRITE completed in both cases.

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: 561bf1589237 ("iscsi-target: Fix iscsit_sequence_cmd reject handling for iser")
Cc: stable@vger.kernel.org
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v3: New patch. Mainline already reaches the zero tags through the
oversized Data-Out Reject, so the tag fix is its own patch, ahead of
the v2 change (2/2).
v2: https://lore.kernel.org/target-devel/20261129001755.78909-1-bugs@stellman-greene.com/

A reproducer is available on request.

 drivers/target/iscsi/iscsi_target.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 2b4956f46c132..359c66d1051ab 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -797,6 +797,8 @@ int iscsit_add_reject(
 
 	cmd->iscsi_opcode = ISCSI_OP_REJECT;
 	cmd->reject_reason = reason;
+	cmd->init_task_tag = RESERVED_ITT;
+	cmd->targ_xfer_tag = 0xFFFFFFFF;
 
 	cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL);
 	if (!cmd->buf_ptr) {

  parent reply	other threads:[~2026-11-29 15:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 19:17 [PATCH scsi-fixes] scsi: target: iscsi: Fix UAF on an immediate data digest error Andrew Stellman
2026-11-28 19:38 ` sashiko-bot
2026-11-29  0:17 ` [PATCH v2 " Andrew Stellman
2026-11-29  0:36   ` sashiko-bot
2026-11-29 15:52   ` Andrew Stellman [this message]
2026-11-29 15:52     ` [PATCH v3 scsi-fixes 2/2] " Andrew Stellman
2026-11-29 16:12       ` sashiko-bot

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=20261129155252.2217-1-bugs@stellman-greene.com \
    --to=bugs@stellman-greene.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=michael.christie@oracle.com \
    --cc=mkp@kernel.org \
    --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