Skip to contentSkip to conversation

scsi: target: iscsi: fix stalled aborted WRITE commands

PATCH Superseded Laurence Oberman 2 participants 7 messages Oct 14 – Oct 16

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover scsi: target: iscsi: fix stalled aborted WRITE commands

These two patches apply on top of
commit d5869dae5080 ("scsi: target: iscsi: Fix hang for aborted WRITE_PENDING commands").

A WRITE command that is still in TRANSPORT_WRITE_PENDING has never been passed to the backend, so when a TMR aborts it the iSCSI fabric is the one that has to complete it. That commit fixed the case where the final DataOut PDU for an already-issued R2T arrives after the abort. Two more paths can leave such a command with nothing to complete it:

- Patch 1 is the hang this work started from. A WRITE that arrives with immediate data, aborted after that data has been received but before the first R2T is built, is never completed by anything: no R2T has been sent so the initiator cannot send more data, and no DataOut timer is armed so the ERL=0 timeout cannot fire either. core_tmr_lun_reset() then blocks for as long as the connection stays up.

- Patch 2 closes the equivalent window where a new R2T would have been sent for an already-aborted command.

Patch 1 also adds a one-shot completion claim. Completing the command in iscsit_execute_cmd() introduces a second site which iscsit_release_commands_from_conn() would also complete during connection teardown, because t_state is still TRANSPORT_WRITE_PENDING there and target_complete_cmd() on an aborted command records nothing that would say otherwise. The claim makes sure only one of them does it.

How this was found and tested:

The hang was reported against an Oracle RAC cluster on two-session iSCSI LIO targets, where one node's LUN_RESET aborts WRITEs belonging to the other node's session. It was not reproducible in a lab, so the diagnosis came from instrumented kernels in the reporter's environment, logging every site that completes or waits on an aborted command.

Across two hosts every stall had the identical signature given in patch 1, and the stall only ever ended when the initiator gave up and dropped the connection. 217 of 222 LUN_RESET drains completed in under a second; the rest took 46 to 54 seconds, which is where the hung-task panics came from. One 53.7 second stall recovered on its own and the host ran for a further 19 hours.

Both patches, backported to a 5.14-based distro kernel, have since run 300 reset cycles with no hang, in two independent runs: one instrumented and one with the tracing removed. The same reproducer previously failed at 95 and 196 cycles. The code here is equivalent to what was tested; only comments differ.

One thing to flag for review: patch 2's window was never observed. The instrumented kernels recorded no completions at that site in either run, and the reproducer never reached it. It is included because the same reasoning applies there, but it has no field evidence behind it, and I am happy to drop it or send it separately if you would prefer.

An earlier attempt at this fix completed the command from core_tmr_drain_state_list() instead. That is not safe: at that point the initiator may still be sending DataOut for the command, and the result was a double completion -- re-queued se_cmd->work, list_del corruption and a refcount underflow. Mentioning it in case the same idea comes up in review.

Laurence Oberman (2):
scsi: target: iscsi: Complete an aborted WRITE stuck before the first

    R2T

scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be
sent

 drivers/target/iscsi/iscsi_target.c      | 31 ++++++++++++++--
 drivers/target/iscsi/iscsi_target_erl1.c | 10 +++++-
 drivers/target/iscsi/iscsi_target_util.c | 46 ++++++++++++++++++++++++
 drivers/target/iscsi/iscsi_target_util.h |  2 ++
 include/target/iscsi/iscsi_target_core.h |  5 +++
 5 files changed, 91 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T

A WRITE that arrives with immediate data, and whose data length exceeds FirstBurstLength, is left in TRANSPORT_WRITE_PENDING by iscsit_execute_cmd() until the first R2T is built. If a LUN_RESET or ABORT_TASK from another session sets CMD_T_ABORTED in that window, iscsit_execute_cmd() returns without sending the R2T.

