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=1796020962; b=YOW/y9wlnNxQRcdHPS+5VjZx6+4reF4CTigmIS1M+ePDhjQWVQeJkb7PzKrLShn4tPNf qEqnbyfK1ItdzRA4+u3mB5QsiP6sVcqgAdnr61oJe5bNYbSNEId9bxJ08I1ryIhawwqRQ U2PGZuKfad5hhmjDmVwa/L7i/M7D1omRlQNWDgt8fgqmotRvsOKgfUV5rehQBVwbBXAK5 9V3ep0Bp2m2eB6ZnOoA8rCeuEDm1L/qn3INYUo3ZH/3CLVPOJxZavhchhf9MrTXM8vBR0 0GWkB0Fi5ZaCUCQ2akAu9W0nj3Q0/I/me3iQ1/3un/KPR46qbPFS4HWjhXepnCxH4kQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020962; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bQZlC5KGYyN8wok8rrpxvphuhZdAvQVvGXEVfPncbNo=; b=I00hCWR+KN2+HSYMWY+6Fuw9xMBfEpHjL45oO4+viJcCkhzJon00d3lne8AA8VryTWDK GjnSCDtXAhiumriMsdPmtGb0CYxcTgckYyyn0cuj21ZQ15z15p0OoVlWuICHvZyK9aHeH N+WrTBI22lUmI5auSnFsnFaXd9nUFEGM4uMpoSkCP9H7DwJ3feRkv+I6e3Uw1312kiNCO z55CaswJVwT2z3/nGWx2JQTJOeqCVMi8u+KJ3Xjsoo7mBpGQv9jHss9s+Zp5oTaApwsQq a4WFPe8l193wXVt6ekM4Qc2698D5gw5OuVVvXGyZyPCPBkI+ZTYdiWVa425udWtqPyw== 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=ClBH5rYc; 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 5262A606A31C; Mon, 30 Nov 2026 06:42:42 +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=ClBH5rYc Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBDFD1F00896; Mon, 30 Nov 2026 06:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796020962; bh=bQZlC5KGYyN8wok8rrpxvphuhZdAvQVvGXEVfPncbNo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ClBH5rYcg8uMmK+ha1VCrYZyQJmqGSzgplZjztZSN3m4NAqJ11ADqHpSqZKADk7Jm soQEwCgKFrwgKIqzXh1YE8wH3uEz4Y42d8ZPmV8+SFzzVzHo/wF3ResqaYDlc/pA3w MVltRa94t7Pg1g1L/sYIJ2v/fyufVeHQ6SNDLet+2U4/eV13ENmd8KvoShrVltaJ7t aj5s1/wm9ctUM3F3GKFQlMWK7B2r1MuYwRjVvHPZmsPcWpt+gMkEM5981gXJD+uqLe oWg2cITp0ysduN2HX7IaLuX0LEidOJ+hUfpl/c+yqnnJDZo6kaPuxf5kwSsh8mlcd2 ix4c+GYP3z1cw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH scsi-fixes 3/3] scsi: target: iscsi: Reject Status SNACKs beyond sent 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: <20261130062812.56660-4-bugs@stellman-greene.com> References: <20261130062812.56660-1-bugs@stellman-greene.com> <20261130062812.56660-4-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 06:42:41 +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: - [Medium] scsi: target: iscsi: wrong initial_stat_sn and exp_statsn in Status SNACK - [Medium] scsi: target: iscsi: Status SNACK bounded by initial_stat_sn not exp_statsn - [Medium] scsi: target: iscsi: non-wrapping StatSN comparisons in Status SNACK handler - [Medium] scsi: target: iscsi: unlocked multi-read of conn->stat_sn in Status SNACK - [Low] scsi: target: iscsi: exp_statsn > begrun skips Reject in Status SNACK handler -- commit 5a8324fc6b642a7631e331d3ec3152304756fdfa Author: Andrew Stellman scsi: target: iscsi: Reject Status SNACKs beyond sent StatSNs This commit saves the connection's initial StatSN at login and rejects Status SNACK requests whose range falls outside the StatSNs sent on the connection with a Protocol Error Reject PDU. > diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/is= csi/iscsi_target_erl1.c > index 3562e9ad5e4c8..542467dd5960d 100644 > --- a/drivers/target/iscsi/iscsi_target_erl1.c > +++ b/drivers/target/iscsi/iscsi_target_erl1.c > @@ -468,6 +468,7 @@ 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, > @@ -475,8 +476,12 @@ int iscsit_handle_status_snack( > { > struct iscsit_cmd *cmd =3D NULL; > u32 last_statsn; > + u32 sent, offset; > int found_cmd; > =20 > + if (!begrun && !runlength && conn->exp_statsn =3D=3D conn->stat_sn) > + return 0; > + > if (!begrun) { > begrun =3D conn->exp_statsn; > } else if (conn->exp_statsn > begrun) { > @@ -486,6 +491,11 @@ int iscsit_handle_status_snack( > conn->cid); > return 0; > } > + sent =3D conn->stat_sn - conn->initial_stat_sn; > + offset =3D begrun - conn->initial_stat_sn; > + if (offset >=3D sent || (runlength && runlength > sent - offset)) > + return iscsit_add_reject_keep_conn(conn, > + ISCSI_REASON_PROTOCOL_ERROR, buf); [Severity: Low] Does returning 0 on conn->exp_statsn > begrun before checking sent and offset skip the Reject for out-of-range requests? When 0 < conn->initial_stat_sn <=3D conn->exp_statsn, a non-zero begrun below conn->initial_stat_sn (a StatSN never sent on the connection), or a begrun in [conn->initial_stat_sn, conn->exp_statsn) whose runlength extends past conn->stat_sn, takes the early return 0 instead of sending a Protocol Error Reject. [Severity: Medium] Should the requested range be bounded by conn->exp_statsn rather than conn->initial_stat_sn? iscsit_ack_from_expstatsn() removes and frees acknowledged commands from conn->conn_cmd_list and assigns conn->exp_statsn =3D exp_statsn without checking that exp_statsn moves forward: drivers/target/iscsi/iscsi_target.c:iscsit_ack_from_expstatsn() { ... conn->exp_statsn =3D exp_statsn; spin_lock_bh(&conn->cmd_lock); list_for_each_entry_safe(cmd, cmd_p, &conn->conn_cmd_list, i_conn_node) { spin_lock(&cmd->istate_lock); if ((cmd->i_state =3D=3D ISTATE_SENT_STATUS) && iscsi_sna_lt(cmd->stat_sn, exp_statsn)) { cmd->i_state =3D ISTATE_REMOVE; spin_unlock(&cmd->istate_lock); iscsit_free_cmd(cmd, false); ... } After N responses have been acknowledged and freed, an initiator can send a PDU with hdr->exp_statsn set back to conn->initial_stat_sn followed by a Status SNACK for those N historical StatSNs. That passes both conn->exp_statsn > begrun and the conn->initial_stat_sn bounds check, causing the loop below to walk conn->conn_cmd_list under conn->cmd_lock and log "Unable to find StatSN" for every freed StatSN sent since login. > =20 > last_statsn =3D (!runlength) ? conn->stat_sn : (begrun + runlength); [Severity: Medium] Can reading conn->stat_sn multiple times without a single snapshot race with the TX thread when runlength is 0? The TX thread increments conn->stat_sn when building a response PDU before transmitting it and before setting cmd->i_state to ISTATE_SENT_STATUS: RX thread (iscsit_handle_status_snack) TX thread (iscsit_response_queue) -------------------------------------- --------------------------------- sent =3D conn->stat_sn - conn->initial_stat_sn; if (offset >=3D sent || ...) iscsit_build_rsp_pdu() cmd->stat_sn =3D conn->stat_sn++; last_statsn =3D conn->stat_sn; while (begrun < last_statsn) /* matches in-flight cmd */ cmd->i_state =3D ISTATE_SEND_STATUS_RECOVERY; iscsit_add_cmd_to_response_queue() <-- queued twice while in flight If conn->stat_sn advances between the bounds check and the last_statsn assignment, last_statsn includes the in-flight command whose i_state is still ISTATE_SEND_STATUS, and the RX thread queues it onto conn->response_queue_list a second time. [Severity: Medium] How does this handle 32-bit StatSN wrap-around across 0xffffffff? sent and offset use wrapping u32 subtraction, so a range crossing 0xffffffff -> 0x00000000 passes the new bounds check. However, conn->exp_statsn > begrun and while (begrun < last_statsn) use raw unsigned comparisons rather than serial number arithmetic. When begrun is 0xffffffff and runlength is 1 (or 0 with conn->stat_sn wrapped past 0), last_statsn wraps to 0x00000000 (or conn->stat_sn), so begrun < last_statsn is immediately false and the loop exits without retransmitting the unacknowledged response. Likewise, when conn->exp_statsn is pre-wrap and begrun is post-wrap, conn->exp_statsn > begrun is true and drops a valid SNACK. > diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/i= scsi/iscsi_target_login.c > index c282b6a702968..83e721075f8df 100644 > --- a/drivers/target/iscsi/iscsi_target_login.c > +++ b/drivers/target/iscsi/iscsi_target_login.c > @@ -177,6 +177,7 @@ static int iscsi_login_set_conn_values( > ret =3D get_random_bytes_wait(&conn->stat_sn, sizeof(u32)); > if (unlikely(ret)) > return ret; > + conn->initial_stat_sn =3D conn->stat_sn; [Severity: Medium] Does saving conn->initial_stat_sn before Login Response PDUs are sent, without initializing conn->exp_statsn, cause false Rejects and allow SNACKs for login StatSNs? iscsi_login_set_conn_values() runs on the first Login Request PDU, after which every Login Response PDU increments conn->stat_sn without adding an entry to conn->conn_cmd_list: drivers/target/iscsi/iscsi_target_nego.c:iscsi_target_do_tx_login_io() { ... login_rsp->statsn =3D cpu_to_be32(conn->stat_sn++); ... } When Full Feature Phase begins, conn->stat_sn has advanced past conn->initial_stat_sn by the number of Login Response PDUs sent, while conn->exp_statsn is still 0 until a command calls iscsit_ack_from_expstatsn(). As a result, a Status SNACK with BegRun 0 and RunLength 0 sent right after login sees conn->exp_statsn !=3D conn->stat_sn, sets begrun to 0, and is rejected with ISCSI_REASON_PROTOCOL_ERROR instead of being treated as a no-op. Conversely, a Status SNACK requesting the Login Response StatSNs in [conn->initial_stat_sn, conn->stat_sn) passes the bounds check and logs "Unable to find StatSN". --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130062812.5666= 0-1-bugs@stellman-greene.com?part=3D3