Skip to content

Commit a47fa41

Browse files
ddissmartinkpetersen
authored andcommitted
scsi: target: Fix NULL dereference on XCOPY completion
CPU affinity control added with commit 39ae3ed ("scsi: target: core: Make completion affinity configurable") makes target_complete_cmd() queue work on a CPU based on se_tpg->se_tpg_wwn->cmd_compl_affinity state. LIO's EXTENDED COPY worker is a special case in that read/write cmds are dispatched using the global xcopy_pt_tpg, which carries a NULL se_tpg_wwn pointer following initialization in target_xcopy_setup_pt(). The NULL xcopy_pt_tpg->se_tpg_wwn pointer is dereferenced on completion of any EXTENDED COPY initiated read/write cmds. E.g using the libiscsi SCSI.ExtendedCopy.Simple test: BUG: kernel NULL pointer dereference, address: 00000000000001a8 RIP: 0010:target_complete_cmd+0x9d/0x130 [target_core_mod] Call Trace: fd_execute_rw+0x148/0x42a [target_core_file] ? __dynamic_pr_debug+0xa7/0xe0 ? target_check_reservation+0x5b/0x940 [target_core_mod] __target_execute_cmd+0x1e/0x90 [target_core_mod] transport_generic_new_cmd+0x17c/0x330 [target_core_mod] target_xcopy_issue_pt_cmd+0x9/0x60 [target_core_mod] target_xcopy_read_source.isra.7+0x10b/0x1b0 [target_core_mod] ? target_check_fua+0x40/0x40 [target_core_mod] ? transport_complete_task_attr+0x130/0x130 [target_core_mod] target_xcopy_do_work+0x61f/0xc00 [target_core_mod] This fix makes target_complete_cmd() queue work on se_cmd->cpuid if se_tpg_wwn is NULL. Link: https://lore.kernel.org/r/[email protected] Fixes: 39ae3ed ("scsi: target: core: Make completion affinity configurable") Cc: Lee Duncan <[email protected]> Cc: Mike Christie <[email protected]> Reviewed-by: Mike Christie <[email protected]> Signed-off-by: David Disseldorp <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent fae2160 commit a47fa41

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/target/target_core_transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
886886
INIT_WORK(&cmd->work, success ? target_complete_ok_work :
887887
target_complete_failure_work);
888888

889-
if (wwn->cmd_compl_affinity == SE_COMPL_AFFINITY_CPUID)
889+
if (!wwn || wwn->cmd_compl_affinity == SE_COMPL_AFFINITY_CPUID)
890890
cpu = cmd->cpuid;
891891
else
892892
cpu = wwn->cmd_compl_affinity;

0 commit comments

Comments
 (0)