Nothing then completes the command. No R2T has been sent, so the initiator cannot legally send more data; no DataOut timer was armed, so the ERL=0 timeout cannot fire either. The command stays in TRANSPORT_WRITE_PENDING with CMD_T_ABORTED set, and core_tmr_drain_state_list() blocks in target_put_cmd_and_wait() on it for as long as the connection stays up:

  INFO: task kworker/5:2 blocked for more than 46 seconds.
   target_put_cmd_and_wait+0x6d/0xb0 [target_core_mod]
   core_tmr_drain_state_list+0x2dc/0x380 [target_core_mod]
   core_tmr_lun_reset+0x93/0x1a0 [target_core_mod]

Complete it in iscsit_execute_cmd() instead. No DataOut path can race with this: without an R2T the initiator cannot send further data for the command, and the branch is only reached when no unsolicited DataOut is expected either.

That introduces a second site which can complete a command that iscsit_release_commands_from_conn() would also complete during connection teardown, because t_state is still TRANSPORT_WRITE_PENDING there. target_complete_cmd() on a command that already has CMD_T_ABORTED set goes straight into target_cmd_interrupted(), which queues target_abort_work and returns without setting CMD_T_COMPLETE and without changing t_state, so nothing in target core records that a completion has happened. A second target_complete_cmd() re-initialises and re-queues se_cmd->work while it is still queued and drops a command reference that was never taken. Add a one-shot claim, taken under se_cmd->t_state_lock, so that only one of the two sites completes the command.

This was reported against an Oracle RAC cluster on two-session iSCSI LIO targets, where one node's LUN_RESET aborts WRITEs belonging to the other node's session. It was not reproducible in a lab, so the diagnosis came from instrumented kernels in the reporter's environment. Across two hosts, every stalled command had the same signature: DMA_TO_DEVICE, TRANSPORT_WRITE_PENDING, CMD_T_ABORTED | CMD_T_TAS, outstanding_r2ts == 0, write_data_done == first_burst_len, and an empty cmd_r2t_list. 217 of 222 LUN_RESET drains completed in under a second; the rest took 46 to 54 seconds, which is where the hung-task panics came from. One 53.7 second stall recovered on its own and the host ran for a further 19 hours. The stall only ever ended when the initiator gave up and dropped the connection, which let iscsit_release_commands_from_conn() complete the command.

Assisted-by Claude LLM
---
 drivers/target/iscsi/iscsi_target.c      | 12 +++++--
 drivers/target/iscsi/iscsi_target_erl1.c | 10 +++++-
 drivers/target/iscsi/iscsi_target_util.c | 46 ++++++++++++++++++++++++
 drivers/target/iscsi/iscsi_target_util.h |  2 ++
 include/target/iscsi/iscsi_target_core.h |  5 +++
 5 files changed, 72 insertions(+), 3 deletions(-)
drivers/target/iscsi/iscsi_target.c +10 -2
index 124ff269b8e7..aab9237a6776 100644
@@ -4198,10 +4198,18 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn)
 		if (cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) {
 			/*
 			 * We never submitted the cmd to LIO core, so we have
-			 * to tell LIO to perform the completion process.
+			 * to tell LIO to perform the completion process --
+			 * unless iscsit_execute_cmd() already did.  t_state
+			 * stays TRANSPORT_WRITE_PENDING across that
+			 * completion, so the claim is the only thing that can
+			 * tell us.
 			 */
+			bool claimed = iscsit_claim_completion_locked(cmd);
+
 			spin_unlock_irq(&se_cmd->t_state_lock);
-			target_complete_cmd(&cmd->se_cmd, SAM_STAT_TASK_ABORTED);
+			if (claimed)
+				target_complete_cmd(&cmd->se_cmd,
+						    SAM_STAT_TASK_ABORTED);
 			continue;
 		}
 		spin_unlock_irq(&se_cmd->t_state_lock);
