scsi: target: iscsi: Fix the Discovery session opcode check
Subsystems (2)
PATCH 1/1 scsi: target: iscsi: Fix the Discovery session opcode check
From: Andrew Stellman <[email protected]>
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.
---
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(-)
drivers/target/iscsi/cxgbit/cxgbit_target.c +1 -2
@@ -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,
drivers/target/iscsi/iscsi_target.c +1 -2
@@ -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,
Signature · 1 line
2.53.0
[email protected]
AI reviewThank 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() --
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 <[email protected]>
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.
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c +0
-0
drivers/target/iscsi/iscsi_target.c static void iscsit_get_rx_pdu(struct iscsit_conn *conn) · line 4094
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c +1
-2@@ -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().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1