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=1796307997; b=wOKPdfqeg5ItTBmyVE3I+Q3PXSr9rFyYjZf0zLxzDN6YKkGxinXD2ZdF9gZeF/zunSV8 CtdgtqN5bW6Q7byeS3GBhShKEJXF7ZupiwIui+1LGHoHjXh8MAgO1WVy0kMy8lZ/KeIIj DYQdwA17JiuVQaIdo0PT4LANIU2/cZayHHHs4JauVRpFR/KV6KD2cENrz+cKBaKhzKQQv Ryy62p1KmzpcZHgRbMne1GduplQZLAT2aYkUmEgAL68iVsC35S5YY/KLEeGirL71avrBp fK8rT7BPPobmkE/yXjPclU55x5R3TdJyrOmrgE4vI9GU23yCcJbOIIrPawbGte8YVpQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796307997; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tIhGuckKMsn0mZSk6fx75hMPT9Ej2JKbAF/6Ngggous=; b=QJ2Yb6e5Nf5AdIGyXAwr1Kw4dcJutdsd/pwlZithZ4ymtZs8KQeG7B5OfRQpUeHB7NgI fO/6OFVy7Cnx8k4ln2nIP3RORAxfJ6LPWrkPz8M34hErac4r1HNE+g32O4BwFR+J4MGPQ ZS9utgHb5mFYVdDCYusDAVNxNWsc118ZtVIvdsSDUxQfXjyDM8lWXIOB7wBroAy9HDQQZ 7TXDl0E7+RudpF+FGU5f3g/4EsVfwyAOLODtQo9Cjj93E7cB4C+adx8Z7U4e+EQ4SL/by fr1VMOZpLnm4QxrnUtp+AXwmZNxQK9FW9sDtXUF7ZJHfxiJDYSDKfaCS3qD7EB7idxw== 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=Ezho8bAt; 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 19AFD606A322; Thu, 3 Dec 2026 14:26:37 +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=Ezho8bAt Received: by smtp.kernel.org (Postfix) with ESMTPSA id A23D31F00896; Thu, 3 Dec 2026 14:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796307996; bh=tIhGuckKMsn0mZSk6fx75hMPT9Ej2JKbAF/6Ngggous=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Ezho8bAtTrPWDCzmwDoCnbolN5jdTGJcEyXfekL6jufu9hpJZiUj2XT02+8xUiPrQ yK6zQPF822ly2iLbkwEp5Wd6NJNKDnJNYZz8yh/Y0rRqr4X2sgODe16dCCrQbDujZH K2+rxSuGl3IYqFOo97c1Zr3AAZfU5Dhg40roHKgI5zXTTARVkIJj1ULeA2RT2qEj/G Kw2Fx3TlKWvzB903Y6zNKTJ6wiJpxcxLvz0vUmVPcB+wecJ9wzxI/aXg4NiULsIAXq wQPlRuox9L9/2dIyGfm7SdcipVhiakg1u2W0FYqHxKiOVtO+Pb4NQHfD+3A+noMH2k Ihj8be4Zh6q9g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] scsi: target: iscsi: reject Text data on a continuation request Reply-To: sashiko-reviews@lists.linux.dev To: "James Sawyer" Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org In-Reply-To: <20261203-iscsi-text-double-listadd-v3-1-75dd3ef9ce30@jamessawyer.co.uk> References: <20261203-iscsi-text-double-listadd-v3-1-75dd3ef9ce30@jamessawyer.co.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 14:26:36 +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 2 potential issues to consider: - [Critical] scsi: target: iscsi: iscsit_setup_text_cmd() hijacks live cmd on reject - [High] scsi: target: iscsi: early Text reject leaves unread TCP payload -- commit 16b6a243b5153b553b7782bb0663c15e0f491e40 Author: James Sawyer scsi: target: iscsi: reject Text data on a continuation request This commit adds a check in iscsit_setup_text_cmd() to reject Text Requests that carry a non-zero payload when TTT !=3D 0xFFFFFFFF, before the rest of iscsit_setup_text_cmd() updates the looked-up command. > diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/i= scsi_target.c > index 124ff269b8e75..d33b563ee83eb 100644 > --- a/drivers/target/iscsi/iscsi_target.c > +++ b/drivers/target/iscsi/iscsi_target.c > @@ -2172,6 +2172,20 @@ iscsit_setup_text_cmd(struct iscsit_conn *conn, st= ruct iscsit_cmd *cmd, > (unsigned char *)hdr); > } > =20 > + /* > + * A Text Request with TTT !=3D 0xFFFFFFFF continues an earlier > + * SendTargets response and reuses the command found by ITT, which is > + * still linked on conn_cmd_list. Such a continuation must be empty. > + * Reject one that carries data here, before the looked-up command is > + * mutated, rather than process a new request on it. > + */ > + if (hdr->ttt !=3D cpu_to_be32(0xFFFFFFFF) && payload_length) { > + pr_err("Text data on a continuation request is not supported, TTT: 0x%= 08x\n", > + be32_to_cpu(hdr->ttt)); > + return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, > + (unsigned char *)hdr); > + } [Severity: Critical] Does passing the looked-up cmd to iscsit_reject_cmd() really leave it untouched? When hdr->ttt !=3D 0xFFFFFFFF, all three transports obtain cmd via iscsit_find_cmd_from_itt(), which returns any live command on conn->conn_cmd_list matching that ITT regardless of opcode or state. iscsit_reject_cmd() calls iscsit_add_reject_from_cmd(), which mutates it: drivers/target/iscsi/iscsi_target.c:iscsit_add_reject_from_cmd() { ... const bool do_put =3D cmd->se_cmd.se_tfo !=3D NULL; ... cmd->buf_ptr =3D kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL); if (!cmd->buf_ptr) { ... iscsit_free_cmd(cmd, false); return -1; } ... cmd->i_state =3D ISTATE_SEND_REJECT; iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); if (do_put) { ... target_put_sess_cmd(&cmd->se_cmd); } } If the ITT matches an active SCSI or TMR command, target_put_sess_cmd() drops a reference it does not own, causing a use-after-free while target core and conn->conn_cmd_list still reference cmd. Overwriting cmd->buf_ptr also leaks any existing buffer (such as a SendTargets response), and if TX is concurrently running iscsit_send_text_rsp() it can read text_length bytes past the 48-byte allocation. On OOM, iscsit_free_cmd(cmd, false) frees a linked cmd. Writing cmd->i_state without cmd->istate_lock and queueing a second response entry can also race with iscsit_ack_from_expstatsn() freeing cmd with check_queues false, leaving a use-after-free on response_queue_list. Finally, iscsit_build_reject() ORs ISCSI_FLAG_CMD_FINAL into the reused header without zeroing it, leaving stale ISCSI_FLAG_TEXT_CONTINUE set. On iSER this prevents isert_put_cmd() from releasing cmd, and isert_put_reject() reuses isert_cmd->tx_desc while a send may be active. Rejecting a data-carrying continuation with a newly allocated reject command (or closing the connection) instead of reusing cmd would leave the looked-up command untouched. [Severity: High] Can returning early here leave the Text payload unread on the TCP socket? On TCP, iscsit_get_rx_pdu() reads only the 48-byte BHS header before calling iscsit_handle_text_cmd(), leaving ALIGN(payload_length, 4) bytes (plus optional DataDigest) unread until rx_data(). When this check triggers, payload_length is non-zero, yet the error return is swallowed: drivers/target/iscsi/iscsi_target.c:iscsit_handle_text_cmd() { ... rc =3D iscsit_setup_text_cmd(conn, cmd, hdr); if (rc < 0) return 0; ... } Because iscsi_target_rx_opcode() then returns 0, iscsit_get_rx_pdu() continues its loop and parses the unread Text payload bytes as the next iSCSI PDU header, desynchronizing the TCP stream and keeping the connection open for repeated pr_err() log flooding and buffer leaks. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-iscsi-text= -double-listadd-v3-1-75dd3ef9ce30@jamessawyer.co.uk?part=3D1