From: sashiko-bot@kernel.org
To: "Ziheng Wei" <zihengw03@163.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH] scsi: target: iscsi: hold cmd_lock and istate_lock across status SNACK recovery
Date: Mon, 30 Nov 2026 10:49:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-240886@kernel.org> (raw)
In-Reply-To: <20261130103511.1384218-1-zihengw03@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] scsi: target: iscsi: incomplete i_state check in
iscsit_handle_status_snack()
--
commit a8d8126cd528b9066379675b5773847632704322
Author: Ziheng Wei <zihengw03@163.com>
scsi: target: iscsi: hold cmd_lock and istate_lock across status SNACK recovery
This commit holds conn->cmd_lock across cmd->istate_lock and response
queue insertion in iscsit_handle_status_snack(), and rejects commands in
ISTATE_REMOVE to avoid racing with iscsit_ack_from_expstatsn().
> diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
> index d8ca06e697d63..22638e0919af3 100644
> --- a/drivers/target/iscsi/iscsi_target_erl1.c
> +++ b/drivers/target/iscsi/iscsi_target_erl1.c
> @@ -497,9 +497,9 @@ int iscsit_handle_status_snack(
> break;
> }
> }
> - spin_unlock_bh(&conn->cmd_lock);
>
> if (!found_cmd) {
> + spin_unlock_bh(&conn->cmd_lock);
> pr_err("Unable to find StatSN: 0x%08x for"
> " a Status SNACK, assuming this was a"
> " protactic SNACK for an untransmitted"
> @@ -508,9 +508,11 @@ int iscsit_handle_status_snack(
> continue;
> }
>
> - spin_lock_bh(&cmd->istate_lock);
> - if (cmd->i_state == ISTATE_SEND_DATAIN) {
> - spin_unlock_bh(&cmd->istate_lock);
> + spin_lock(&cmd->istate_lock);
> + if (cmd->i_state == ISTATE_SEND_DATAIN ||
> + cmd->i_state == ISTATE_REMOVE) {
> + spin_unlock(&cmd->istate_lock);
> + spin_unlock_bh(&conn->cmd_lock);
> pr_err("Ignoring Status SNACK for BegRun:"
> " 0x%08x, RunLength: 0x%08x, assuming this was"
> " a protactic SNACK for an untransmitted"
> @@ -518,10 +520,12 @@ int iscsit_handle_status_snack(
> begrun++;
> continue;
> }
> - spin_unlock_bh(&cmd->istate_lock);
> -
> cmd->i_state = ISTATE_SEND_STATUS_RECOVERY;
> - iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
> + spin_unlock(&cmd->istate_lock);
> +
> + iscsit_add_cmd_to_response_queue(cmd, conn,
> + ISTATE_SEND_STATUS_RECOVERY);
> + spin_unlock_bh(&conn->cmd_lock);
> begrun++;
> }
[Severity: Critical]
Should this check reject any state where cmd->i_state != ISTATE_SENT_STATUS
instead of only ISTATE_SEND_DATAIN and ISTATE_REMOVE?
Because ISTATE_SEND_STATUS_RECOVERY is not rejected, a second Status SNACK
for the same StatSN before the TX thread drains the first entry queues cmd
onto conn->response_queue_list a second time:
RX thread TX thread
iscsit_handle_status_snack()
cmd->i_state = ISTATE_SEND_STATUS_RECOVERY
iscsit_add_cmd_to_response_queue(cmd, ...) [qr1]
iscsit_handle_status_snack()
/* i_state is ISTATE_SEND_STATUS_RECOVERY */
iscsit_add_cmd_to_response_queue(cmd, ...) [qr2]
iscsit_response_queue() [qr1]
cmd->i_state = ISTATE_SENT_STATUS
iscsit_ack_from_expstatsn()
/* sees ISTATE_SENT_STATUS */
iscsit_free_cmd(cmd, false)
iscsit_response_queue() [qr2]
<-- use-after-free of cmd
When the TX thread completes qr1, iscsit_response_queue() resets
cmd->i_state to ISTATE_SENT_STATUS while qr2 is still queued. A subsequent
PDU advancing ExpStatSN then causes iscsit_ack_from_expstatsn() to call
iscsit_free_cmd(cmd, false), which skips
iscsit_remove_cmd_from_response_queue() and frees cmd while qr2 remains on
conn->response_queue_list.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130103511.1384218-1-zihengw03@163.com?part=1
prev parent reply other threads:[~2026-11-30 10:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:35 [PATCH] scsi: target: iscsi: hold cmd_lock and istate_lock across status SNACK recovery Ziheng Wei
2026-11-30 10:49 ` sashiko-bot [this message]
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-240886@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=target-devel@vger.kernel.org \
--cc=zihengw03@163.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox