linux/drivers/target
David Disseldorp a47fa41381 scsi: target: Fix NULL dereference on XCOPY completion
CPU affinity control added with commit 39ae3edda3 ("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/20210720225522.26291-1-ddiss@suse.de
Fixes: 39ae3edda3 ("scsi: target: core: Make completion affinity configurable")
Cc: Lee Duncan <lduncan@suse.com>
Cc: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2021-07-20 23:18:22 -04:00
..
iscsi scsi: target: iscsi: Remove redundant continue statement 2021-06-18 23:01:03 -04:00
loopback scsi: core: Kill DRIVER_SENSE 2021-05-31 22:48:21 -04:00
sbp scsi: target: sbp_target: Remove redundant assignment to pg_size 2021-05-14 23:09:24 -04:00
tcm_fc scsi: target: tcm_fc: Fix a kernel-doc header 2021-04-15 22:44:41 -04:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile
target_core_alua.c scsi: target: Use standard SAM status types 2021-05-31 22:48:24 -04:00
target_core_alua.h
target_core_configfs.c scsi: target: core: Add configurable IEEE Company ID attribute 2021-05-15 14:14:28 -04:00
target_core_device.c scsi: target: core: Add configurable IEEE Company ID attribute 2021-05-15 14:14:28 -04:00
target_core_fabric_configfs.c scsi: target: core: Make completion affinity configurable 2021-03-04 17:37:03 -05:00
target_core_fabric_lib.c scsi: target: Handle short iSIDs 2020-07-08 00:14:34 -04:00
target_core_file.c scsi: target: core: file: Don't duplicate memset(0xff) 2021-03-09 23:47:18 -05:00
target_core_file.h
target_core_hba.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
target_core_iblock.c SCSI misc on 20210702 2021-07-02 15:14:36 -07:00
target_core_iblock.h scsi: target: iblock: Add backend plug/unplug callouts 2021-03-04 17:37:02 -05:00
target_core_internal.h scsi: target: core: Make completion affinity configurable 2021-03-04 17:37:03 -05:00
target_core_pr.c scsi: target: Use standard SAM status types 2021-05-31 22:48:24 -04:00
target_core_pr.h scsi: target: core: Unify NAA identifier generation 2021-05-15 14:14:28 -04:00
target_core_pscsi.c block-5.14-2021-07-08 2021-07-09 12:05:33 -07:00
target_core_pscsi.h
target_core_rd.c scsi: target: Add the DUMMY flag to rd_mcp 2021-04-05 23:26:38 -04:00
target_core_rd.h scsi: target: Add the DUMMY flag to rd_mcp 2021-04-05 23:26:38 -04:00
target_core_sbc.c scsi: target: Fix protect handling in WRITE SAME(32) 2021-07-18 21:27:42 -04:00
target_core_spc.c scsi: target: Use standard SAM status types 2021-05-31 22:48:24 -04:00
target_core_stat.c scsi: target: core: Remove unused macros NONE and ISPRINT 2021-03-09 23:47:18 -05:00
target_core_tmr.c scsi: target: core: Flush submission work during TMR processing 2021-03-04 17:37:02 -05:00
target_core_tpg.c scsi: target: Drop sess_cmd_lock from I/O path 2020-11-04 22:39:37 -05:00
target_core_transport.c scsi: target: Fix NULL dereference on XCOPY completion 2021-07-20 23:18:22 -04:00
target_core_ua.c scsi: target: use an enum to track emulate_ua_intlck_ctrl 2020-02-21 17:37:16 -05:00
target_core_ua.h
target_core_user.c SCSI misc on 20210702 2021-07-02 15:14:36 -07:00
target_core_xcopy.c scsi: target: Use standard SAM status types 2021-05-31 22:48:24 -04:00
target_core_xcopy.h scsi: target: Fix XCOPY NAA identifier lookup 2021-01-11 17:06:48 -05:00