linux-stable/drivers/target
Dmitry Bogdanov b65e9044be scsi: target: core: Remove from tmr_list during LUN unlink
[ Upstream commit 12b6fcd0ea ]

Currently TMF commands are removed from de_device.dev_tmf_list at the very
end of se_cmd lifecycle. However, se_lun unlinks from se_cmd upon a command
status (response) being queued in transport layer. This means that LUN and
backend device can be deleted in the meantime and a panic will occur:

target_tmr_work()
	cmd->se_tfo->queue_tm_rsp(cmd); // send abort_rsp to a wire
	transport_lun_remove_cmd(cmd) // unlink se_cmd from se_lun
- // - // - // -
<<<--- lun remove
<<<--- core backend device remove
- // - // - // -
qlt_handle_abts_completion()
  tfo->free_mcmd()
    transport_generic_free_cmd()
      target_put_sess_cmd()
        core_tmr_release_req() {
          if (dev) { // backend device, can not be null
            spin_lock_irqsave(&dev->se_tmr_lock, flags); //<<<--- CRASH

Call Trace:
NIP [c000000000e1683c] _raw_spin_lock_irqsave+0x2c/0xc0
LR [c00800000e433338] core_tmr_release_req+0x40/0xa0 [target_core_mod]
Call Trace:
(unreliable)
0x0
target_put_sess_cmd+0x2a0/0x370 [target_core_mod]
transport_generic_free_cmd+0x6c/0x1b0 [target_core_mod]
tcm_qla2xxx_complete_mcmd+0x28/0x50 [tcm_qla2xxx]
process_one_work+0x2c4/0x5c0
worker_thread+0x88/0x690

For the iSCSI protocol this is easily reproduced:

 - Send some SCSI sommand

 - Send Abort of that command over iSCSI

 - Remove LUN on target

 - Send next iSCSI command to acknowledge the Abort_Response

 - Target panics

There is no need to keep the command in tmr_list until response completion,
so move the removal from tmr_list from the response completion to the
response queueing when the LUN is unlinked.  Move the removal from state
list too as it is a subject to the same race condition.

Link: https://lore.kernel.org/r/20211018135753.15297-1-d.bogdanov@yadro.com
Fixes: c66ac9db8d ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18 19:17:03 +01:00
..
iscsi scsi: target: Remove redundant assignment to variable ret 2021-07-27 00:06:42 -04:00
loopback SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
sbp scsi: target: sbp: Drop incorrect ASC/ASCQ usage 2021-08-03 07:27:43 -04:00
tcm_fc scsi: target: tcm_fc: Fix a kernel-doc header 2021-04-15 22:44:41 -04:00
Kconfig scsi: core: Rename CONFIG_BLK_SCSI_REQUEST to CONFIG_SCSI_COMMON 2021-07-28 22:24:27 -04:00
Makefile
target_core_alua.c scsi: target: core: Drop unnecessary se_cmd ASC/ASCQ members 2021-08-03 07:27:43 -04:00
target_core_alua.h
target_core_configfs.c scsi: target: Fix the pgr/alua_support_store functions 2021-09-13 22:15:46 -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
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
target_core_iblock.c scsi: target: Remove redundant assignment to variable ret 2021-07-27 00:06:42 -04: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: Fix spelling mistake "CONFLIFT" -> "CONFLICT" 2021-09-22 00:17:29 -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 scsi: target: pscsi: Fix possible null-pointer dereference in pscsi_complete_cmd() 2021-08-17 22:28:39 -04: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: Remove from tmr_list during LUN unlink 2021-11-18 19:17:03 +01: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: core: Remove from tmr_list during LUN unlink 2021-11-18 19:17:03 +01:00
target_core_ua.c
target_core_ua.h
target_core_user.c scsi: target: tcmu: Add new feature KEEP_BUF 2021-08-03 07:27:42 -04:00
target_core_xcopy.c scsi: target: Fix sense key for invalid EXTENDED COPY request 2021-08-17 22:28:40 -04:00
target_core_xcopy.h scsi: target: Fix XCOPY NAA identifier lookup 2021-01-11 17:06:48 -05:00