Skip to contentSkip to conversation

scsi: target: iscsi: Free dropped Text commands on DataDigest errors

PATCH New Andrew Stellman 2 participants 2 messages Nov 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: target: iscsi: Free dropped Text commands on DataDigest errors

From: Andrew Stellman <[email protected]>

At ErrorRecoveryLevel 1 and above, iscsit_handle_text_cmd() and cxgbit_handle_text_cmd() silently drop a Text Request whose DataDigest doesn't match. When the request starts a new exchange (TTT 0xffffffff), the receive path has already allocated a command and a session tag for it, but the drop path returns without linking the command to the connection or freeing it, so each such request leaks the command and its tag.

Free the command on both drop paths when TTT is 0xffffffff, as the NOP-Out DataDigest error path already does. A Text Request that continues an existing exchange uses a command that is already on the connection list, so it's left alone. The PDU is still dropped silently.

Tested over TCP on mainline in an arm64 QEMU guest with KASAN, ERL 1 and DataDigest=CRC32C. Before the fix, after 140 Text Requests with a bad DataDigest the target logged 136 digest errors and a following NOP-Out got no NOP-In within 3 seconds; with the fix it got a NOP-In. The cxgbit change was compiled but not run.

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 fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude Opus 5.5, and both were reviewed by me.

Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Fixes 9730ffcb8957 ("cxgbit: add files for cxgbit.ko")

---
A reproducer is available on request.

 drivers/target/iscsi/cxgbit/cxgbit_target.c | 2 ++
 drivers/target/iscsi/iscsi_target.c         | 2 ++
 2 files changed, 4 insertions(+)
drivers/target/iscsi/cxgbit/cxgbit_target.c +2 -0
index 3698f2eb097e3..b9abc735284ee 100644
@@ -1179,6 +1179,8 @@ cxgbit_handle_text_cmd(struct cxgbit_sock *csk, struct iscsit_cmd *cmd)
 			pr_info("Dropping Text"
 				" Command CmdSN: 0x%08x due to"
 				" DataCRC error.\n", hdr->cmdsn);
+			if (hdr->ttt == cpu_to_be32(0xFFFFFFFF))
+				iscsit_free_cmd(cmd, false);
 			return 0;
 		}
 	}
drivers/target/iscsi/iscsi_target.c +2 -0
index 2b4956f46c132..9810e3dfcc1ce 100644
@@ -2300,6 +2300,8 @@ iscsit_handle_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
 					" DataCRC error.\n", hdr->cmdsn);
 					kfree(text_in);
 					cmd->text_in_ptr = NULL;
+					if (hdr->ttt == cpu_to_be32(0xFFFFFFFF))
+						iscsit_free_cmd(cmd, false);
 					return 0;
 				}
 			} else {
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] scsi: target: iscsi: inaccurate Fixes trailer for iscsit_handle_text_cmd() It also noticed 1 related…

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] scsi: target: iscsi: inaccurate Fixes trailer for iscsit_handle_text_cmd()
It also noticed 1 related pre-existing issue this patch does not introduce:
- [Critical] scsi: target: iscsi: TCP stream desynchronization in non-SCSI handlers [1]
--

commit 3e3312bd41bf89c36eb174a1346bc67aacc6f605
Author: Andrew Stellman <[email protected]>

Quoted 27 lines

scsi: target: iscsi: Free dropped Text commands on DataDigest errors

At ErrorRecoveryLevel 1 and above, iscsit_handle_text_cmd() and cxgbit_handle_text_cmd() silently drop a Text Request whose DataDigest doesn't match. When the request starts a new exchange (TTT 0xffffffff), the receive path has already allocated a command and a session tag for it, but the drop path returns without linking the command to the connection or freeing it, so each such request leaks the command and its tag.

Free the command on both drop paths when TTT is 0xffffffff, as the NOP-Out DataDigest error path already does. A Text Request that continues an existing exchange uses a command that is already on the connection list, so it's left alone. The PDU is still dropped silently.

Tested over TCP on mainline in an arm64 QEMU guest with KASAN, ERL 1 and DataDigest=CRC32C. Before the fix, after 140 Text Requests with a bad DataDigest the target logged 136 digest errors and a following NOP-Out got no NOP-In within 3 seconds; with the fix it got a NOP-In. The cxgbit change was compiled but not run.

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 fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude Opus 5.5, and both were reviewed by me.

Quoted 3 lines
Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Fixes 9730ffcb8957 ("cxgbit: add files for cxgbit.ko")

[Severity: Low]
In commit e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1"), iscsit_handle_text_cmd() validated the DataDigest before calling iscsit_allocate_cmd(), so the ERL >= 1 DataCRC drop path did not leak a command. The leak in iscsit_handle_text_cmd() was introduced when commit 64534aa79496 ("iscsi-target: Refactor ISCSI_OP_TEXT RX handling") hoisted iscsit_allocate_cmd() into iscsi_target_rx_opcode(). Should the first
Fixes: tag be:

Fixes 64534aa79496 ("iscsi-target: Refactor ISCSI_OP_TEXT RX handling")

[ ... ]

drivers/target/iscsi/iscsi_target.c iscsit_handle_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, · line 2307

Quoted 13 lines
drivers/target/iscsi/iscsi_target.c +2 -0
index 2b4956f46c132..9810e3dfcc1ce 100644
@@ -2300,6 +2300,8 @@ iscsit_handle_text_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
 					" DataCRC error.\n", hdr->cmdsn);
 					kfree(text_in);
 					cmd->text_in_ptr = NULL;
+					if (hdr->ttt == cpu_to_be32(0xFFFFFFFF))
+						iscsit_free_cmd(cmd, false);
 					return 0;
 				}
 			} else {

[Severity: Critical]
This problem wasn't introduced by this patch, but can an early failure in iscsit_setup_text_cmd() desynchronize the TCP stream [1]?

drivers/target/iscsi/iscsi_target.c:iscsit_handle_text_cmd() {
	...
	rc = iscsit_setup_text_cmd(conn, cmd, hdr);
	if (rc < 0)
		return 0;

	rx_size = payload_length;
	if (payload_length) {
	...
}

When iscsit_setup_text_cmd() fails on a Text Request carrying a non-zero payload_length (and similarly in iscsit_handle_nop_out() when iscsit_setup_nop_out() fails), the handler returns 0 without reading payload_length bytes from the socket. The RX thread then parses the unread payload as the next iSCSI Basic Header Segment, allowing crafted payload bytes to inject arbitrary PDUs or crash the target.

[1] https://sashiko.dev/#/bug/linux-bc9d46c7-9320-42b5-85cc-7b0a1cddfeb4

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1