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 v3 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
Date: Fri, 04 Dec 2026 06:06:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-249184@kernel.org> (raw)
In-Reply-To: <20261204054748.45560-4-bugs@stellman-greene.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] scsi: target: iscsi: unchecked -ENOMEM leaks cmd in
  iscsit_add_reject_common()
- [Medium] scsi: target: iscsi: premature loop break in
  iscsit_handle_status_snack()
- [Medium] scsi: target: iscsi: Status SNACK resends non-SCSI PDUs as
  SCSI RSP
- [Low] scsi: target: iscsi: missing WRITE_ONCE() on TX conn->stat_sn
  increments
--

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

scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs

This commit bounds Status SNACK handling to the unacknowledged StatSN window
using wrap-safe arithmetic, initializes conn->exp_statsn at login completion,
ignores out-of-range ExpStatSN updates, and checks cmd->i_state under
conn->cmd_lock before queuing status recovery.

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index ffa3432f595c8..69f43126589f9 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -961,6 +961,9 @@ static void iscsit_ack_from_expstatsn(struct iscsit_conn *conn, u32 exp_statsn)
>  	LIST_HEAD(ack_list);
>  	struct iscsit_cmd *cmd, *cmd_p;
>  
> +	if (iscsi_sna_lt(exp_statsn, conn->exp_statsn) ||
> +	    iscsi_sna_gt(exp_statsn, READ_ONCE(conn->stat_sn)))
> +		return;
>  	conn->exp_statsn = exp_statsn;
>  
>  	if (conn->sess->sess_ops->RDMAExtensions)

[Severity: Low]
Does this READ_ONCE(conn->stat_sn) (and the one in
iscsit_handle_status_snack()) need matching WRITE_ONCE() updates on the TX
thread?

The TX paths still increment conn->stat_sn with plain conn->stat_sn++ (for
example in iscsit_build_rsp_pdu() and cxgbit_target.c) without a shared lock,
which causes an unmarked data race under KCSAN on active connections.

[ ... ]

> diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
> index 3562e9ad5e4c8..bf7d7dcf2e334 100644
> --- a/drivers/target/iscsi/iscsi_target_erl1.c
> +++ b/drivers/target/iscsi/iscsi_target_erl1.c

[ ... ]

> +	sent = next_statsn - exp_statsn;
> +	offset = begrun - exp_statsn;
> +	if (offset >= sent || (runlength && runlength > sent - offset))
> +		return iscsit_add_reject_keep_conn(conn,
> +				ISCSI_REASON_PROTOCOL_ERROR, buf);

[Severity: Medium]
Can this leak the reject cmd and its session tag if
iscsit_add_cmd_to_response_queue() returns -ENOMEM?

iscsit_add_reject_keep_conn() calls iscsit_add_reject_common() with
keep_conn set to true, which ignores the return value of
iscsit_add_cmd_to_response_queue():

drivers/target/iscsi/iscsi_target.c:iscsit_add_reject_common() {
	...
	cmd->i_state = ISTATE_SEND_REJECT;
	iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);

	return keep_conn ? 0 : -1;
}

If the GFP_ATOMIC allocation in iscsit_add_cmd_to_response_queue() fails,
returning 0 keeps the connection open while leaving cmd, cmd->buf_ptr, and
its session tag stranded on conn->conn_cmd_list in ISTATE_SEND_REJECT until
the connection closes.

[ ... ]

>  		spin_lock_bh(&conn->cmd_lock);
>  		list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) {
>  			if (cmd->stat_sn == begrun) {
>  				found_cmd = 1;
>  				break;
>  			}
>  		}

[ ... ]

> +		spin_lock(&cmd->istate_lock);
> +		if (cmd->i_state != ISTATE_SENT_STATUS) {
> +			spin_unlock(&cmd->istate_lock);
> +			spin_unlock_bh(&conn->cmd_lock);
>  			begrun++;
>  			continue;
>  		}

[Severity: Medium]
Can breaking out of the conn->conn_cmd_list scan on the first matching
cmd->stat_sn skip a valid ISTATE_SENT_STATUS command later in the list?

When an unsolicited NOP-In is sent, iscsit_build_nopin_rsp() copies
conn->stat_sn without incrementing it and leaves the NOP-In on
conn->conn_cmd_list in ISTATE_SENT_NOPIN_WANT_RESPONSE.  The next
status-bearing command gets the same StatSN, so a Status SNACK for it hits
the earlier NOP-In first, sees i_state != ISTATE_SENT_STATUS, and advances
begrun without retransmitting the real response.

Reading cmd->stat_sn outside cmd->istate_lock also races with the TX thread
assigning cmd->stat_sn.  Taking cmd->istate_lock inside the loop and checking
cmd->i_state == ISTATE_SENT_STATUS && cmd->stat_sn == begrun (as
iscsit_ack_from_expstatsn() does) avoids both issues.

>  		cmd->i_state = ISTATE_SEND_STATUS_RECOVERY;
> -		iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
> +		ret = iscsit_add_cmd_to_response_queue(cmd, conn,
> +						       ISTATE_SEND_STATUS_RECOVERY);

[Severity: Medium]
Does queuing any ISTATE_SENT_STATUS command here resend non-SCSI responses as
bogus SCSI Response PDUs?

In iscsit_response_queue(), non-SCSI responses including ISCSI_OP_REJECT from
iscsit_add_reject_keep_conn() also transition to ISTATE_SENT_STATUS on
conn->conn_cmd_list.  When a Status SNACK matches such a StatSN,
ISTATE_SEND_STATUS_RECOVERY dispatches unconditionally to
iscsit_send_response() -> iscsit_build_rsp_pdu(), which emits an
ISCSI_OP_SCSI_CMD_RSP header and calls iscsit_increment_maxcmdsn().

Because ISCSI_OP_REJECT commands have immediate_cmd and maxcmdsn_inc set to
0, repeating Reject -> Status SNACK -> ExpStatSN ack lets an initiator
inflate conn->sess->max_cmd_sn arbitrarily.

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

      reply	other threads:[~2026-12-04  6:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  5:47 [PATCH v3 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
2026-12-04  5:47 ` [PATCH v3 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
2026-12-04  6:10   ` sashiko-bot
2026-12-04  5:47 ` [PATCH v3 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap Andrew Stellman
2026-12-04  6:06   ` sashiko-bot
2026-12-04  5:47 ` [PATCH v3 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
2026-12-04  6:06   ` 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-249184@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.