* [PATCH v4 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes
@ 2026-12-04 18:43 Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Mike Christie, Dmitry Bogdanov, Ziheng Wei, target-devel,
linux-scsi
From: Andrew Stellman <astellman@stellman-greene.com>
Patch 1 queues invalid Data and R2T SNACK Rejects on a separate command
and closes the connection as before. Patch 2 checks their ranges
without u32 wrap. Patch 3 bounds Status SNACKs to sent, unacknowledged
StatSNs and closes on invalid ranges.
The series applies to Linux 7.4-rc5 after this two-patch prerequisite:
https://lore.kernel.org/r/20261202164950.49838-1-bugs@stellman-greene.com
Ziheng Wei's patch also holds cmd_lock while queueing in
iscsit_handle_status_snack(), so it overlaps with 3/3:
https://lore.kernel.org/all/20261130103511.1384218-1-zihengw03@163.com/
---
v4: Drop the keep-connection path after Sashiko's v3 review.
v3: https://lore.kernel.org/r/20261204054748.45560-1-bugs@stellman-greene.com
v2: https://lore.kernel.org/r/20261202165734.51018-1-bugs@stellman-greene.com
v1: https://lore.kernel.org/r/20261130062812.56660-1-bugs@stellman-greene.com
Andrew Stellman (3):
scsi: target: iscsi: Don't drop live command refs on SNACK Reject
scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap
scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
drivers/target/iscsi/iscsi_target.c | 5 +-
drivers/target/iscsi/iscsi_target_erl1.c | 74 +++++++++++++-----------
drivers/target/iscsi/iscsi_target_erl1.h | 5 +-
drivers/target/iscsi/iscsi_target_nego.c | 2 +
4 files changed, 50 insertions(+), 36 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject
2026-12-04 18:43 [PATCH v4 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
@ 2026-12-04 18:43 ` Andrew Stellman
2026-12-04 19:12 ` sashiko-bot
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
2 siblings, 1 reply; 6+ messages in thread
From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Mike Christie, Dmitry Bogdanov, Ziheng Wei, target-devel,
linux-scsi
From: Andrew Stellman <astellman@stellman-greene.com>
Out-of-range Data or R2T SNACKs make iscsit_handle_recovery_datain()
and iscsit_handle_r2t_snack() reject a live SCSI command, dropping its
reference during connection teardown. Queue the Reject on a separate
command and close the connection as before.
The issue was found by OpenAI GPT-6 (Codex) running Quality Playbook,
an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
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: 3e1c81a95f0d ("iscsi-target: Refactor RX PDU logic + export request PDU handling")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v4: Drop the keep-connection path after Sashiko's v3 review.
v3: https://lore.kernel.org/r/20261204054748.45560-2-bugs@stellman-greene.com
v2: https://lore.kernel.org/r/20261202165734.51018-2-bugs@stellman-greene.com
v1: https://lore.kernel.org/r/20261130062812.56660-2-bugs@stellman-greene.com
Tested on Linux 7.4-rc5 plus the two prerequisites in arm64 QEMU with
KASAN, ERL=1 and default_cmdsn_depth=1: a bad Data SNACK got a Reject
and then a refcount underflow before this change; with it, the
connection closed with no Reject and no warning.
A reproducer is available on request.
drivers/target/iscsi/iscsi_target_erl1.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
index 44b851e4a602..20eef05400e6 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.c
+++ b/drivers/target/iscsi/iscsi_target_erl1.c
@@ -129,7 +129,8 @@ static int iscsit_handle_r2t_snack(
" protocol error.\n", cmd->init_task_tag, begrun,
(begrun + runlength), cmd->acked_data_sn);
- return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
+ return iscsit_add_reject(cmd->conn,
+ ISCSI_REASON_PROTOCOL_ERROR, buf);
}
if (runlength) {
@@ -138,7 +139,7 @@ static int iscsit_handle_r2t_snack(
" with BegRun: 0x%08x, RunLength: 0x%08x, exceeds"
" current R2TSN: 0x%08x, protocol error.\n",
cmd->init_task_tag, begrun, runlength, cmd->r2t_sn);
- return iscsit_reject_cmd(cmd,
+ return iscsit_add_reject(cmd->conn,
ISCSI_REASON_BOOKMARK_INVALID, buf);
}
last_r2tsn = (begrun + runlength);
@@ -398,7 +399,8 @@ static int iscsit_handle_recovery_datain(
" protocol error.\n", cmd->init_task_tag, begrun,
(begrun + runlength), cmd->acked_data_sn);
- return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
+ return iscsit_add_reject(conn,
+ ISCSI_REASON_PROTOCOL_ERROR, buf);
}
/*
@@ -409,14 +411,14 @@ static int iscsit_handle_recovery_datain(
pr_err("Initiator requesting BegRun: 0x%08x, RunLength"
": 0x%08x greater than maximum DataSN: 0x%08x.\n",
begrun, runlength, (cmd->data_sn - 1));
- return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_INVALID,
- buf);
+ return iscsit_add_reject(conn,
+ ISCSI_REASON_BOOKMARK_INVALID, buf);
}
dr = iscsit_allocate_datain_req();
if (!dr)
- return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_NO_RESOURCES,
- buf);
+ return iscsit_add_reject(conn,
+ ISCSI_REASON_BOOKMARK_NO_RESOURCES, buf);
dr->data_sn = dr->begrun = begrun;
dr->runlength = runlength;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap
2026-12-04 18:43 [PATCH v4 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
@ 2026-12-04 18:43 ` Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
2 siblings, 0 replies; 6+ messages in thread
From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Mike Christie, Dmitry Bogdanov, Ziheng Wei, target-devel,
linux-scsi
From: Andrew Stellman <astellman@stellman-greene.com>
In iscsit_handle_recovery_datain() and iscsit_handle_r2t_snack(),
BegRun + RunLength wraps in u32, letting a huge range pass the check
against the last DataSN or R2TSN sent. Check the sum in u64 and close
the connection on an invalid range.
The issue was found by Claude Opus 5.5, Claude Sonnet 5.5 and Claude
Haiku 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with OpenAI GPT-6 (Codex) and
reviewed by me.
Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v4: Use the connection-close path from 1/3.
v3: https://lore.kernel.org/r/20261204054748.45560-3-bugs@stellman-greene.com
v2: https://lore.kernel.org/r/20261202165734.51018-3-bugs@stellman-greene.com
v1: https://lore.kernel.org/r/20261130062812.56660-3-bugs@stellman-greene.com
Tested on Linux 7.4-rc5 plus the two prerequisites in arm64 QEMU with
KASAN and ERL=1: before this change a wrapping Data SNACK got Data-In
and a wrapping R2T SNACK got no reply; with it, both closed the
connection, the R2T case after a Reject with reason 0x09.
A reproducer is available on request.
drivers/target/iscsi/iscsi_target_erl1.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
index 20eef05400e6..5d59f409b225 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.c
+++ b/drivers/target/iscsi/iscsi_target_erl1.c
@@ -134,7 +134,7 @@ static int iscsit_handle_r2t_snack(
}
if (runlength) {
- if ((begrun + runlength) > cmd->r2t_sn) {
+ if ((u64)begrun + runlength > cmd->r2t_sn) {
pr_err("Command ITT: 0x%08x received R2T SNACK"
" with BegRun: 0x%08x, RunLength: 0x%08x, exceeds"
" current R2TSN: 0x%08x, protocol error.\n",
@@ -407,7 +407,7 @@ static int iscsit_handle_recovery_datain(
* Make sure BegRun and RunLength in the Data SNACK are sane.
* Note: (cmd->data_sn - 1) will carry the maximum DataSN sent.
*/
- if ((begrun + runlength) > (cmd->data_sn - 1)) {
+ if ((u64)begrun + runlength > (cmd->data_sn - 1)) {
pr_err("Initiator requesting BegRun: 0x%08x, RunLength"
": 0x%08x greater than maximum DataSN: 0x%08x.\n",
begrun, runlength, (cmd->data_sn - 1));
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
2026-12-04 18:43 [PATCH v4 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap Andrew Stellman
@ 2026-12-04 18:43 ` Andrew Stellman
2026-12-04 19:56 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Andrew Stellman @ 2026-12-04 18:43 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Mike Christie, Dmitry Bogdanov, Ziheng Wei, target-devel,
linux-scsi
From: Andrew Stellman <astellman@stellman-greene.com>
iscsit_handle_status_snack() can search beyond sent, unacknowledged
StatSNs, and stale ExpStatSN can move the window back. Initialize and
validate ExpStatSN, bound the range, and queue only sent statuses under
cmd_lock. An out-of-window Status SNACK now closes the connection;
before, it got no reply. A BegRun of 0 with a nonzero RunLength now
means StatSN 0 instead of ExpStatSN.
The issue was found by Claude Opus 5.5, Claude Sonnet 5.5 and Claude
Haiku 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), 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")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v4: Close on an invalid range instead of keeping the connection.
v3: https://lore.kernel.org/r/20261204054748.45560-4-bugs@stellman-greene.com
v2: https://lore.kernel.org/r/20261202165734.51018-4-bugs@stellman-greene.com
v1: https://lore.kernel.org/r/20261130062812.56660-4-bugs@stellman-greene.com
Tested on Linux 7.4-rc5 plus the two prerequisites in arm64 QEMU with
KASAN and ERL=1: an out-of-window Status SNACK got no reply before this
change and closed the connection with it, while a valid Status SNACK
got its SCSI Response resent in both cases.
A reproducer is available on request.
drivers/target/iscsi/iscsi_target.c | 5 ++-
drivers/target/iscsi/iscsi_target_erl1.c | 54 +++++++++++++-----------
drivers/target/iscsi/iscsi_target_erl1.h | 5 ++-
drivers/target/iscsi/iscsi_target_nego.c | 2 +
4 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index a8d44ac00abb..7a6e07b2f521 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -953,6 +953,9 @@ static void iscsit_ack_from_expstatsn(struct iscsit_conn *conn, u32 exp_statsn)
LIST_HEAD(ack_list);
struct iscsit_cmd *cmd, *cmd_p;
+ if (iscsi_sna_lt(exp_statsn, conn->exp_statsn) ||
+ iscsi_sna_gt(exp_statsn, READ_ONCE(conn->stat_sn)))
+ return;
conn->exp_statsn = exp_statsn;
if (conn->sess->sess_ops->RDMAExtensions)
@@ -2549,7 +2552,7 @@ int iscsit_handle_snack(
be32_to_cpu(hdr->begrun),
be32_to_cpu(hdr->runlength));
case ISCSI_FLAG_SNACK_TYPE_STATUS:
- return iscsit_handle_status_snack(conn, hdr->itt,
+ return iscsit_handle_status_snack(conn, buf, hdr->itt,
be32_to_cpu(hdr->ttt),
be32_to_cpu(hdr->begrun), be32_to_cpu(hdr->runlength));
case ISCSI_FLAG_SNACK_TYPE_DATA_ACK:
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
index 5d59f409b225..b4502bdafa0d 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.c
+++ b/drivers/target/iscsi/iscsi_target_erl1.c
@@ -468,28 +468,32 @@ int iscsit_handle_recovery_datain_or_r2t(
/* #warning FIXME: Status SNACK needs to be dependent on OPCODE!!! */
int iscsit_handle_status_snack(
struct iscsit_conn *conn,
+ unsigned char *buf,
itt_t init_task_tag,
u32 targ_xfer_tag,
u32 begrun,
u32 runlength)
{
struct iscsit_cmd *cmd = NULL;
- u32 last_statsn;
- int found_cmd;
-
- if (!begrun) {
- begrun = conn->exp_statsn;
- } else if (conn->exp_statsn > begrun) {
- pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:"
- " 0x%08x but already got ExpStatSN: 0x%08x on CID:"
- " %hu.\n", begrun, runlength, conn->exp_statsn,
- conn->cid);
- return 0;
+ u32 next_statsn = READ_ONCE(conn->stat_sn);
+ u32 exp_statsn = READ_ONCE(conn->exp_statsn);
+ u32 sent, offset, count;
+ int found_cmd, ret;
+
+ if (!begrun && !runlength) {
+ if (exp_statsn == next_statsn)
+ return 0;
+ begrun = exp_statsn;
}
+ sent = next_statsn - exp_statsn;
+ offset = begrun - exp_statsn;
+ if (offset >= sent || (runlength && runlength > sent - offset))
+ return iscsit_add_reject(conn,
+ ISCSI_REASON_PROTOCOL_ERROR, buf);
- last_statsn = (!runlength) ? conn->stat_sn : (begrun + runlength);
+ count = runlength ? runlength : sent - offset;
- while (begrun < last_statsn) {
+ while (count--) {
found_cmd = 0;
spin_lock_bh(&conn->cmd_lock);
@@ -499,9 +503,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"
@@ -510,20 +514,22 @@ 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);
- pr_err("Ignoring Status SNACK for BegRun:"
- " 0x%08x, RunLength: 0x%08x, assuming this was"
- " a protactic SNACK for an untransmitted"
- " StatSN\n", begrun, runlength);
+ spin_lock(&cmd->istate_lock);
+ if (cmd->i_state != ISTATE_SENT_STATUS) {
+ spin_unlock(&cmd->istate_lock);
+ spin_unlock_bh(&conn->cmd_lock);
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);
+ ret = iscsit_add_cmd_to_response_queue(cmd, conn,
+ ISTATE_SEND_STATUS_RECOVERY);
+ if (ret)
+ cmd->i_state = ISTATE_SENT_STATUS;
+ spin_unlock(&cmd->istate_lock);
+ spin_unlock_bh(&conn->cmd_lock);
+ if (ret)
+ return ret;
begrun++;
}
diff --git a/drivers/target/iscsi/iscsi_target_erl1.h b/drivers/target/iscsi/iscsi_target_erl1.h
index 12472eefe559..81e7f7ad6f93 100644
--- a/drivers/target/iscsi/iscsi_target_erl1.h
+++ b/drivers/target/iscsi/iscsi_target_erl1.h
@@ -19,8 +19,9 @@ extern int iscsit_create_recovery_datain_values_datasequenceinorder_no(
struct iscsit_cmd *, struct iscsi_datain_req *);
extern int iscsit_handle_recovery_datain_or_r2t(struct iscsit_conn *, unsigned char *,
itt_t, u32, u32, u32);
-extern int iscsit_handle_status_snack(struct iscsit_conn *, itt_t, u32,
- u32, u32);
+int iscsit_handle_status_snack(struct iscsit_conn *conn, unsigned char *buf,
+ itt_t init_task_tag, u32 targ_xfer_tag,
+ u32 begrun, u32 runlength);
extern int iscsit_handle_data_ack(struct iscsit_conn *, u32, u32, u32);
extern int iscsit_dataout_datapduinorder_no_fbit(struct iscsit_cmd *, struct iscsi_pdu *);
extern int iscsit_recover_dataout_sequence(struct iscsit_cmd *, u32, u32);
diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
index ccd468e26fb9..be79f0f9bfa0 100644
--- a/drivers/target/iscsi/iscsi_target_nego.c
+++ b/drivers/target/iscsi/iscsi_target_nego.c
@@ -356,6 +356,8 @@ static int iscsi_target_do_tx_login_io(struct iscsit_conn *conn, struct iscsi_lo
if (conn->conn_transport->iscsit_put_login_tx(conn, login,
login->rsp_length + padding) < 0)
goto err;
+ if (login->login_complete)
+ conn->exp_statsn = conn->stat_sn;
login->rsp_length = 0;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
@ 2026-12-04 19:12 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04 19:12 UTC (permalink / raw)
To: Andrew Stellman; +Cc: target-devel, linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] iscsi-target: iscsit_add_reject() on SNACK errors can deadlock
iscsi_trx
--
commit 54bafde1d196e0744177a40988397d61290fe45a
Author: Andrew Stellman <astellman@stellman-greene.com>
scsi: target: iscsi: Don't drop live command refs on SNACK Reject
This commit switches the error paths in iscsit_handle_r2t_snack() and
iscsit_handle_recovery_datain() from iscsit_reject_cmd() to
iscsit_add_reject(), so Reject PDUs are queued on a newly allocated command
instead of reusing the live SCSI command.
> diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
> index 44b851e4a602d..20eef05400e69 100644
> --- a/drivers/target/iscsi/iscsi_target_erl1.c
> +++ b/drivers/target/iscsi/iscsi_target_erl1.c
> @@ -129,7 +129,8 @@ static int iscsit_handle_r2t_snack(
> " protocol error.\n", cmd->init_task_tag, begrun,
> (begrun + runlength), cmd->acked_data_sn);
>
> - return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
> + return iscsit_add_reject(cmd->conn,
> + ISCSI_REASON_PROTOCOL_ERROR, buf);
> }
>
> if (runlength) {
> @@ -138,7 +139,7 @@ static int iscsit_handle_r2t_snack(
> " with BegRun: 0x%08x, RunLength: 0x%08x, exceeds"
> " current R2TSN: 0x%08x, protocol error.\n",
> cmd->init_task_tag, begrun, runlength, cmd->r2t_sn);
> - return iscsit_reject_cmd(cmd,
> + return iscsit_add_reject(cmd->conn,
> ISCSI_REASON_BOOKMARK_INVALID, buf);
> }
> last_r2tsn = (begrun + runlength);
> @@ -398,7 +399,8 @@ static int iscsit_handle_recovery_datain(
> " protocol error.\n", cmd->init_task_tag, begrun,
> (begrun + runlength), cmd->acked_data_sn);
>
> - return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
> + return iscsit_add_reject(conn,
> + ISCSI_REASON_PROTOCOL_ERROR, buf);
> }
>
> /*
> @@ -409,14 +411,14 @@ static int iscsit_handle_recovery_datain(
> pr_err("Initiator requesting BegRun: 0x%08x, RunLength"
> ": 0x%08x greater than maximum DataSN: 0x%08x.\n",
> begrun, runlength, (cmd->data_sn - 1));
> - return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_INVALID,
> - buf);
> + return iscsit_add_reject(conn,
> + ISCSI_REASON_BOOKMARK_INVALID, buf);
> }
>
> dr = iscsit_allocate_datain_req();
> if (!dr)
> - return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_NO_RESOURCES,
> - buf);
> + return iscsit_add_reject(conn,
> + ISCSI_REASON_BOOKMARK_NO_RESOURCES, buf);
>
> dr->data_sn = dr->begrun = begrun;
> dr->runlength = runlength;
[Severity: High]
Can calling iscsit_add_reject() on these SNACK error paths deadlock the
iscsi_trx thread?
Previously, iscsit_reject_cmd() reused cmd without allocating a session tag.
iscsit_add_reject() calls iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE),
which sleeps in iscsit_wait_for_tag() when se_sess->sess_tag_pool is empty.
With ErrorRecoveryLevel >= 1, a remote initiator can keep ExpStatSN fixed
and fill se_sess->sess_tag_pool with ISTATE_SENT_STATUS commands (one
completed SCSI read plus immediate NOP-OUTs with non-reserved ITTs, which
bypass CmdSN checks).
If the initiator then sends an out-of-range Data or R2T SNACK for that
read's ITT, iscsi_target_rx_opcode() dispatches ISCSI_OP_SNACK without
calling iscsit_ack_from_expstatsn(). iscsi_trx then blocks in
iscsit_wait_for_tag() waiting for a tag that only iscsi_trx can free.
When conn->nopin_timer fires, iscsit_add_nopin() fails on the empty tag pool
without starting nopin_response_timer or re-arming nopin_timer. The
connection and session stay wedged indefinitely, holding the socket and all
session tags until an administrator forces teardown.
Using TASK_RUNNING in iscsit_add_reject() (which already returns -1 to tear
down the connection when allocation fails) would avoid blocking iscsi_trx.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184320.71059-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
@ 2026-12-04 19:56 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04 19:56 UTC (permalink / raw)
To: Andrew Stellman; +Cc: target-devel, linux-scsi
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] scsi: target: iscsi: Status SNACK count unbounded via reused
Text cmds
- [Medium] scsi: target: iscsi: premature loop break in
iscsit_handle_status_snack()
- [Medium] scsi: target: iscsi: iscsit_handle_status_snack() skips
in-flight status
- [Medium] scsi: target: iscsi: iscsit_handle_status_snack() rejects
BegRun == stat_sn
- [Low] scsi: target: iscsi: missing WRITE_ONCE() on TX conn->stat_sn
increments
--
commit b28038ae70262f93815219794ab32a2dc9108ee1
Author: Andrew Stellman <astellman@stellman-greene.com>
scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs
This commit initializes conn->exp_statsn at login completion, validates
ExpStatSN updates against the sent StatSN window, bounds Status SNACK
ranges to unacknowledged StatSNs, and holds conn->cmd_lock while
requeueing sent statuses for recovery.
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 2b4956f46c132..5e46c6e2dc2dd 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -951,6 +951,9 @@ static void iscsit_ack_from_expstatsn(struct iscsit_conn *conn, u32 exp_statsn)
> LIST_HEAD(ack_list);
> struct iscsit_cmd *cmd, *cmd_p;
>
> + if (iscsi_sna_lt(exp_statsn, conn->exp_statsn) ||
> + iscsi_sna_gt(exp_statsn, READ_ONCE(conn->stat_sn)))
> + return;
> conn->exp_statsn = exp_statsn;
[Severity: Low]
Should the TX-side increments of conn->stat_sn also use WRITE_ONCE()?
This patch adds lockless READ_ONCE(conn->stat_sn) on the RX thread here
and in iscsit_handle_status_snack(), while the concurrent TX-thread
increments in iscsit_build_rsp_pdu() (and the other response builders in
iscsi_target.c and cxgbit_tx_datain_iso()) still do plain conn->stat_sn++.
That leaves a KCSAN data race on the RX/TX hot path.
[ ... ]
> diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c
> index 5d59f409b2256..b4502bdafa0df 100644
> --- a/drivers/target/iscsi/iscsi_target_erl1.c
> +++ b/drivers/target/iscsi/iscsi_target_erl1.c
> @@ -468,28 +468,32 @@ int iscsit_handle_recovery_datain_or_r2t(
> /* #warning FIXME: Status SNACK needs to be dependent on OPCODE!!! */
> int iscsit_handle_status_snack(
> struct iscsit_conn *conn,
> + unsigned char *buf,
> itt_t init_task_tag,
> u32 targ_xfer_tag,
> u32 begrun,
> u32 runlength)
> {
> struct iscsit_cmd *cmd = NULL;
> - u32 last_statsn;
> - int found_cmd;
> -
> - if (!begrun) {
> - begrun = conn->exp_statsn;
> - } else if (conn->exp_statsn > begrun) {
> - pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:"
> - " 0x%08x but already got ExpStatSN: 0x%08x on CID:"
> - " %hu.\n", begrun, runlength, conn->exp_statsn,
> - conn->cid);
> - return 0;
> + u32 next_statsn = READ_ONCE(conn->stat_sn);
> + u32 exp_statsn = READ_ONCE(conn->exp_statsn);
> + u32 sent, offset, count;
> + int found_cmd, ret;
> +
> + if (!begrun && !runlength) {
> + if (exp_statsn == next_statsn)
> + return 0;
> + begrun = exp_statsn;
> }
> + sent = next_statsn - exp_statsn;
> + offset = begrun - exp_statsn;
> + if (offset >= sent || (runlength && runlength > sent - offset))
> + return iscsit_add_reject(conn,
> + ISCSI_REASON_PROTOCOL_ERROR, buf);
[Severity: Medium]
Can offset >= sent reject a valid Status SNACK when begrun equals
next_statsn and runlength is 0?
Because conn->stat_sn is randomly seeded, an initiator sending an
explicit BegRun = ExpStatSN (equal to conn->stat_sn) with RunLength = 0
when no unacknowledged statuses exist skips the !begrun && !runlength
branch and hits offset == sent. iscsit_add_reject() then returns -1 and
iscsit_get_rx_pdu() tears down the connection instead of returning 0 with
nothing to resend.
Changing offset >= sent to offset > sent allows offset == sent with
runlength == 0 to produce count == 0 (while still rejecting nonzero
runlength) and removes the need for the exp_statsn == next_statsn check.
> - last_statsn = (!runlength) ? conn->stat_sn : (begrun + runlength);
> + count = runlength ? runlength : sent - offset;
>
> - while (begrun < last_statsn) {
> + while (count--) {
[Severity: High]
Can a remote initiator still make count arbitrarily large by reusing a
Text command?
In iscsi_target_rx_opcode(), an immediate empty ISCSI_OP_TEXT PDU with
ttt != 0xFFFFFFFF reuses an existing iscsit_cmd on conn->conn_cmd_list
without consuming a session tag, and iscsit_build_text_rsp() increments
conn->stat_sn++ on each response while overwriting cmd->stat_sn. With
ExpStatSN held fixed, next_statsn - exp_statsn can grow well past the
command depth.
A single 48-byte Status SNACK with BegRun = 0 and RunLength = 0 then runs
count iterations scanning conn->conn_cmd_list under
spin_lock_bh(&conn->cmd_lock) with no cond_resched() and prints an
unratelimited pr_err() for every missing StatSN, repeatable on each
subsequent SNACK to starve CPU and flood the kernel log. Scanning
conn->conn_cmd_list once for StatSNs in [begrun, begrun + count) (or
capping count and ratelimiting pr_err()) would avoid this.
Separately, the new iscsi_sna_gt() check in iscsit_ack_from_expstatsn()
also wraps and drops valid ExpStatSN updates if conn->stat_sn advances
more than 2^31 + 1 ahead of conn->exp_statsn.
> found_cmd = 0;
>
> spin_lock_bh(&conn->cmd_lock);
> @@ -499,9 +503,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"
> @@ -510,20 +514,22 @@ 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);
> - pr_err("Ignoring Status SNACK for BegRun:"
> - " 0x%08x, RunLength: 0x%08x, assuming this was"
> - " a protactic SNACK for an untransmitted"
> - " StatSN\n", begrun, runlength);
> + spin_lock(&cmd->istate_lock);
> + if (cmd->i_state != ISTATE_SENT_STATUS) {
> + spin_unlock(&cmd->istate_lock);
> + spin_unlock_bh(&conn->cmd_lock);
> begrun++;
> continue;
> }
[Severity: Medium]
Can breaking out of the conn->conn_cmd_list scan before checking
cmd->i_state skip a valid StatSN?
An earlier in-flight command allocated by iscsit_allocate_cmd() has
cmd->stat_sn == 0 until status transmission, and an unsolicited NOP-In
keepalive in ISTATE_SENT_NOPIN_WANT_RESPONSE copies conn->stat_sn in
iscsit_build_nopin_rsp() without incrementing it. In either case the
loop breaks on the non-ISTATE_SENT_STATUS entry, skips begrun, and
silently fails to retransmit the later command's status, stalling
initiator error recovery.
Reading cmd->stat_sn before taking cmd->istate_lock also races with
concurrent TX-thread assignment of cmd->stat_sn. Acquiring
cmd->istate_lock inside the list_for_each_entry() loop and matching
cmd->i_state == ISTATE_SENT_STATUS && cmd->stat_sn == begrun (as
iscsit_ack_from_expstatsn() does) avoids both problems.
[Severity: Medium]
Can checking cmd->i_state != ISTATE_SENT_STATUS silently drop a Status
SNACK for an already-transmitted status PDU?
The TX thread advances conn->stat_sn and transmits the status PDU before
updating cmd->i_state to ISTATE_SENT_STATUS:
TX thread RX thread
iscsit_response_queue()
iscsit_send_response()
iscsit_build_rsp_pdu()
cmd->stat_sn = conn->stat_sn++
iscsit_xmit_pdu()
iscsit_handle_status_snack()
next_statsn = READ_ONCE(conn->stat_sn)
...
cmd->i_state != ISTATE_SENT_STATUS
<-- skips status, returns 0
spin_lock_bh(&cmd->istate_lock)
cmd->i_state = ISTATE_SENT_STATUS
spin_unlock_bh(&cmd->istate_lock)
If the initiator sees a digest error on that PDU and its Status SNACK
arrives in this window, iscsit_handle_status_snack() accepts the range
but skips cmd while it is still in ISTATE_SEND_STATUS. The SNACK is then
lost and recovery stalls until a command timeout or connection recovery.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184320.71059-1-bugs@stellman-greene.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-04 19:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:43 [PATCH v4 scsi-fixes 0/3] scsi: target: iscsi: SNACK Reject and range fixes Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 1/3] scsi: target: iscsi: Don't drop live command refs on SNACK Reject Andrew Stellman
2026-12-04 19:12 ` sashiko-bot
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 2/3] scsi: target: iscsi: Check Data and R2T SNACK ranges without wrap Andrew Stellman
2026-12-04 18:43 ` [PATCH v4 scsi-fixes 3/3] scsi: target: iscsi: Bound Status SNACKs to unacknowledged StatSNs Andrew Stellman
2026-12-04 19:56 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox