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=1796364399; b=BCPjYhN5sEtZVbL2znnCNQs4mmzhqvYxulgBmyQz5tGP4UHh6Y5t/yToYkXMnbygjRup 1Sbwh9K/VJmD+Xf/kKLiDymmzLtmhwxGmOFuRJ8ss0MgPSatWGt7dWz32q2v50788k9id Td1Ym6OuG2y3Rl7pSoHvUXNc99sLoWPYQOUd/GYahYKMilgyDsp1Vl63h+YDniHiE8ztm xeAvsZWf86TLDmvJi58p+AVHpCmow1ZxY8Dymydajd8wl9TnvhSoKAjxxxBlVsp/wdBVm bVe1oxTTTE69ZeR8QmKdmvEz0Fn1hESoGjCSfzz0q+JGc+j5bjA3uCS9aIeD2FAo6OA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364399; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=D9TTJ9AvzmBfNloxQb0kA6n7oYd57skv+uAGNGAzfVM=; b=04/D0Mhbm55BfSe2OqrLA8rryrB3DucQB3rPDgzi+P8k3Y8UB0VV87lJaDczpHT/SZaU PhFpb+0l2vE9fuZjzWG8DoPt4z5hxo7ZHVjfq87GIwFTizdDBm5IkwUSZ0nw2tC2aK7xB H6M+SQGdTWydQEC92KslKfxPffvb0CDpuQ79NTKlItR+anf8XdBq9I62ZW+Qtj5dCIL7H DFxXCYFdAdn9AaQmNcj5E8Zri8bh+MNuA0iAUTnTLTldRSVYGZRlG+S6N/2tFk8dxJSgY eQOGNRGugj81By0SBVZpnsv0dcCvpXrfL1zD6btsVSyKASk1GhOeHgYEHUNoAw+Z11g== 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=NkZhdEm8; 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 1F1E7606A698; Fri, 4 Dec 2026 06:06:39 +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=NkZhdEm8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D01E11F000CE; Fri, 4 Dec 2026 06:06:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796364399; bh=D9TTJ9AvzmBfNloxQb0kA6n7oYd57skv+uAGNGAzfVM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NkZhdEm8dPEtlWq8z5ne6EmyoLQui+eDCMgvZeTdUCgH4i30k/6f9B8hBrh9mRkzQ HxhzBT5SCqRaaIODeEYboPCPybgj0Qk2tqA+w8ESUn4YRTjhB3y1nIQkox7Dp+L4k9 eSAvpZN4XSO84+BVJ9YDQ5pw+gbWdESIbF/RFlNXy0z7qqH8svPcgslSfNyuQpX1aE h2DbaYFPDJyai4DEzPCZyTIuYdosZhgMbdK2DHCqYyxL2SjSg9aZLrA7FDZAHava5r ROvo50wKBT2Ojekox/wL8hmVugBrLhBhtekfcQVUGePsYkIMWnU+gWUbeTe+v8nDJI HDxchZt4q18qg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 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: <20261204054748.45560-4-bugs@stellman-greene.com> References: <20261204054748.45560-1-bugs@stellman-greene.com> <20261204054748.45560-4-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:06:38 +0000 X-Mailing-List: linux-scsi@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 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 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 completio= n, 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/i= scsi_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_c= onn *conn, u32 exp_statsn) > LIST_HEAD(ack_list); > struct iscsit_cmd *cmd, *cmd_p; > =20 > + if (iscsi_sna_lt(exp_statsn, conn->exp_statsn) || > + iscsi_sna_gt(exp_statsn, READ_ONCE(conn->stat_sn))) > + return; > conn->exp_statsn =3D exp_statsn; > =20 > 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 loc= k, which causes an unmarked data race under KCSAN on active connections. [ ... ] > 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 [ ... ] > + 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); [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 =3D 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 =3D=3D begrun) { > found_cmd =3D 1; > break; > } > } [ ... ] > + 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 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 !=3D 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 checki= ng cmd->i_state =3D=3D ISTATE_SENT_STATUS && cmd->stat_sn =3D=3D begrun (as iscsit_ack_from_expstatsn() does) avoids both issues. > 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 here resend non-SCSI responses = as bogus SCSI Response PDUs? In iscsit_response_queue(), non-SCSI responses including ISCSI_OP_REJECT fr= om 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204054748.4556= 0-1-bugs@stellman-greene.com?part=3D3