Skip to content

Commit fda6a1f

Browse files
bryamzxzmartinkpetersen
authored andcommitted
scsi: target: core: Fix iSCSI ISID use-after-free in REGISTER AND MOVE
core_scsi3_emulate_pro_register_and_move() maps the PERSISTENT RESERVE OUT parameter list with transport_kmap_data_sg() and parses the destination TransportID with target_parse_pr_out_transport_id(). For an iSCSI TransportID (FORMAT CODE 01b), iscsi_parse_pr_out_transport_id() returns the ISID in iport_ptr as a raw pointer into that mapped buffer. The function then unmaps the buffer with transport_kunmap_data_sg() before dereferencing iport_ptr in strcmp(), __core_scsi3_locate_pr_reg() and core_scsi3_alloc_registration(). When the parameter list spans more than one page (PARAMETER LIST LENGTH > 4096), transport_kmap_data_sg() uses vmap() and transport_kunmap_data_sg() does vunmap(), so the kernel virtual address backing iport_ptr is torn down and every subsequent dereference is a use-after-free read of the unmapped region. Keep the parameter list mapped until iport_ptr is no longer needed: drop the early transport_kunmap_data_sg() and unmap once on the success path, right before returning. The error paths already unmap through the existing "if (buf) transport_kunmap_data_sg(cmd)" at the out: label, which now runs on every post-map error exit because buf is no longer cleared early. Only reads of the mapping happen while spinlocks are held; the map and unmap calls remain outside any lock. The sibling caller core_scsi3_decode_spec_i_port() already uses the buffer before unmapping it and is left unchanged. Fixes: 4949314 ("target: Allow control CDBs with data > 1 page") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me> Reviewed-by: John Garry <john.g.garry@oracle.com> Reviewed-by: David Disseldorp <ddiss@suse.de> Link: https://patch.msgid.link/20260610042245.35473-1-hexlabsecurity@proton.me Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent d04a179 commit fda6a1f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

drivers/target/target_core_pr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,9 +3293,6 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
32933293
goto out;
32943294
}
32953295

3296-
transport_kunmap_data_sg(cmd);
3297-
buf = NULL;
3298-
32993296
pr_debug("SPC-3 PR [%s] Extracted initiator %s identifier: %s"
33003297
" %s\n", dest_tf_ops->fabric_name, (iport_ptr != NULL) ?
33013298
"port" : "device", initiator_str, (iport_ptr != NULL) ?
@@ -3532,6 +3529,11 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
35323529
core_scsi3_update_and_write_aptpl(cmd->se_dev, aptpl);
35333530

35343531
core_scsi3_put_pr_reg(dest_pr_reg);
3532+
/*
3533+
* iport_ptr aliases the PR-OUT parameter list mapped above, so the
3534+
* buffer is unmapped only here on success (and at out: on error).
3535+
*/
3536+
transport_kunmap_data_sg(cmd);
35353537
return 0;
35363538
out:
35373539
if (buf)

0 commit comments

Comments
 (0)