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

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