mirror-linux/drivers/target
Dmitry Bogdanov a7a4def6c7 scsi: target: iscsit: Free cmds before session free
[ Upstream commit d8990b5a4d ]

Commands from recovery entries are freed after session has been closed.
That leads to use-after-free at command free or NPE with such call trace:

Time2Retain timer expired for SID: 1, cleaning up iSCSI session.
BUG: kernel NULL pointer dereference, address: 0000000000000140
RIP: 0010:sbitmap_queue_clear+0x3a/0xa0
Call Trace:
 target_release_cmd_kref+0xd1/0x1f0 [target_core_mod]
 transport_generic_free_cmd+0xd1/0x180 [target_core_mod]
 iscsit_free_cmd+0x53/0xd0 [iscsi_target_mod]
 iscsit_free_connection_recovery_entries+0x29d/0x320 [iscsi_target_mod]
 iscsit_close_session+0x13a/0x140 [iscsi_target_mod]
 iscsit_check_post_dataout+0x440/0x440 [iscsi_target_mod]
 call_timer_fn+0x24/0x140

Move cleanup of recovery enrties to before session freeing.

Reported-by: Forza <forza@tnonline.net>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230319015620.96006-7-michael.christie@oracle.com
Reviewed-by: Maurizio Lombardi <mlombard@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-24 17:32:37 +01:00
..
iscsi scsi: target: iscsit: Free cmds before session free 2023-05-24 17:32:37 +01:00
loopback
sbp
tcm_fc
Kconfig
Makefile
target_core_alua.c
target_core_alua.h
target_core_configfs.c
target_core_device.c scsi: target: Fix multiple LUN_RESET handling 2023-05-11 23:03:19 +09:00
target_core_fabric_configfs.c
target_core_fabric_lib.c
target_core_file.c
target_core_file.h
target_core_hba.c
target_core_iblock.c
target_core_iblock.h
target_core_internal.h scsi: target: Move cmd counter allocation 2023-05-11 23:03:19 +09:00
target_core_pr.c
target_core_pr.h
target_core_pscsi.c
target_core_pscsi.h
target_core_rd.c
target_core_rd.h
target_core_sbc.c
target_core_spc.c
target_core_stat.c
target_core_tmr.c scsi: target: Fix multiple LUN_RESET handling 2023-05-11 23:03:19 +09:00
target_core_tpg.c scsi: target: Move sess cmd counter to new struct 2023-05-11 23:03:19 +09:00
target_core_transport.c scsi: target: iscsit: isert: Alloc per conn cmd counter 2023-05-11 23:03:19 +09:00
target_core_ua.c
target_core_ua.h
target_core_user.c
target_core_xcopy.c scsi: target: Pass in cmd counter to use during cmd setup 2023-05-11 23:03:19 +09:00
target_core_xcopy.h scsi: target: core: Change the way target_xcopy_do_work() sets restiction on max I/O 2023-05-11 23:03:19 +09:00