From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796231721; b=wiGVgi6HuNELHto69T3LNYELfCUFaAqDTgBhZnONdppuN0PB3UIU0aIRhhYhsXslTugQ 3OJkcwHoSjq3EkJ5CricZ/LwrO7+CC4RpT289nRC6ptsZinc10mS8oT3MbFgTIgi5JXcU Md7kSBsq3U5ePEy09k0HLh5MWmjEo8DhWAPopFC48llJBrcvMUl5xMXqHx6hCpcHjoIQb KBF6+hYPvUd0Xyxaaz1hVOzXXDvkYGfv4lqBXDsgyaKtyNZkHLOccLs//86gpW0izOsc3 VD63O3QxQ6LBf0Vsy+B3SS3vbKFXhi5N5eL4QxHof3ZQHBLIzEg4wRUYO4PwZ69hItQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796231721; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vlg85ra2G3woZQUGlKQveyszBQ72dOYxEUURkMRIp8U=; b=PLQJWHpilkm8JsYKAM4LfAKd/iRfRNv73iioQgnaUF7t092WhWDt9oItc6VyPwo1DPa9 5tDKyueKotwWNHUXw+VcpcUMs6ME8Zqz1Me7qLLlEH9BLvgxgvBlPQJZF9s7fSjjk/Ook pz7+eJvQYmZRgj49OBRsYSqwCERCyDts/BedP3ZZWT0vtPLgrnQvLboEZRrZgLa55L4A5 I7d4mYr7yk6evk6yEDFwbx3YARkmql5NI6TtZAbHIxXZUu+7WFyCtIv62SjapO3ilJwM6 92b+DIN13YBXkMNBuPyLHBaR4MMUmHtj7iTZ4kfb9HTHyNTPks0JwLZaw1yLyHwBeMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="QiuKf/tK"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03721606A32F; Wed, 2 Dec 2026 17:15:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QiuKf/tK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D8601F00893; Wed, 2 Dec 2026 17:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796231720; bh=vlg85ra2G3woZQUGlKQveyszBQ72dOYxEUURkMRIp8U=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QiuKf/tKqZwvwx6vWxOKuqgX/w6IcwWAR9VG4Vwf9o7KnGcgVHqS3ejodPN3Rt4t2 rqN/SSKr7gqzQSgsdLpgJ6teGqMoRsscfj1+Lp0seBgpOPxJQSSV/OUgk769SpVtf2 eXrPtMLOYJx0ooModl+ZZ+cgrUmwcQ5NHNTI3ZG1aWpsiN/ulbinxF9QrZR/CjBaIP 1maN5/8qagcGtYvzhj7as2qhuTZwKqTCgySdH3x+fv3WE4P0Wae0h4mvcHV2Y6dGc8 vSAdLRe08MttQeY6sTGneRnUqR1THn67sYlXLiR55fesNYN1SLf535p4CDHr6G2R/6 HqoVNbNvUC9gQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Reply-To: sashiko-reviews@lists.linux.dev To: "Andrew Stellman" Cc: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org In-Reply-To: <20261202165734.51018-4-bugs@stellman-greene.com> References: <20261202165734.51018-1-bugs@stellman-greene.com> <20261202165734.51018-4-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 17:15:20 +0000 X-Mailing-List: target-devel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/is= csi/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 =3D NULL; > - u32 last_statsn; > - int found_cmd; > - > - if (!begrun) { > - begrun =3D 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 =3D READ_ONCE(conn->stat_sn); > + u32 exp_statsn =3D READ_ONCE(conn->exp_statsn); > + u32 sent, offset, count; > + int found_cmd, ret; > + > + if (!begrun && !runlength) { > + if (exp_statsn =3D=3D next_statsn) > + return 0; > + begrun =3D exp_statsn; > } > + sent =3D next_statsn - exp_statsn; > + offset =3D begrun - exp_statsn; > + if (offset >=3D sent || (runlength && runlength > sent - offset)) > + return iscsit_add_reject_keep_conn(conn, > + ISCSI_REASON_PROTOCOL_ERROR, buf); > =20 > - last_statsn =3D (!runlength) ? conn->stat_sn : (begrun + runlength); > + count =3D runlength ? runlength : sent - offset; > =20 > - while (begrun < last_statsn) { > + while (count--) { > found_cmd =3D 0; > =20 > spin_lock_bh(&conn->cmd_lock); > @@ -499,9 +503,9 @@ int iscsit_handle_status_snack( > break; > } > } > - spin_unlock_bh(&conn->cmd_lock); > =20 > 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; > } > =20 > - spin_lock_bh(&cmd->istate_lock); > - if (cmd->i_state =3D=3D 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 !=3D 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 =3D=3D begrun miss the actual ISTATE_SENT_STATUS command and s= kip 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 =3D (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 !=3D ISTATE_SENT_STATUS check drops the SNACK for begrun instead of continuing t= he list search, leaving the initiator to time out waiting for the status retransmission. > cmd->i_state =3D ISTATE_SEND_STATUS_RECOVERY; > - iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); > + ret =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202165734.5101= 8-1-bugs@stellman-greene.com?part=3D3