All of lore.kernel.org
 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 v2 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject
Date: Wed, 02 Dec 2026 17:21:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-246323@kernel.org> (raw)
In-Reply-To: <20261202165734.51018-2-bugs@stellman-greene.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] scsi: target: iscsi: uninitialized ITT/TTT in
  iscsit_add_reject_common()
- [High] scsi: target: iscsi: tag pool exhaustion deadlock on repeated
  SNACK rejects
--

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

scsi: target: iscsi: Don't drop live command refs on SNACK Reject

This commit introduces iscsit_add_reject_keep_conn() and uses it in
iscsit_handle_r2t_snack() and iscsit_handle_recovery_datain() so that
rejected out-of-range Data and R2T SNACKs allocate a separate Reject
command and keep the connection open instead of dropping the live SCSI
command's reference.

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 2b4956f46c132..fbfd8a61ced51 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -784,10 +784,8 @@ static void __exit iscsi_target_cleanup_module(void)
>  	kfree(iscsit_global);
>  }
>  
> -int iscsit_add_reject(
> -	struct iscsit_conn *conn,
> -	u8 reason,
> -	unsigned char *buf)
> +static int iscsit_add_reject_common(struct iscsit_conn *conn, u8 reason,
> +				    unsigned char *buf, bool keep_conn)
>  {
>  	struct iscsit_cmd *cmd;
>  
> @@ -812,10 +810,21 @@ int iscsit_add_reject(
>  	cmd->i_state = ISTATE_SEND_REJECT;
>  	iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
>  
> -	return -1;
> +	return keep_conn ? 0 : -1;
> +}

[Severity: Critical]
Does linking cmd onto conn->conn_cmd_list while keeping the connection
open leave cmd->init_task_tag and cmd->targ_xfer_tag at 0?

iscsit_allocate_cmd() zero-initializes cmd, and unlike target-originated
commands in iscsit_add_nopin() or iscsit_send_conn_drop_async_message(),
iscsit_add_reject_common() does not set cmd->init_task_tag = RESERVED_ITT,
cmd->targ_xfer_tag = 0xFFFFFFFF, or cmd->immediate_cmd = 1.  When
keep_conn is true, cmd remains on conn->conn_cmd_list until ExpStatSN
acknowledges it, so subsequent PDUs on the live connection can look it up
by TTT 0 or ITT 0.

For example, a NOP-Out with ITT = RESERVED_ITT and TTT = 0 matches the
Reject cmd in iscsit_find_cmd_from_ttt() and frees it while it is still
queued on conn->response_queue_list:

RX thread (iscsi_target_rx_thread)  TX thread (iscsi_target_tx_thread)
----------------------------------  ----------------------------------
iscsit_handle_snack()
  ...
  iscsit_add_reject_keep_conn()
    list_add_tail(&cmd->i_conn_node,
                  &conn->conn_cmd_list)
    iscsit_add_cmd_to_response_queue(
      cmd, conn, ISTATE_SEND_REJECT)

iscsit_process_nop_out() [TTT = 0]
  iscsit_find_cmd_from_ttt(conn, 0)
  cmd->i_state = ISTATE_REMOVE
  iscsit_add_cmd_to_immediate_queue()
                                    iscsit_handle_immediate_queue()
                                      iscsit_immediate_queue()
                                        /* ISTATE_REMOVE */
                                        list_del_init(&cmd->i_conn_node)
                                        iscsit_free_cmd(cmd, false)
                                    iscsit_handle_response_queue()
                                      iscsit_response_queue()
                                        /* ISTATE_SEND_REJECT */
                                        iscsit_send_reject(cmd, conn)
                                          <-- use-after-free of cmd
                                              and cmd->buf_ptr

A subsequent Text PDU with TTT != 0xFFFFFFFF and ITT = 0 also matches the
Reject cmd via iscsit_find_cmd_from_itt() in iscsi_target_rx_opcode() and
passes it to iscsit_process_text_cmd(), which re-adds cmd->i_conn_node to
conn->conn_cmd_list and corrupts the list.  In addition, because
cmd->immediate_cmd is 0, closing the connection before the Reject is
acknowledged causes iscsit_increment_maxcmdsn() to increment
sess->max_cmd_sn for a Reject PDU that consumed no CmdSN.

> diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
> index 44b851e4a602d..312e0502b9f0e 100644
> --- a/drivers/target/iscsi/iscsi_target_erl1.c
> +++ b/drivers/target/iscsi/iscsi_target_erl1.c
> @@ -129,7 +129,8 @@ static int iscsit_handle_r2t_snack(
>  			" protocol error.\n", cmd->init_task_tag, begrun,
>  			(begrun + runlength), cmd->acked_data_sn);
>  
> -		return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
> +		return iscsit_add_reject_keep_conn(cmd->conn,
> +				ISCSI_REASON_PROTOCOL_ERROR, buf);
>  	}

[Severity: High]
Can repeated SNACK rejects exhaust se_sess->sess_tag_pool and deadlock
iscsi_target_rx_thread?

iscsit_add_reject_keep_conn() allocates a command tag via
iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE).  Once the TX thread sends
the Reject, the command moves to ISTATE_SENT_STATUS and holds its tag on
conn->conn_cmd_list until iscsit_ack_from_expstatsn() frees it on the RX
thread.

However, SNACK PDUs are not gated by the CmdSN window and
iscsit_handle_snack() does not call iscsit_ack_from_expstatsn().  Every
opcode that does call iscsit_ack_from_expstatsn() (such as
ISCSI_OP_SCSI_CMD or ISCSI_OP_NOOP_OUT) first calls
iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE) in iscsi_target_rx_opcode():

drivers/target/iscsi/iscsi_target.c:iscsi_target_rx_opcode() {
	...
	switch (hdr->opcode & ISCSI_OPCODE_MASK) {
	case ISCSI_OP_SCSI_CMD:
		cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE);
		if (!cmd)
			goto reject;

		ret = iscsit_handle_scsi_cmd(conn, cmd, buf);
	...
}

If an initiator sends enough rejected SNACKs to fill
se_sess->sess_tag_pool, the next rejected SNACK or incoming command blocks
iscsi_target_rx_thread indefinitely in iscsit_wait_for_tag(), waiting for
a tag that can only be released by iscsit_ack_from_expstatsn() running on
that same RX thread.

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

  reply	other threads:[~2026-12-02 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:57 [PATCH v2 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
2026-12-02 16:57 ` [PATCH v2 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
2026-12-02 17:21   ` sashiko-bot [this message]
2026-12-02 16:57 ` [PATCH v2 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap Andrew Stellman
2026-12-02 16:57 ` [PATCH v2 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
2026-12-02 17:15   ` 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=sashiko-outbox-246323@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 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.