From: sashiko-bot@kernel.org
To: "Laurence Oberman" <loberman@redhat.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent
Date: Fri, 16 Oct 2026 18:08:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-174751@kernel.org> (raw)
In-Reply-To: <20261016175351.126373-3-loberman@redhat.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] iscsi: double completion due to incomplete CMD_T_ABORTED fix
- [Medium] iscsi: data race on cmd->outstanding_r2ts during abort
--
commit 538cfb5a3bbcee47d2aa78e30d5cf64fe5bed2fe
Author: Laurence Oberman <loberman@redhat.com>
scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent
This commit adds a check for aborted commands in the DataOut processing
path when a new R2T is requested. It ensures the command is safely
completed using iscsit_complete_aborted_cmd() to claim the completion.
This prevents a race condition where a connection drop could cause a
double-completion of the aborted command.
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index aab9237a67768..3dad7f69f3bae 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1669,6 +1669,22 @@ 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)
[Severity: High]
This patch introduces iscsit_complete_aborted_cmd() to fix a double-completion
race by safely claiming the completion. However, does this still leave two
other paths vulnerable to the same issue?
If cmd->outstanding_r2ts >= 1, the patch explicitly leaves completion to
__iscsit_check_dataout_hdr(). But __iscsit_check_dataout_hdr() uses
target_complete_cmd() directly without claiming the completion:
__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);
}
...
}
Similarly, if the final payload for an aborted command is received in this
function, it reaches DATAOUT_SEND_TO_TRANSPORT and calls target_execute_cmd(),
which also queues the abort work without claiming the completion:
iscsit_check_dataout_payload() {
...
} else if (rc == DATAOUT_SEND_TO_TRANSPORT) {
...
target_execute_cmd(&cmd->se_cmd);
return 0;
...
}
Could a connection drop in either of these windows allow
iscsit_release_commands_from_conn() to complete the command a second time,
resulting in corruption of the target_completion_wq?
[Severity: Medium]
Is it safe to read cmd->outstanding_r2ts without holding cmd->r2t_lock here?
If iscsit_build_r2ts_for_cmd() encounters an allocation failure, the target
core queues the command to qf_work_queue. The worker thread will retry
building the R2T asynchronously via transport_write_pending_qf() ->
iscsit_build_r2ts_for_cmd(), incrementing the counter under cmd->r2t_lock:
iscsit_build_r2ts_for_cmd() {
...
cmd->outstanding_r2ts++;
first_r2t = 0;
if (iscsit_add_r2t_to_list(cmd, offset, xfer_len, 0, 0) < 0) {
...
}
If the command is aborted concurrently, the RX thread processing incoming
DataOut PDUs will locklessly decrement the counter in
__iscsit_check_dataout_hdr() and locklessly read it here. Could this
concurrent non-atomic access cause lost updates, leading to a corrupted
counter and a leaked command?
> + iscsit_complete_aborted_cmd(cmd);
> + return 0;
> + }
> +
> iscsit_set_dataout_sequence_values(cmd);
> conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
> } else if (rc == DATAOUT_SEND_TO_TRANSPORT) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261016175351.126373-1-loberman@redhat.com?part=2
next prev parent reply other threads:[~2026-10-16 18:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 17:53 [PATCH v2 0/2] scsi: target: iscsi: fix stalled aborted WRITE commands Laurence Oberman
2026-10-16 17:53 ` [PATCH v2 1/2] scsi: target: iscsi: Complete an aborted WRITE stuck before the first R2T Laurence Oberman
2026-10-16 17:53 ` [PATCH v2 2/2] scsi: target: iscsi: Complete an aborted WRITE when a new R2T would be sent Laurence Oberman
2026-10-16 18:08 ` sashiko-bot [this message]
2026-10-16 18:19 ` Laurence Oberman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-174751@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.