* [PATCH v3 0/2] scsi: target: iscsi: SendTargets reject fixes
@ 2026-12-04 18:43 Andrew Stellman
2026-12-04 18:43 ` [PATCH v3 1/2] scsi: target: iscsi: Fix leak of a Text command rejected for invalid SendTargets Andrew Stellman
2026-12-04 18:43 ` [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions Andrew Stellman
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Mike Christie, Dmitry Bogdanov, target-devel, linux-scsi
From: Andrew Stellman <astellman@stellman-greene.com>
Patch 1 fixes the leak that the Sashiko review of v1 found, without
changing when the connection closes. Patch 2 rejects SendTargets=All
on Normal sessions, including an empty Text request that reuses a NOP-Out's
ITT, which the Sashiko review of v2 found.
Andrew Stellman (2):
scsi: target: iscsi: Fix leak of a Text command rejected for invalid
SendTargets
scsi: target: iscsi: Reject SendTargets=All on Normal sessions
---
v2: https://lore.kernel.org/r/20261204054735.45435-1-bugs@stellman-greene.com/
v1: https://lore.kernel.org/r/20261130063456.58615-1-bugs@stellman-greene.com/
Applies to v7.4-rc5.
drivers/target/iscsi/iscsi_target.c | 8 ++++++++
1 file changed, 8 insertions(+)
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 1/2] scsi: target: iscsi: Fix leak of a Text command rejected for invalid SendTargets 2026-12-04 18:43 [PATCH v3 0/2] scsi: target: iscsi: SendTargets reject fixes Andrew Stellman @ 2026-12-04 18:43 ` Andrew Stellman 2026-12-04 18:43 ` [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions Andrew Stellman 1 sibling, 0 replies; 4+ messages in thread From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw) To: Martin K. Petersen Cc: Mike Christie, Dmitry Bogdanov, target-devel, linux-scsi From: Andrew Stellman <astellman@stellman-greene.com> iscsit_process_text_cmd() rejects an invalid SendTargets value with iscsit_reject_cmd(), which doesn't add the new Text command to the connection's command list, so the command and its Reject header leak: ten immediate SendTargets=Bogus requests left 20 unreferenced objects in kmemleak. Use iscsit_add_reject_cmd() for a new command (TTT 0xffffffff), so it's listed and freed. The leak was found by the Sashiko review of v1: https://sashiko.dev/#/patchset/20261130063456.58615-1-bugs@stellman-greene.com?part=1 The fix and this changelog were drafted with OpenAI GPT-6 (Codex), Claude Opus 5.5 and Claude Sonnet 5.5 and reviewed by me. Fixes: 9864ca9d27f7 ("iscsi-target: Move sendtargets parsing into iscsit_process_text_cmd") Signed-off-by: Andrew Stellman <astellman@stellman-greene.com> --- v3: no change. v2: https://lore.kernel.org/r/20261204054735.45435-2-bugs@stellman-greene.com/ v1: https://lore.kernel.org/r/20261130063456.58615-1-bugs@stellman-greene.com/ Tested on v7.4-rc5 (fe6ff8d5d675) in arm64 QEMU with KASAN and kmemleak: after ten immediate SendTargets=Bogus requests, the second scan found 20 objects without this patch and none with it. A reproducer is available on request. drivers/target/iscsi/iscsi_target.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 2b4956f46c13..7bf4a3b0998f 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -2226,6 +2226,9 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, return iscsit_execute_cmd(cmd, 0); reject: + if (hdr->ttt == cpu_to_be32(0xffffffff)) + return iscsit_add_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, + (unsigned char *)hdr); return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, (unsigned char *)hdr); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions 2026-12-04 18:43 [PATCH v3 0/2] scsi: target: iscsi: SendTargets reject fixes Andrew Stellman 2026-12-04 18:43 ` [PATCH v3 1/2] scsi: target: iscsi: Fix leak of a Text command rejected for invalid SendTargets Andrew Stellman @ 2026-12-04 18:43 ` Andrew Stellman 2026-12-04 19:20 ` sashiko-bot 1 sibling, 1 reply; 4+ messages in thread From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw) To: Martin K. Petersen Cc: Mike Christie, Dmitry Bogdanov, target-devel, linux-scsi From: Andrew Stellman <astellman@stellman-greene.com> RFC 7143 Appendix C disallows SendTargets=All on an operational session, but iscsit_process_text_cmd() accepts it on a Normal session and can return the target names that session's ACL can see. An empty Text request that reuses a NOP-Out's ITT reaches the same response. Reject SendTargets=All, and an empty Text request without a named target, on Normal sessions. Such requests are now rejected and return no target names. The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool: https://github.com/andrewstellman/quality-playbook The empty-Text path was found by the Sashiko review of v2: https://sashiko.dev/#/patchset/20261204054735.45435-1-bugs@stellman-greene.com?part=2 The fix was drafted with OpenAI GPT-6 (Codex), this changelog with OpenAI GPT-6 (Codex) and Claude Opus 5.5, and both were reviewed by me. Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1") Fixes: e4f4e8016e68 ("iscsi/iser-target: Support multi-sequence sendtargets text response") Signed-off-by: Andrew Stellman <astellman@stellman-greene.com> --- v3: Also reject the empty-Text path on Normal sessions. v2: https://lore.kernel.org/r/20261204054735.45435-3-bugs@stellman-greene.com/ v1: https://lore.kernel.org/r/20261130063456.58615-1-bugs@stellman-greene.com/ Tested on v7.4-rc5 (fe6ff8d5d675) in arm64 QEMU with KASAN: a NOP-Out followed by an empty Text with the same ITT returned two target names on v2 and closed the connection with no names on v3. A reproducer is available on request. drivers/target/iscsi/iscsi_target.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 7bf4a3b0998f..133fc4f0d9bb 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -2186,6 +2186,9 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, " discovery\n"); goto reject; } + if (!conn->sess->sess_ops->SessionType && + !(cmd->cmd_flags & ICF_SENDTARGETS_SINGLE)) + goto reject; goto empty_sendtargets; } if (strncmp("SendTargets=", text_in, 12) != 0) { @@ -2197,6 +2200,8 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, text_ptr = strchr(text_in, '='); BUG_ON(!text_ptr); if (!strncmp("=All", text_ptr, 5)) { + if (!conn->sess->sess_ops->SessionType) + goto reject; cmd->cmd_flags |= ICF_SENDTARGETS_ALL; } else if (!strncmp("=iqn.", text_ptr, 5) || !strncmp("=eui.", text_ptr, 5)) { -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions 2026-12-04 18:43 ` [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions Andrew Stellman @ 2026-12-04 19:20 ` sashiko-bot 0 siblings, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-12-04 19:20 UTC (permalink / raw) To: Andrew Stellman; +Cc: target-devel, linux-scsi Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Critical] scsi: target: iscsi: UAF when rejecting Text PDU reusing SCSI or TMR ITT - [Critical] scsi: target: iscsi: buf_ptr leak and TX OOB read on reused NOP-Out ITT -- commit b14aaa98ccafd0087fcc5c1540989f44bd35234f Author: Andrew Stellman <astellman@stellman-greene.com> scsi: target: iscsi: Reject SendTargets=All on Normal sessions This commit rejects SendTargets=All and empty Text requests without ICF_SENDTARGETS_SINGLE in iscsit_process_text_cmd() when running on a Normal session. > diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c > index 7bf4a3b0998fb..133fc4f0d9bbb 100644 > --- a/drivers/target/iscsi/iscsi_target.c > +++ b/drivers/target/iscsi/iscsi_target.c > @@ -2186,6 +2186,9 @@ iscsit_process_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, > " discovery\n"); > goto reject; > } > + if (!conn->sess->sess_ops->SessionType && > + !(cmd->cmd_flags & ICF_SENDTARGETS_SINGLE)) > + goto reject; > goto empty_sendtargets; > } > if (strncmp("SendTargets=", text_in, 12) != 0) { [Severity: Critical] Can this reject path cause a use-after-free on cmd and cmd->buf_ptr when an empty Text PDU reuses the ITT of a SCSI command? For hdr->ttt != 0xffffffff, iscsi_target_rx_opcode() (and the iSER and cxgbit RX paths) looks up cmd with iscsit_find_cmd_from_itt() without checking cmd->iscsi_opcode or cmd->targ_xfer_tag. Routing that command to reject calls iscsit_reject_cmd() -> iscsit_add_reject_from_cmd(). Because cmd->se_cmd.se_tfo is non-NULL, iscsit_add_reject_from_cmd() queues cmd on conn->response_queue_list and calls target_put_sess_cmd(&cmd->se_cmd). For a completed SCSI command awaiting ExpStatSN (cmd_kref == 1 after lio_check_stop_free()), that drops cmd_kref to 0 and runs iscsit_release_cmd() while cmd is still queued for TX and linked on conn->conn_cmd_list. Freeing cmd->buf_ptr and returning cmd to the session tag pool causes a use-after-free in iscsit_send_reject(), followed by a refcount underflow and double free in iscsit_release_commands_from_conn(). Earlier, iscsit_setup_text_cmd() also overwrites cmd->data_direction with DMA_NONE, causing SCSI WRITE teardown to skip stopping cmd->dataout_timer and freeing cmd_r2t_list. Rejecting non-0xffffffff TTT Text PDUs with iscsit_add_reject() before iscsit_setup_text_cmd() when the looked-up command is not an ISCSI_OP_TEXT with matching targ_xfer_tag would avoid mutating foreign commands. [Severity: Critical] Does rejecting an empty Text PDU that reuses a NOP-Out ITT leak cmd->buf_ptr and allow an out-of-bounds read in iscsit_send_nopin()? When a NOP-Out carries ping data, iscsit_handle_nop_out() stores it in cmd->buf_ptr and cmd->buf_ptr_size and queues ISTATE_SEND_NOPIN. If a pipelined empty Text PDU reuses that ITT on a Normal session, iscsit_add_reject_from_cmd() overwrites cmd->buf_ptr with a 48-byte kmemdup() without freeing the ping_data buffer or updating cmd->buf_ptr_size: RX thread TX thread iscsit_handle_nop_out() cmd->buf_ptr = ping_data cmd->buf_ptr_size = 4096 queue ISTATE_SEND_NOPIN iscsit_process_text_cmd() iscsit_add_reject_from_cmd() cmd->buf_ptr = kmemdup(..., 48) iscsit_send_nopin() iscsit_xmit_pdu(..., cmd->buf_ptr, cmd->buf_ptr_size) <-- slab out-of-bounds read The old ping_data buffer is leaked, and when cmd->buf_ptr_size exceeds 48 bytes, iscsit_send_nopin() reads past the reject header and sends adjacent kernel heap memory over the network. In addition, iscsit_add_reject_from_cmd() updates cmd->i_state without cmd->istate_lock, racing with iscsit_response_queue(). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204184309.70952-1-bugs@stellman-greene.com?part=2 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 19:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-04 18:43 [PATCH v3 0/2] scsi: target: iscsi: SendTargets reject fixes Andrew Stellman 2026-12-04 18:43 ` [PATCH v3 1/2] scsi: target: iscsi: Fix leak of a Text command rejected for invalid SendTargets Andrew Stellman 2026-12-04 18:43 ` [PATCH v3 2/2] scsi: target: iscsi: Reject SendTargets=All on Normal sessions Andrew Stellman 2026-12-04 19:20 ` sashiko-bot
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.