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 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
Date: Wed, 02 Dec 2026 17:15:20 +0000 [thread overview]
Message-ID: <sashiko-outbox-246314@kernel.org> (raw)
In-Reply-To: <20261202165734.51018-4-bugs@stellman-greene.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: target: iscsi: premature loop break in
iscsit_handle_status_snack()
- [Medium] scsi: target: iscsi: non-SCSI responses resent as SCSI RSP on
Status SNACK
--
commit 1e2b7340230a6d6cf159ffb169b465170253c238
Author: Andrew Stellman <astellman@stellman-greene.com>
scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
This commit initializes conn->exp_statsn at login, ignores invalid ExpStatSN
updates, validates that Status SNACK ranges fall within the unacknowledged
StatSN window, and queues only ISTATE_SENT_STATUS commands under cmd_lock.
> 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
> @@ -468,28 +468,32 @@ int iscsit_handle_recovery_datain_or_r2t(
> /* #warning FIXME: Status SNACK needs to be dependent on OPCODE!!! */
> int iscsit_handle_status_snack(
> struct iscsit_conn *conn,
> + unsigned char *buf,
> itt_t init_task_tag,
> u32 targ_xfer_tag,
> u32 begrun,
> u32 runlength)
> {
> struct iscsit_cmd *cmd = NULL;
> - u32 last_statsn;
> - int found_cmd;
> -
> - if (!begrun) {
> - begrun = conn->exp_statsn;
> - } else if (conn->exp_statsn > begrun) {
> - pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:"
> - " 0x%08x but already got ExpStatSN: 0x%08x on CID:"
> - " %hu.\n", begrun, runlength, conn->exp_statsn,
> - conn->cid);
> - return 0;
> + u32 next_statsn = READ_ONCE(conn->stat_sn);
> + u32 exp_statsn = READ_ONCE(conn->exp_statsn);
> + u32 sent, offset, count;
> + int found_cmd, ret;
> +
> + if (!begrun && !runlength) {
> + if (exp_statsn == next_statsn)
> + return 0;
> + begrun = exp_statsn;
> }
> + 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);
>
> - last_statsn = (!runlength) ? conn->stat_sn : (begrun + runlength);
> + count = runlength ? runlength : sent - offset;
>
> - while (begrun < last_statsn) {
> + while (count--) {
> found_cmd = 0;
>
> spin_lock_bh(&conn->cmd_lock);
> @@ -499,9 +503,9 @@ int iscsit_handle_status_snack(
> break;
> }
> }
> - spin_unlock_bh(&conn->cmd_lock);
>
> if (!found_cmd) {
> + spin_unlock_bh(&conn->cmd_lock);
> pr_err("Unable to find StatSN: 0x%08x for"
> " a Status SNACK, assuming this was a"
> " protactic SNACK for an untransmitted"
> @@ -510,20 +514,22 @@ int iscsit_handle_status_snack(
> continue;
> }
>
> - spin_lock_bh(&cmd->istate_lock);
> - if (cmd->i_state == ISTATE_SEND_DATAIN) {
> - spin_unlock_bh(&cmd->istate_lock);
> - pr_err("Ignoring Status SNACK for BegRun:"
> - " 0x%08x, RunLength: 0x%08x, assuming this was"
> - " a protactic SNACK for an untransmitted"
> - " StatSN\n", begrun, runlength);
> + 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 walk on the first entry with
cmd->stat_sn == begrun miss the actual ISTATE_SENT_STATUS command and skip
resending its status?
An unsolicited NOP-In queued by iscsit_add_nopin() copies conn->stat_sn
without advancing it and stays on conn->conn_cmd_list in
ISTATE_SENT_NOPIN_WANT_RESPONSE:
drivers/target/iscsi/iscsi_target.c:iscsit_build_nopin_rsp() {
...
cmd->stat_sn = (nopout_response) ? conn->stat_sn++ :
conn->stat_sn;
...
}
The next response on the connection consumes that same StatSN and enters
ISTATE_SENT_STATUS later in conn->conn_cmd_list. Because the loop breaks on
the earlier NOP-In before checking cmd->i_state, the cmd->i_state !=
ISTATE_SENT_STATUS check drops the SNACK for begrun instead of continuing the
list search, leaving the initiator to time out waiting for the status
retransmission.
> 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 as ISTATE_SEND_STATUS_RECOVERY
cause non-SCSI responses to be resent as ISCSI_OP_SCSI_CMD_RSP PDUs?
In iscsit_response_queue(), non-SCSI responses such as ISTATE_SEND_REJECT
(including the reject added above by iscsit_add_reject_keep_conn()),
ISTATE_SEND_NOPIN, ISTATE_SEND_TEXTRSP, ISTATE_SEND_TASKMGTRSP, and
ISTATE_SEND_ASYNCMSG also advance conn->stat_sn and transition to
ISTATE_SENT_STATUS:
drivers/target/iscsi/iscsi_target.c:iscsit_response_queue() {
...
case ISTATE_SEND_STATUS:
case ISTATE_SEND_ASYNCMSG:
case ISTATE_SEND_NOPIN:
case ISTATE_SEND_STATUS_RECOVERY:
case ISTATE_SEND_TEXTRSP:
case ISTATE_SEND_TASKMGTRSP:
case ISTATE_SEND_REJECT:
spin_lock_bh(&cmd->istate_lock);
cmd->i_state = ISTATE_SENT_STATUS;
spin_unlock_bh(&cmd->istate_lock);
break;
...
}
When a Status SNACK covers that StatSN, queuing the command as
ISTATE_SEND_STATUS_RECOVERY sends it through iscsit_send_response() ->
iscsit_build_rsp_pdu(), which transmits a bogus SCSI Command Response and
calls iscsit_increment_maxcmdsn() even for PDUs like Reject or Async Message
that never incremented MaxCmdSN, desynchronizing the session CmdSN window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202165734.51018-1-bugs@stellman-greene.com?part=3
prev parent reply other threads:[~2026-12-02 17:15 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
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 [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-246314@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