Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH scsi-fixes] scsi: target: iscsi: Fix the Discovery session opcode check
@ 2026-11-28 19:17 Andrew Stellman
  2026-11-28 19:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Stellman @ 2026-11-28 19:17 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: target-devel, linux-scsi

From: Andrew Stellman <astellman@stellman-greene.com>

RFC 7143 section 4.3 limits a Discovery session to Text and Logout
requests. The TCP and cxgbit receive loops check this with bit tests,
which pass any opcode with bit 0x04 set, so a Data-Out PDU (0x05) sent
in a Discovery session passes the check and reaches the Data-Out
handler.

Compare the masked opcode with ISCSI_OP_TEXT and ISCSI_OP_LOGOUT
instead. This changes existing behaviour: in a Discovery session,
Data-Out and the other opcodes with bit 0x04 set now take the existing
illegal-opcode reject path. Normal sessions are not affected.

Tested over TCP on mainline in an arm64 QEMU guest. Before the fix, a
Data-Out sent after a Discovery login reached the ITT lookup in the
Data-Out handler; with the fix it was rejected at the Discovery check.
A SendTargets Text request got a Text Response in both cases. 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")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 drivers/target/iscsi/cxgbit/cxgbit_target.c | 3 +--
 drivers/target/iscsi/iscsi_target.c         | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/target/iscsi/cxgbit/cxgbit_target.c b/drivers/target/iscsi/cxgbit/cxgbit_target.c
index 3698f2eb097e37..79fc3ff458dc34 100644
--- a/drivers/target/iscsi/cxgbit/cxgbit_target.c
+++ b/drivers/target/iscsi/cxgbit/cxgbit_target.c
@@ -1301,8 +1301,7 @@ static int cxgbit_rx_opcode(struct cxgbit_sock *csk)
 	opcode = hdr->opcode & ISCSI_OPCODE_MASK;
 
 	if (conn->sess->sess_ops->SessionType &&
-	    ((!(opcode & ISCSI_OP_TEXT)) ||
-	     (!(opcode & ISCSI_OP_LOGOUT)))) {
+	    opcode != ISCSI_OP_TEXT && opcode != ISCSI_OP_LOGOUT) {
 		pr_err("Received illegal iSCSI Opcode: 0x%02x"
 			" while in Discovery Session, rejecting.\n", opcode);
 		iscsit_add_reject(conn, ISCSI_REASON_PROTOCOL_ERROR,
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 03d618cd767218..dcb4c4a8e829f1 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -4088,8 +4088,7 @@ static void iscsit_get_rx_pdu(struct iscsit_conn *conn)
 		opcode = buffer[0] & ISCSI_OPCODE_MASK;
 
 		if (conn->sess->sess_ops->SessionType &&
-		   ((!(opcode & ISCSI_OP_TEXT)) ||
-		    (!(opcode & ISCSI_OP_LOGOUT)))) {
+		    opcode != ISCSI_OP_TEXT && opcode != ISCSI_OP_LOGOUT) {
 			pr_err("Received illegal iSCSI Opcode: 0x%02x"
 			" while in Discovery Session, rejecting.\n", opcode);
 			iscsit_add_reject(conn, ISCSI_REASON_PROTOCOL_ERROR,
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH scsi-fixes] scsi: target: iscsi: Fix the Discovery session opcode check
  2026-11-28 19:17 [PATCH scsi-fixes] scsi: target: iscsi: Fix the Discovery session opcode check Andrew Stellman
@ 2026-11-28 19:26 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-28 19:26 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:
- [Medium] scsi: target: iscsi: bogus Reject on HeaderDigest error in
  iscsit_get_rx_pdu()
--

commit 1fd1145d67663e7038dd80d77ad570d438916435
Author: Andrew Stellman <astellman@stellman-greene.com>

scsi: target: iscsi: Fix the Discovery session opcode check

This commit replaces the bitwise opcode checks for Discovery sessions in
iscsit_get_rx_pdu() and cxgbit_rx_opcode() with equality checks against
ISCSI_OP_TEXT and ISCSI_OP_LOGOUT.

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 2b4956f46c132..3f56c5495821e 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -4088,8 +4088,7 @@ static void iscsit_get_rx_pdu(struct iscsit_conn *conn)
>  		opcode = buffer[0] & ISCSI_OPCODE_MASK;
>  
>  		if (conn->sess->sess_ops->SessionType &&
> -		   ((!(opcode & ISCSI_OP_TEXT)) ||
> -		    (!(opcode & ISCSI_OP_LOGOUT)))) {
> +		    opcode != ISCSI_OP_TEXT && opcode != ISCSI_OP_LOGOUT) {
>  			pr_err("Received illegal iSCSI Opcode: 0x%02x"
>  			" while in Discovery Session, rejecting.\n", opcode);
>  			iscsit_add_reject(conn, ISCSI_REASON_PROTOCOL_ERROR,

[Severity: Medium]
On a HeaderDigest CRC32C failure in a Discovery session, does this cause
iscsit_get_rx_pdu() to queue a Reject PDU containing the synthetic 0xff
buffer instead of dropping the connection in iscsi_target_rx_opcode()?

Just above this check, the HeaderDigest error path overwrites buffer:

drivers/target/iscsi/iscsi_target.c:iscsit_get_rx_pdu() {
    ...
			if (digest != checksum) {
				pr_err("HeaderDigest CRC32C failed,"
					" received 0x%08x, computed 0x%08x\n",
					digest, checksum);
				/*
				 * Set the PDU to 0xff so it will intentionally
				 * hit default in the switch below.
				 */
				memset(buffer, 0xff, ISCSI_HDR_LEN);
				atomic_long_inc(&conn->sess->conn_digest_errors);
    ...
}

Previously, the resulting opcode 0x3f passed the bitwise check (since bit
0x04 was set) and reached the default case in iscsi_target_rx_opcode().
With the equality check, a digest failure in a Discovery session hits this
branch, logs a bogus illegal opcode 0x3f error, and passes the all-0xff
buffer to iscsit_add_reject().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128191735.30260-1-bugs@stellman-greene.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 19:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 19:17 [PATCH scsi-fixes] scsi: target: iscsi: Fix the Discovery session opcode check Andrew Stellman
2026-11-28 19:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox