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=1796414201; b=YGaP3yXUvc/sVt/nZSHAfxX54w3/AbvgYrVsLb4ady3DK6NhKkOO/Io+J6uKj3AuzASa LndjaqO3d7BvB42PKR8sB0OHQXq0efZpkJ3HVdci2mxqnsLhXE3M13L/7ZvfRJFSdg3UY qEOjYRMtFBADgA8wwteAk6naQ3c066mazw/K6VSeX0om3YCHlEqU+BQgAUJ7BpkpKetN/ KaX81GqhJFvMTGsatZuIW9eoRrbMhbRonTm8b32q9o4WGULjaOorN1Qom+gkjB6SKXu4T Av0aQ2JkMVUVZfN8tspbb3mJlbhATL8zhsa4vKJOvkqWr5WCamRPP7dV673y36PJWvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796414201; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=P0ufok2XSR0/XKm6BtO+3IIFaouI7G9bXeaE9WqGj1E=; b=4QZ52Ps4004Z608yCt1dRf1lcGowHZ6Jq5wpBaJI2MfJx0E45YMfCwFLr/z4eeiApRP8 t8nnYffbSYJ1Xfbdpo2YcguzScOHUJ2MOITnVc3DKh5i4bnspxPKt1+HS4a5yWGSMa3Xo Bps+yrXXSnWZRnPw7kgyfHXcZ0E/A3e2PF0BvWzdw/LT0Cj8FUwvRfwZioImSKvuayo7U 6a2w+tk5S1uRxlxkBglLhkIMIrHzrf9xBPXXrQK4pzNrCos1LnY7efF1W8TVXDJe8qJwz ifO7AJJioVNcbVL/ErRj36f5psGmy5rFMgv+KXzn37IPdR9F/ZvOnVYczcT9pG2QWHg== 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=LT2qA5Cc; 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 BA8F3606A322; Fri, 4 Dec 2026 19:56:41 +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=LT2qA5Cc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AD911F0093B; Fri, 4 Dec 2026 19:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796414201; bh=P0ufok2XSR0/XKm6BtO+3IIFaouI7G9bXeaE9WqGj1E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=LT2qA5Ccz9DdwstYlKmq1e8HnQ1tgL+Z9Ny/gKYmszwKxa3zdgcoslmMfLJZvUklP rLpqxjdgCPBLkJUqj3TNI+5d8y3J7IGACWJzZ7lWTZE8wErEc1XGEteWimEqFMTA7W XWAWfS57hSwQwwEPTvc4FomiBdMlIL+zhE6FJ8mSh2vD6LS/sOgVa5McyNevW3/Emy CmoOFvqL4UDAlZChcziwXlc2lJDtyEcT6U2P7iU/U78EP50Abe/IqZinV3qC/bY8wz UH9HJqi8T2WwM8N9LxdfVsc5Z9KPI6ufbHNCr8hAke8S+hl48nAwRD3RDxyAkkn360 b2/Dg8tm7W11w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 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: <20261204184320.71059-4-bugs@stellman-greene.com> References: <20261204184320.71059-1-bugs@stellman-greene.com> <20261204184320.71059-4-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 19:56:40 +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 5 potential issues to consider: - [High] scsi: target: iscsi: Status SNACK count unbounded via reused Text cmds - [Medium] scsi: target: iscsi: premature loop break in iscsit_handle_status_snack() - [Medium] scsi: target: iscsi: iscsit_handle_status_snack() skips in-flight status - [Medium] scsi: target: iscsi: iscsit_handle_status_snack() rejects BegRun =3D=3D stat_sn - [Low] scsi: target: iscsi: missing WRITE_ONCE() on TX conn->stat_sn increments -- commit b28038ae70262f93815219794ab32a2dc9108ee1 Author: Andrew Stellman scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs This commit initializes conn->exp_statsn at login completion, validates ExpStatSN updates against the sent StatSN window, bounds Status SNACK ranges to unacknowledged StatSNs, and holds conn->cmd_lock while requeueing sent statuses for recovery. > diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/i= scsi_target.c > index 2b4956f46c132..5e46c6e2dc2dd 100644 > --- a/drivers/target/iscsi/iscsi_target.c > +++ b/drivers/target/iscsi/iscsi_target.c > @@ -951,6 +951,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; [Severity: Low] Should the TX-side increments of conn->stat_sn also use WRITE_ONCE()? This patch adds lockless READ_ONCE(conn->stat_sn) on the RX thread here and in iscsit_handle_status_snack(), while the concurrent TX-thread increments in iscsit_build_rsp_pdu() (and the other response builders in iscsi_target.c and cxgbit_tx_datain_iso()) still do plain conn->stat_sn++. That leaves a KCSAN data race on the RX/TX hot path. [ ... ] > diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/is= csi/iscsi_target_erl1.c > index 5d59f409b2256..b4502bdafa0df 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(conn, > + ISCSI_REASON_PROTOCOL_ERROR, buf); [Severity: Medium] Can offset >=3D sent reject a valid Status SNACK when begrun equals next_statsn and runlength is 0? Because conn->stat_sn is randomly seeded, an initiator sending an explicit BegRun =3D ExpStatSN (equal to conn->stat_sn) with RunLength =3D 0 when no unacknowledged statuses exist skips the !begrun && !runlength branch and hits offset =3D=3D sent. iscsit_add_reject() then returns -1 and iscsit_get_rx_pdu() tears down the connection instead of returning 0 with nothing to resend. Changing offset >=3D sent to offset > sent allows offset =3D=3D sent with runlength =3D=3D 0 to produce count =3D=3D 0 (while still rejecting nonzero runlength) and removes the need for the exp_statsn =3D=3D next_statsn check. > - last_statsn =3D (!runlength) ? conn->stat_sn : (begrun + runlength); > + count =3D runlength ? runlength : sent - offset; > =20 > - while (begrun < last_statsn) { > + while (count--) { [Severity: High] Can a remote initiator still make count arbitrarily large by reusing a Text command? In iscsi_target_rx_opcode(), an immediate empty ISCSI_OP_TEXT PDU with ttt !=3D 0xFFFFFFFF reuses an existing iscsit_cmd on conn->conn_cmd_list without consuming a session tag, and iscsit_build_text_rsp() increments conn->stat_sn++ on each response while overwriting cmd->stat_sn. With ExpStatSN held fixed, next_statsn - exp_statsn can grow well past the command depth. A single 48-byte Status SNACK with BegRun =3D 0 and RunLength =3D 0 then ru= ns count iterations scanning conn->conn_cmd_list under spin_lock_bh(&conn->cmd_lock) with no cond_resched() and prints an unratelimited pr_err() for every missing StatSN, repeatable on each subsequent SNACK to starve CPU and flood the kernel log. Scanning conn->conn_cmd_list once for StatSNs in [begrun, begrun + count) (or capping count and ratelimiting pr_err()) would avoid this. Separately, the new iscsi_sna_gt() check in iscsit_ack_from_expstatsn() also wraps and drops valid ExpStatSN updates if conn->stat_sn advances more than 2^31 + 1 ahead of conn->exp_statsn. > 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 scan before checking cmd->i_state skip a valid StatSN? An earlier in-flight command allocated by iscsit_allocate_cmd() has cmd->stat_sn =3D=3D 0 until status transmission, and an unsolicited NOP-In keepalive in ISTATE_SENT_NOPIN_WANT_RESPONSE copies conn->stat_sn in iscsit_build_nopin_rsp() without incrementing it. In either case the loop breaks on the non-ISTATE_SENT_STATUS entry, skips begrun, and silently fails to retransmit the later command's status, stalling initiator error recovery. Reading cmd->stat_sn before taking cmd->istate_lock also races with concurrent TX-thread assignment of cmd->stat_sn. Acquiring cmd->istate_lock inside the list_for_each_entry() loop and matching cmd->i_state =3D=3D ISTATE_SENT_STATUS && cmd->stat_sn =3D=3D begrun (as iscsit_ack_from_expstatsn() does) avoids both problems. [Severity: Medium] Can checking cmd->i_state !=3D ISTATE_SENT_STATUS silently drop a Status SNACK for an already-transmitted status PDU? The TX thread advances conn->stat_sn and transmits the status PDU before updating cmd->i_state to ISTATE_SENT_STATUS: TX thread RX thread iscsit_response_queue() iscsit_send_response() iscsit_build_rsp_pdu() cmd->stat_sn =3D conn->stat_sn++ iscsit_xmit_pdu() iscsit_handle_status_snack() next_statsn =3D READ_ONCE(conn->stat_sn) ... cmd->i_state !=3D ISTATE_SENT_STATUS <-- skips status, returns 0 spin_lock_bh(&cmd->istate_lock) cmd->i_state =3D ISTATE_SENT_STATUS spin_unlock_bh(&cmd->istate_lock) If the initiator sees a digest error on that PDU and its Status SNACK arrives in this window, iscsit_handle_status_snack() accepts the range but skips cmd while it is still in ISTATE_SEND_STATUS. The SNACK is then lost and recovery stalls until a command timeout or connection recovery. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204184320.7105= 9-1-bugs@stellman-greene.com?part=3D3