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=1796364658; b=NhI4PSIJvzgpTpjdnUXVTM+vwn2V1Pc6kGK/3pqapQcKOty5Qoq+FpiJU7bTWG0+AUur fDBauJtET8Rf4DeTPf03lDkYO9UdqdEkGQ4CzK84ESKiKg/WmB8uC3BNHkdShoEJZoSY0 ViebV+T7ZfLnE1zaHUF9k25pSDzwFP1mWdXmBHpHolEgRSMjXu7+4Jrsy9mBMz4yjYopc WNcdFov4+T9ua5nsKq9K7DQmNKeQ5iSC2+b8Cfn26lRH0rSOFdooez9237ouE7hwa6Tj+ IqOHuiFS+sZfZ/h/XBgivGUl4mf+HYtExJgOAZJAfRD9PBW2PFuo8e3pk9Arwx2x5wg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364658; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=k12h8wEaVwRvODKHg0AcgJMQf2YdUdIBGDH5V2onhsU=; b=Rq/cvbM1Q6KERqU76Gsgr0rJG8sndXpshW4GrDsgSuEC09lrRX22jMRcSlua7HpGm7IL gat4soyoMgWoftBTEbTS0Optct7OnMwHR186TwZ+suur+6f4DroXTDNoAowE04aOf6MG0 6PdoIUyEKD1KGoTEue3BZCTy8fJjlmAF9KMGpl21SNIKie5CvslZzwxoA3vI+NzeBHjur Z93xt4MBPEciUdGkiE934GTBdi3yUZ8xQCuVE1x7+DZjRIalLuCYj9lSEb4EzAXFYZZT9 C2R5yKRNP6AzhWp6Yc/Xgxc0xqQT8K5AG727Qby+s4+jYDhuhBuGaaXTt3VPYRzyhUA== 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="THi2M/Eu"; 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 21DEB606A322; Fri, 4 Dec 2026 06:10:58 +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=THi2M/Eu Received: by smtp.kernel.org (Postfix) with ESMTPSA id D75DA1F000CE; Fri, 4 Dec 2026 06:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796364658; bh=k12h8wEaVwRvODKHg0AcgJMQf2YdUdIBGDH5V2onhsU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=THi2M/EuWekbAEFCNjd2xPbqu/yvNHA+HvcDYGSrHljOQsSRPfAgGvy1S0k9L49iA ccsuV4toFBSpZ24b/F0ltHB6XfvlSHIkUnLSsFeqBPr3lwE9DXr+7nsO2zN1cqEW71 iFxFvCViC8itm7r30nemNlTXMW8OWmYT+jFnheBsWSjs+OH1XCiITGXrLaaOT73kuR eRpwBZvIlXwLCTnh8n6QbEixMU1pZPdPAq0Wxl/Qxsyjzc4sDfZ+4mx3Pz19xLAn4B c9DB7JbFa3WiOw7iW539QHz0U4UmdoucVqgl5r+Fgxk1Jnn6Kv+UzISAnuLAjoT2ZC rthw8kgNUyFeg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject 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-2-bugs@stellman-greene.com> References: <20261204054748.45560-1-bugs@stellman-greene.com> <20261204054748.45560-2-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:10:57 +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: - [Critical] scsi: target: iscsi: uninitialized ITT/TTT in iscsit_add_reject_common() - [High] scsi: target: iscsi: iscsit_add_reject_keep_conn() can exhaust tags for RX - [Medium] scsi: target: iscsi: uninitialized immediate_cmd on Reject inflates MaxCmdSN - [Medium] scsi: target: iscsi: ignored response-queue error leaks Reject cmd and tag -- commit ff2a609861eafe929213c6e748e480ac3ee02194 Author: Andrew Stellman scsi: target: iscsi: Don't drop live command refs on SNACK Reject This commit introduces iscsit_add_reject_keep_conn() so out-of-range Data and R2T SNACK errors send a Reject on a separate non-blocking command allocation while keeping the connection open, instead of rejecting the live SCSI command. > diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/i= scsi_target.c > index 2b4956f46c132..ffa3432f595c8 100644 > --- a/drivers/target/iscsi/iscsi_target.c > +++ b/drivers/target/iscsi/iscsi_target.c > @@ -784,14 +784,13 @@ static void __exit iscsi_target_cleanup_module(void) > kfree(iscsit_global); > } > =20 > -int iscsit_add_reject( > - struct iscsit_conn *conn, > - u8 reason, > - unsigned char *buf) > +static int iscsit_add_reject_common(struct iscsit_conn *conn, u8 reason, > + unsigned char *buf, bool keep_conn) > { > struct iscsit_cmd *cmd; > =20 > - cmd =3D iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); > + cmd =3D iscsit_allocate_cmd(conn, keep_conn ? TASK_RUNNING : > + TASK_INTERRUPTIBLE); > if (!cmd) > return -1; [Severity: High] Can repeated bad SNACKs still deadlock iscsi_target_rx_thread even with TASK_RUNNING here? Passing TASK_RUNNING only closes the connection on the allocation after se_sess->sess_tag_pool is already empty. Each transmitted Reject stays on conn->conn_cmd_list in ISTATE_SENT_STATUS holding its tag until iscsit_ack_from_expstatsn() runs on the RX thread, and iscsit_handle_snack() never calls it. If an initiator sends enough out-of-range Data or R2T SNACKs to consume the last free tag and then sends a normal PDU such as ISCSI_OP_SCSI_CMD, iscsi_target_rx_opcode() calls iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE) before the handler can call iscsit_ack_from_expstatsn(). The RX thread then sleeps permanently in iscsit_wait_for_tag() waiting for a tag that only it can free. When nopin_timer fires, iscsit_add_nopin() also fails tag allocation and returns without arming nopin_response_timer or re-arming nopin_timer, leaving the connection wedged. [ ... ] > @@ -812,10 +811,21 @@ int iscsit_add_reject( > cmd->i_state =3D ISTATE_SEND_REJECT; > iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); > =20 > - return -1; > + return keep_conn ? 0 : -1; > +} [Severity: Critical] Does leaving cmd->init_task_tag and cmd->targ_xfer_tag zeroed on a live Reject command allow a use-after-free and conn->conn_cmd_list corruption? Unlike iscsit_add_nopin(), which sets RESERVED_ITT and 0xFFFFFFFF, iscsit_add_reject_common() leaves both tags at 0 after iscsit_allocate_cmd(= ). When keep_conn is true, the RX thread keeps reading PDUs while the Reject command stays on conn->conn_cmd_list: RX thread TX thread iscsit_add_reject_keep_conn() list_add_tail(cmd, conn_cmd_list) queue ISTATE_SEND_REJECT iscsit_process_nop_out(ttt=3D0) iscsit_find_cmd_from_ttt(0) queue ISTATE_REMOVE (immed) iscsit_handle_immediate_queue() list_del_init(cmd) iscsit_free_cmd(cmd, false) kfree(cmd->buf_ptr) target_free_tag() iscsit_handle_response_queue() iscsit_send_reject(cmd) xmit cmd->buf_ptr <-- use-after-free Because iscsit_free_cmd() is called with shutdown=3Dfalse, the queued ISTATE_SEND_REJECT stays on conn->response_queue_list and iscsit_send_rejec= t() transmits 48 bytes from freed cmd->buf_ptr (and repeated NOP-Outs with ttt= =3D0 can double free it). Because 0 is also a valid ITT, a Text PDU with itt=3D0 and ttt!=3D0xffffffff matches the Reject command in iscsi_target_rx_opcode() and iscsit_process_text_cmd() re-adds cmd->i_conn_node to conn->conn_cmd_list, corrupting the list. Initializing cmd->init_task_tag =3D RESERVED_ITT and cmd->targ_xfer_tag =3D 0xFFFFFFFF before linking cmd onto conn->conn_cmd_list would avoid both. [Severity: Medium] Can leaving cmd->immediate_cmd at 0 on a live Reject command inflate sess->max_cmd_sn beyond the session CmdSN window? A target-generated Reject never consumed an initiator CmdSN, yet iscsit_add_reject_common() leaves cmd->immediate_cmd and cmd->maxcmdsn_inc at 0. If a Status SNACK matches the Reject's StatSN, iscsit_handle_status_snack() matches it without checking cmd->iscsi_opcode. That queues ISTATE_SEND_STATUS_RECOVERY, causing iscsit_build_rsp_pdu() to send a bogus ISCSI_OP_SCSI_CMD_RSP and call iscsit_increment_maxcmdsn(). iscsit_release_commands_from_conn() also increments sess->max_cmd_sn for unacknowledged Rejects on connection teardown in a multi-connection session. Setting cmd->immediate_cmd =3D 1 here and skipping ISCSI_OP_REJECT in iscsit_handle_status_snack() would prevent both. [Severity: Medium] If iscsit_add_cmd_to_response_queue() returns -ENOMEM when keep_conn is tru= e, does this leak cmd, cmd->buf_ptr, and the session tag? iscsit_add_cmd_to_response_queue() uses GFP_ATOMIC, which is already under pressure when iscsit_handle_recovery_datain() calls this after iscsit_allocate_datain_req() fails. Ignoring -ENOMEM leaves cmd stranded on conn->conn_cmd_list in ISTATE_SEND_REJECT, never reaped until teardown. Checking the return value and unlinking and freeing cmd (returning -1) on failure would avoid silently dropping the Reject and leaking the tag. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204054748.4556= 0-1-bugs@stellman-greene.com?part=3D1