drivers/target/iscsi/iscsi_target_erl1.c +9 -1
index d8ca06e697d6..cf72c79be355 100644
@@ -927,8 +927,16 @@ int iscsit_execute_cmd(struct iscsit_cmd *cmd, int ooo)
 
 			if (!(cmd->cmd_flags &
 					ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
-				if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
+				/*
+				 * No R2T has been sent for this command yet,
+				 * so returning here leaves the initiator with
+				 * nothing to send and no DataOut timer armed.
+				 * Complete it, or nothing ever will.
+				 */
+				if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
+					iscsit_complete_aborted_cmd(cmd);
 					return 0;
+				}
 
 				iscsit_set_dataout_sequence_values(cmd);
 				conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
drivers/target/iscsi/iscsi_target_util.c +46 -0

58 lines not on this page · raw message

drivers/target/iscsi/iscsi_target_util.h +2 -0
index 7ae48a8a5cbf..8f3fe7428428 100644
@@ -18,6 +18,8 @@ extern struct iscsi_r2t *iscsit_get_r2t_from_list(struct iscsit_cmd *);
 extern void iscsit_free_r2t(struct iscsi_r2t *, struct iscsit_cmd *);
 extern void iscsit_free_r2ts_from_list(struct iscsit_cmd *);
 extern struct iscsit_cmd *iscsit_allocate_cmd(struct iscsit_conn *, int);
+extern bool iscsit_claim_completion_locked(struct iscsit_cmd *cmd);
+extern void iscsit_complete_aborted_cmd(struct iscsit_cmd *cmd);
 extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsit_cmd *, u32);
 extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsit_cmd *);
 extern struct iscsi_r2t *iscsit_get_holder_for_r2tsn(struct iscsit_cmd *, u32);
include/target/iscsi/iscsi_target_core.h +5 -0
index 51ca80abacf7..0707a9520810 100644
@@ -496,6 +496,11 @@ struct iscsit_cmd {
 	u32			first_data_sg_off;
 	u32			kmapped_nents;
 	sense_reason_t		sense_reason;
+	/*
+	 * Set once the fabric has called target_complete_cmd() for this
+	 * command.  Protected by se_cmd.t_state_lock.
+	 */
+	bool			completion_claimed;
 }  ____cacheline_aligned;
 
 struct iscsi_tmr_req {
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH 1/2] scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] iscsi: double completion and workqueue corruption for aborted WRITEs on DataOut path --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iscsi: double completion and workqueue corruption for aborted WRITEs on DataOut path --

commit 7b04f6989363db2c2b75d8c212ee852153982c8d
Author: Laurence Oberman <[email protected]>

scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T

This patch resolves an issue where an aborted WRITE command that arrives with immediate data exceeding FirstBurstLength gets stuck in TRANSPORT_WRITE_PENDING. It accomplishes this by completing the command in iscsit_execute_cmd() and introducing a new iscsit_claim_completion_locked() helper to avoid a double completion race with iscsit_release_commands_from_conn().

