wzcheng99 239f8e52bc T2 ckpt 10 follow-up: EDTL/CDB pre-flight + strict R2T TTT
Architect review findings 2026-04-21 (ckpt 10 Medium):

#1 EDTL trusted before CDB validation (memory amplification)
    collectWriteData allocated make([]byte, edtl) and issued R2T
    for the full EDTL before SCSIHandler ran the CDB's transfer-
    length check. A hostile peer could advertise a huge EDTL on
    a tiny WRITE(10) CDB to force an outsized buffer + R2T +
    Data-Out collection before rejection.

    Fix in session.handleSCSICmd: compute the CDB-authoritative
    expected byte count (cdbExpectedWriteBytes for WRITE(10))
    BEFORE entering collectWriteData. Mismatched EDTL returns
    CHECK CONDITION + SenseIllegalRequest + ASCInvalidFieldInCDB
    without any allocation or R2T. Unrecognized write opcodes
    fall through to the handler's own validation path.

#2 R2T-solicited Data-Out accepted TTT=0xFFFFFFFF
    collectWriteData had `|| pdu.TTT != 0xFFFFFFFF` exception
    that silently admitted the unsolicited marker after the
    target had issued an explicit R2T with TTT=1. Weakened the
    InitialR2T=Yes "solicited-only" discipline.

    Fix in collectWriteData: remove the 0xFFFFFFFF exception.
    Data-Out MUST echo the R2T's TTT exactly. Comment updated
    to explain why.

Low: narrowed the read-side comment on sendDataInWithStatus /
     handleSCSICmd to reflect the actual T2 ckpt 10 scope
     (single Data-In PDU with S-bit; read splitting deferred
     until an OS initiator exposes the need).

core/frontend/iscsi/t2_ckpt10_hardening_test.go (NEW, sw regression)

  TestT2Route_ISCSI_LargeWrite_EDTLCDBMismatch_RejectsWithoutAllocating:
    Builds a SCSI-Cmd with WRITE(10) transferLen=1 (512 B) but
    EDTL=128 MiB. Asserts:
      - Target reply opcode != R2T  (no R2T issued)
      - Target reply opcode == SCSI-Response with CHECK CONDITION
      - Sense key == IllegalRequest; ASC == InvalidFieldInCDB
      - Round-trip fits within 2s (no 128 MiB allocation attempt)
      - Backend.Write invocation count == 0 (pre-flight reject
        never reaches the handler)
    Uses a custom countingBackend wrapping RecordingBackend to
    pin the "backend never invoked" invariant.

  TestT2Route_ISCSI_LargeWrite_WrongTTT_OnDataOut_Rejected:
    4-block write; 1 block immediate, 3 blocks solicited. Reads
    the R2T, then sends Data-Out with TTT=0xFFFFFFFF (the
    unsolicited marker) instead of echoing the R2T's TTT.
    Asserts:
      - Next read from the client side surfaces an error (target
        closed the session)
      - Backend WriteCount == 0
    Pins the stop-rule: no silent weakening of the negotiated
    solicited-only discipline.

Tests green (no regressions):
  core/frontend/iscsi: 74 tests (was 72; +2 hardening regressions)
  All other packages:  unchanged.

Stop-rule audit: fixes stay inside ckpt 9/10 allowlist. No new
auth/digest/storage/authority paths, no stale W/R semantics
weakened.

Not addressed in this commit (documentation drift, QA-owned):
  - The QA audit file header on t2_v2port_qa_test.go still
    claims V3 "does not implement R2T" which became stale after
    ckpt 10. sw cannot modify a QA-owned file without Discovery
    Bridge — flagged to QA Owner for header update.
2026-04-21 22:52:34 -07:00
Languages
Go 84.5%
Rust 7.9%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%