Quoted 12 lines
drivers/target/iscsi/iscsi_target.c +3 -1
index 124ff269b8e75..aab9237a67768 100644
@@ -4198,10 +4198,18 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn)
 		if (cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) {
 			/*
 			 * We never submitted the cmd to LIO core, so we have
-			 * to tell LIO to perform the completion process.
+			 * to tell LIO to perform the completion process --
+			 * unless iscsit_execute_cmd() already did.  t_state
+			 * stays TRANSPORT_WRITE_PENDING across that

drivers/target/iscsi/iscsi_target.c static void iscsit_release_commands_from_conn(struct iscsit_conn *conn) · line 4212

Quoted 10 lines
drivers/target/iscsi/iscsi_target.c +7 -1
+			 * completion, so the claim is the only thing that can
+			 * tell us.
 			 */
+			bool claimed = iscsit_claim_completion_locked(cmd);
+
 			spin_unlock_irq(&se_cmd->t_state_lock);
-			target_complete_cmd(&cmd->se_cmd, SAM_STAT_TASK_ABORTED);
+			if (claimed)
+				target_complete_cmd(&cmd->se_cmd,
+						    SAM_STAT_TASK_ABORTED);

[Severity: High]
Does this code miss the DataOut paths?

Because target_complete_cmd() is called directly in __iscsit_check_dataout_hdr() and target_execute_cmd() is called in iscsit_check_dataout_payload() for aborted commands without setting the completion_claimed flag.

If a command is aborted on the DataOut path:

drivers/target/iscsi/iscsi_target.c:__iscsit_check_dataout_hdr() {
    ...
		if (se_cmd->transport_state & CMD_T_ABORTED) {
			if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
			    --cmd->outstanding_r2ts < 1) {
				iscsit_stop_dataout_timer(cmd);
				target_complete_cmd(se_cmd, SAM_STAT_TASK_ABORTED);
			}
    ...
}

Because completion_claimed is never set, target_complete_cmd() delegates to target_cmd_interrupted() which queues target_abort_work but leaves the command in TRANSPORT_WRITE_PENDING.

If the connection drops before target_abort_work removes the command from the connection list, iscsit_release_commands_from_conn() will find it, iscsit_claim_completion_locked() will return true, and it will call target_complete_cmd() a second time.

Can this double call to target_complete_cmd() cause target_cmd_interrupted() to re-initialize and re-queue cmd->work while it is already pending on the workqueue, leading to workqueue linked-list corruption and a use-after-free when target_handle_abort() runs twice?

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

Re: [PATCH 1/2] scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T

Quoted 91 lines · On Wed, 2026-10-14 at 15:10 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iscsi: double completion and workqueue corruption for aborted WRITEs on DataOut path
--

commit 7b04f6989363db2c2b75d8c212ee852153982c8d
Author: Laurence Oberman <[email protected]>

scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T

This patch resolves an issue where an aborted WRITE command that arrives with
immediate data exceeding FirstBurstLength gets stuck in TRANSPORT_WRITE_PENDING.
It accomplishes this by completing the command in iscsit_execute_cmd() and
introducing a new iscsit_claim_completion_locked() helper to avoid a double
completion race with iscsit_release_commands_from_conn().

Quoted 33 lines
drivers/target/iscsi/iscsi_target.c +0 -0
index 124ff269b8e75..aab9237a67768 100644
@@ -4198,10 +4198,18 @@ static void
 iscsit_release_commands_from_conn(struct iscsit_conn *conn)

  if (cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) {
  /*
  * We never submitted the cmd to LIO core, so we have

drivers/target/iscsi/iscsi_target.c +0 -1
-			 * to tell LIO to perform the completion

process.

drivers/target/iscsi/iscsi_target.c +1 -0
+			 * to tell LIO to perform the completion

process --

drivers/target/iscsi/iscsi_target.c +1 -0
+			 * unless iscsit_execute_cmd() already

did.  t_state

drivers/target/iscsi/iscsi_target.c +1 -0
+			 * stays TRANSPORT_WRITE_PENDING across

that

drivers/target/iscsi/iscsi_target.c +1 -0
+			 * completion, so the claim is the only

thing that can

drivers/target/iscsi/iscsi_target.c +1 -0
+			 * tell us.

  */

drivers/target/iscsi/iscsi_target.c +1 -0
+			bool claimed =

iscsit_claim_completion_locked(cmd);
+
  spin_unlock_irq(&se_cmd->t_state_lock);

drivers/target/iscsi/iscsi_target.c +0 -1
-			target_complete_cmd(&cmd->se_cmd,

SAM_STAT_TASK_ABORTED);

drivers/target/iscsi/iscsi_target.c +3 -0
+			if (claimed)
+				target_complete_cmd(&cmd->se_cmd,
+						   
Quoted 1 line

SAM_STAT_TASK_ABORTED);

[Severity: High]
Does this code miss the DataOut paths?

Because target_complete_cmd() is called directly in __iscsit_check_dataout_hdr()
and target_execute_cmd() is called in iscsit_check_dataout_payload() for aborted
commands without setting the completion_claimed flag.

If a command is aborted on the DataOut path:

drivers/target/iscsi/iscsi_target.c:__iscsit_check_dataout_hdr() {
    ...

		if (se_cmd->transport_state & CMD_T_ABORTED) {
			if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
			    --cmd->outstanding_r2ts < 1) {
				iscsit_stop_dataout_timer(cmd);
				target_complete_cmd(se_cmd,
SAM_STAT_TASK_ABORTED);
			}

    ...
}

Because completion_claimed is never set, target_complete_cmd() delegates
to target_cmd_interrupted() which queues target_abort_work but leaves the command in TRANSPORT_WRITE_PENDING.

If the connection drops before target_abort_work removes the command from the connection list, iscsit_release_commands_from_conn() will find it,
iscsit_claim_completion_locked() will return true, and it will call target_complete_cmd() a second time.

Quoted 9 lines

Can this double call to target_complete_cmd() cause target_cmd_interrupted()
to re-initialize and re-queue cmd->work while it is already pending on the
workqueue, leading to workqueue linked-list corruption and a use- after-free
when target_handle_abort() runs twice?

Thanks for the review. I verified the mechanism and it is accurate:
target_cmd_interrupted() queues target_abort_work and returns true, and target_complete_cmd_with_sense() then returns before reaching the "cmd->t_state = TRANSPORT_COMPLETE; cmd->transport_state |= CMD_T_COMPLETE" block. The command is left in TRANSPORT_WRITE_PENDING with nothing recorded to say it has been completed. The window is also not narrow: iscsit_release_commands_from_conn() holds conn->cmd_lock across its entire walk and iscsit_aborted_task() needs that same lock to
unlink, so if the work item has not run yet, teardown is guaranteed to see the command rather than merely likely to.

Your point about target_execute_cmd() is correct as well, and worth spelling out: it calls target_cmd_interrupted() before setting cmd->t_state = TRANSPORT_PROCESSING, so an aborted command taking the DATAOUT_SEND_TO_TRANSPORT path also stays in TRANSPORT_WRITE_PENDING.

However, this exposure is pre-existing rather than introduced here. Mainline at that site today is:

	if (cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) {
		spin_unlock_irq(&se_cmd->t_state_lock);
		target_complete_cmd(&cmd->se_cmd,
SAM_STAT_TASK_ABORTED);
		continue;
	}

The call is unconditional, so a command already completed by __iscsit_check_dataout_hdr() or by target_execute_cmd() is completed a second time by teardown as the code stands. This patch gates that call on the claim, and for a command arriving from either of those paths the claim succeeds, because neither path claims. Behaviour for them is therefore identical to mainline. The only change is that the site this patch adds in iscsit_execute_cmd() can no longer be double-completed.

So the patch removes one reachable double completion and adds none. I would rather not extend it to cover the two pre-existing sites: this series has 300 reset cycles of customer validation behind it on a reproducer that previously failed at 95 and 196 cycles, and widening it would mean shipping code that validation never exercised. I am happy to post a separate patch for the pre-existing paths, on its own merits.

The companion finding against patch 2 is a real defect introduced by this series and I am fixing it in v2.

Thanks
Laurence

#4 lore raw

PATCH 2/2 scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent

In reply to Laurence Oberman

iscsit_check_dataout_payload() hands a command to iscsit_get_dataout() to request the next burst whenever iscsit_check_post_dataout() returns DATAOUT_SEND_R2T, without checking CMD_T_ABORTED first.

If a TMR aborted the command while the burst that just finished was in flight, no further DataOut will arrive: the initiator is about to be told the command was aborted. The CMD_T_ABORTED handling in __iscsit_check_dataout_hdr() does not cover this, because it only runs for DataOut PDUs belonging to R2Ts that were already issued, and outstanding_r2ts has already been decremented to zero for the burst that completed. The command is left in TRANSPORT_WRITE_PENDING with nothing to complete it.

Complete it here instead. Guard on outstanding_r2ts so that with MaxOutstandingR2T > 1 the completion is still left to the last R2T to drain in __iscsit_check_dataout_hdr().

Unlike patch 1 of this series, this window was never observed in the
field: instrumented kernels on two hosts recorded no completions at this site across 300 reset cycles, and the reproducer that triggered the other one never reached it. It is closed by code inspection, for symmetry with the other paths that can leave an aborted WRITE_PENDING command stranded.

Assisted-by Claude LLM
---
 drivers/target/iscsi/iscsi_target.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/target/iscsi/iscsi_target.c +19 -0
index aab9237a6776..87b215b18034 100644
@@ -1669,6 +1669,25 @@ iscsit_check_dataout_payload(struct iscsit_cmd *cmd, struct iscsi_data *hdr,
 	if ((rc == DATAOUT_NORMAL) || (rc == DATAOUT_WITHIN_COMMAND_RECOVERY))
 		return 0;
 	else if (rc == DATAOUT_SEND_R2T) {
+		/*
+		 * A new R2T would never be answered for an aborted command.
+		 * The CMD_T_ABORTED handling in __iscsit_check_dataout_hdr()
+		 * does not cover this: it only runs for DataOut PDUs
+		 * belonging to R2Ts that were already issued, and
+		 * iscsit_dataout_update_r2t() has already decremented
+		 * outstanding_r2ts for the burst that just finished.  Guard
+		 * on outstanding_r2ts so that with MaxOutstandingR2T > 1 the
+		 * completion is still left to the last R2T to drain.
+		 */
+		if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
+			if (cmd->outstanding_r2ts < 1) {
+				iscsit_stop_dataout_timer(cmd);
+				target_complete_cmd(&cmd->se_cmd,
+						    SAM_STAT_TASK_ABORTED);
+			}
+			return 0;
+		}
+
 		iscsit_set_dataout_sequence_values(cmd);
 		conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
 	} else if (rc == DATAOUT_SEND_TO_TRANSPORT) {
Signature · 1 line
2.52.0
#5 lore raw

Re: [PATCH 2/2] scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] iscsi: workqueue corruption via double completion of aborted cmd --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iscsi: workqueue corruption via double completion of aborted cmd --

commit 1cef49db01d5c1eb5e9670fc6f016dfd14ddd5cd
Author: Laurence Oberman <[email protected]>

scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent

iscsit_check_dataout_payload() hands a command to iscsit_get_dataout() to request the next burst whenever iscsit_check_post_dataout() returns DATAOUT_SEND_R2T, without checking CMD_T_ABORTED first. This patch guards for aborted commands by stopping the dataout timer and completing the command.

Quoted 8 lines
drivers/target/iscsi/iscsi_target.c +0 -0
index aab9237a67768..87b215b18034e 100644
@@ -1669,6 +1669,25 @@ iscsit_check_dataout_payload(struct iscsit_cmd *cmd, struct iscsi_data *hdr,
 	if ((rc == DATAOUT_NORMAL) || (rc == DATAOUT_WITHIN_COMMAND_RECOVERY))
 		return 0;
 	else if (rc == DATAOUT_SEND_R2T) {

[ ... ]

drivers/target/iscsi/iscsi_target.c iscsit_check_dataout_payload(struct iscsit_cmd *cmd, struct iscsi_data *hdr, · line 1686

Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +5 -0
+		if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
+			if (cmd->outstanding_r2ts < 1) {
+				iscsit_stop_dataout_timer(cmd);
+				target_complete_cmd(&cmd->se_cmd,
+						    SAM_STAT_TASK_ABORTED);

[Severity: High]
Can calling target_complete_cmd() directly on an aborted command bypass the synchronization wrapper iscsit_complete_aborted_cmd()?

Because this bypasses iscsit_claim_completion_locked(), could concurrent session teardown or other abort paths also claim the command and call target_complete_cmd()?

This concurrent modification could lead to target_cmd_interrupted() executing INIT_WORK(&cmd->work, target_abort_work) and queue_work() concurrently on an already active work item, which might destroy the workqueue linked list.

There is also a preexisting location in the header parsing path that exposes the same unsynchronized completion race, which appears to have been copied here and left unfixed:

drivers/target/iscsi/iscsi_target.c:__iscsit_check_dataout_hdr() {
    ...
		if (se_cmd->transport_state & CMD_T_ABORTED) {
			if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
			    --cmd->outstanding_r2ts < 1) {
				iscsit_stop_dataout_timer(cmd);
				target_complete_cmd(se_cmd, SAM_STAT_TASK_ABORTED);
			}
    ...
}

Would it be safer to use iscsit_complete_aborted_cmd() in both places to ensure the completion is safely claimed?

Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +4 -0
+			}
+			return 0;
+		}
+
 		iscsit_set_dataout_sequence_values(cmd);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH 2/2] scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent

Quoted 78 lines · On Wed, 2026-10-14 at 15:00 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iscsi: workqueue corruption via double completion of aborted cmd
--

commit 1cef49db01d5c1eb5e9670fc6f016dfd14ddd5cd
Author: Laurence Oberman <[email protected]>

scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent

iscsit_check_dataout_payload() hands a command to iscsit_get_dataout() to
request the next burst whenever iscsit_check_post_dataout() returns DATAOUT_SEND_R2T, without checking CMD_T_ABORTED first. This patch guards
for aborted commands by stopping the dataout timer and completing the command.

Quoted 11 lines
drivers/target/iscsi/iscsi_target.c +0 -0
index aab9237a67768..87b215b18034e 100644
@@ -1669,6 +1669,25 @@ iscsit_check_dataout_payload(struct
 iscsit_cmd *cmd, struct iscsi_data *hdr,

  if ((rc == DATAOUT_NORMAL) || (rc ==
DATAOUT_WITHIN_COMMAND_RECOVERY))
  return 0;
  else if (rc == DATAOUT_SEND_R2T) {

[ ... ]

Quoted 6 lines
drivers/target/iscsi/iscsi_target.c +5 -0
+		if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
+			if (cmd->outstanding_r2ts < 1) {
+				iscsit_stop_dataout_timer(cmd);
+				target_complete_cmd(&cmd->se_cmd,
+						   

SAM_STAT_TASK_ABORTED);

[Severity: High]
Can calling target_complete_cmd() directly on an aborted command bypass the
synchronization wrapper iscsit_complete_aborted_cmd()?

Because this bypasses iscsit_claim_completion_locked(), could concurrent
session teardown or other abort paths also claim the command and call target_complete_cmd()?

This concurrent modification could lead to target_cmd_interrupted() executing
INIT_WORK(&cmd->work, target_abort_work) and queue_work() concurrently on an
already active work item, which might destroy the workqueue linked list.

There is also a preexisting location in the header parsing path that exposes
the same unsynchronized completion race, which appears to have been copied
here and left unfixed:

drivers/target/iscsi/iscsi_target.c:__iscsit_check_dataout_hdr() {
    ...

		if (se_cmd->transport_state & CMD_T_ABORTED) {
			if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
			    --cmd->outstanding_r2ts < 1) {
				iscsit_stop_dataout_timer(cmd);
				target_complete_cmd(se_cmd,
SAM_STAT_TASK_ABORTED);
			}

    ...
}

Would it be safer to use iscsit_complete_aborted_cmd() in both places to
ensure the completion is safely claimed?

Quoted 5 lines
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +4 -0
+			}
+			return 0;
+		}
+

  iscsit_set_dataout_sequence_values(cmd);

Thanks for the review - you are right, and unlike the companion finding against patch 1 this one is a defect this series introduces rather than inherits.

The new completion in the DATAOUT_SEND_R2T branch calls target_complete_cmd() directly and so never sets completion_claimed. After it runs, the command is still in TRANSPORT_WRITE_PENDING and still
on conn->conn_cmd_list until target_abort_work reaches iscsit_aborted_task(). A connection drop in that window lets iscsit_release_commands_from_conn() claim the command successfully and complete it a second time, which is exactly the sequence you describe.

v2 will route it through iscsit_complete_aborted_cmd():

	if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
		if (cmd->outstanding_r2ts < 1)
			iscsit_complete_aborted_cmd(cmd);
		return 0;
	}

The helper already performs iscsit_stop_dataout_timer() followed by target_complete_cmd(), so the claimed path is unchanged and only the second completion is suppressed. It also gives the helper a second caller, which it should have had in this version.

Worth noting for the record that instrumented kernels logged this site firing zero times across two independent 300-cycle validation runs, so the change does not disturb the path that was actually exercised during testing. The validated fix is the iscsit_execute_cmd() site in patch 1, which v2 leaves alone.

On the pre-existing location in __iscsit_check_dataout_hdr(): I agree it
has the same shape, and the lock context there allows the helper (iscsit_stop_dataout_timer() sleeps at that point, so t_state_lock is already dropped). I would prefer to handle it in a separate patch rather
than fold it into this series - it is a distinct pre-existing race in code this series does not otherwise touch. I have replied on the patch 1 thread with the reasoning.

Thanks
Laurence