linux-brain/include/scsi
Bart Van Assche 6772ac25b1 scsi: target: iscsi: Wait for all commands to finish before freeing a session
[ Upstream commit e9d3009cb936bd0faf0719f68d98ad8afb1e613b ]

The iSCSI target driver is the only target driver that does not wait for
ongoing commands to finish before freeing a session. Make the iSCSI target
driver wait for ongoing commands to finish before freeing a session. This
patch fixes the following KASAN complaint:

BUG: KASAN: use-after-free in __lock_acquire+0xb1a/0x2710
Read of size 8 at addr ffff8881154eca70 by task kworker/0:2/247

CPU: 0 PID: 247 Comm: kworker/0:2 Not tainted 5.4.0-rc1-dbg+ #6
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
Workqueue: target_completion target_complete_ok_work [target_core_mod]
Call Trace:
 dump_stack+0x8a/0xd6
 print_address_description.constprop.0+0x40/0x60
 __kasan_report.cold+0x1b/0x33
 kasan_report+0x16/0x20
 __asan_load8+0x58/0x90
 __lock_acquire+0xb1a/0x2710
 lock_acquire+0xd3/0x200
 _raw_spin_lock_irqsave+0x43/0x60
 target_release_cmd_kref+0x162/0x7f0 [target_core_mod]
 target_put_sess_cmd+0x2e/0x40 [target_core_mod]
 lio_check_stop_free+0x12/0x20 [iscsi_target_mod]
 transport_cmd_check_stop_to_fabric+0xd8/0xe0 [target_core_mod]
 target_complete_ok_work+0x1b0/0x790 [target_core_mod]
 process_one_work+0x549/0xa40
 worker_thread+0x7a/0x5d0
 kthread+0x1bc/0x210
 ret_from_fork+0x24/0x30

Allocated by task 889:
 save_stack+0x23/0x90
 __kasan_kmalloc.constprop.0+0xcf/0xe0
 kasan_slab_alloc+0x12/0x20
 kmem_cache_alloc+0xf6/0x360
 transport_alloc_session+0x29/0x80 [target_core_mod]
 iscsi_target_login_thread+0xcd6/0x18f0 [iscsi_target_mod]
 kthread+0x1bc/0x210
 ret_from_fork+0x24/0x30

Freed by task 1025:
 save_stack+0x23/0x90
 __kasan_slab_free+0x13a/0x190
 kasan_slab_free+0x12/0x20
 kmem_cache_free+0x146/0x400
 transport_free_session+0x179/0x2f0 [target_core_mod]
 transport_deregister_session+0x130/0x180 [target_core_mod]
 iscsit_close_session+0x12c/0x350 [iscsi_target_mod]
 iscsit_logout_post_handler+0x136/0x380 [iscsi_target_mod]
 iscsit_response_queue+0x8de/0xbe0 [iscsi_target_mod]
 iscsi_target_tx_thread+0x27f/0x370 [iscsi_target_mod]
 kthread+0x1bc/0x210
 ret_from_fork+0x24/0x30

The buggy address belongs to the object at ffff8881154ec9c0
 which belongs to the cache se_sess_cache of size 352
The buggy address is located 176 bytes inside of
 352-byte region [ffff8881154ec9c0, ffff8881154ecb20)
The buggy address belongs to the page:
page:ffffea0004553b00 refcount:1 mapcount:0 mapping:ffff888101755400 index:0x0 compound_mapcount: 0
flags: 0x2fff000000010200(slab|head)
raw: 2fff000000010200 dead000000000100 dead000000000122 ffff888101755400
raw: 0000000000000000 0000000080130013 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8881154ec900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8881154ec980: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
>ffff8881154eca00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                             ^
 ffff8881154eca80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8881154ecb00: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc

Cc: Mike Christie <mchristi@redhat.com>
Link: https://lore.kernel.org/r/20191113220508.198257-3-bvanassche@acm.org
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-04 13:59:49 +01:00
..
fc uapi: export all headers under uapi directories 2017-05-11 00:21:54 +09:00
fc_encode.h [SCSI] libfc: Add support for FDMI 2012-02-19 08:08:58 -06:00
fc_frame.h [SCSI] fcoe: remove unused ptype field in fcoe_rcv_info 2011-07-28 12:08:55 +04:00
fcoe_sysfs.h libfcoe, fcoe, bnx2fc: Add new fcoe control interface 2012-12-14 10:38:54 -08:00
iscsi_if.h scsi_transport_iscsi: Add 25G and 40G speed definition 2016-02-23 21:27:02 -05:00
iscsi_proto.h scsi: target: iscsi: Wait for all commands to finish before freeing a session 2020-01-04 13:59:49 +01:00
iser.h IB/iser,isert: Create and use new shared header 2015-12-24 00:17:35 -05:00
libfc.h scsi: libfc: convert fc_fcp_pkt.ref_cnt from atomic_t to refcount_t 2017-03-15 18:44:02 -04:00
libfcoe.h scsi: fcoe: Embed fc_rport_priv in fcoe_rport structure 2019-08-09 17:53:31 +02:00
libiscsi_tcp.h iscsi_tcp: Use ahash 2016-01-27 20:36:10 +08:00
libiscsi.h SCSI misc on 20170503 2017-05-04 12:19:44 -07:00
libsas.h scsi: libsas: align sata_device's rps_resp on a cacheline 2017-12-14 09:52:51 +01:00
osd_attributes.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
osd_initiator.h block: introduce new block status code type 2017-06-09 09:27:32 -06:00
osd_ore.h Boaz Harrosh - Fix broken email address 2014-10-19 20:22:32 +03:00
osd_protocol.h Boaz Harrosh - Fix broken email address 2014-10-19 20:22:32 +03:00
osd_sec.h Boaz Harrosh - Fix broken email address 2014-10-19 20:22:32 +03:00
osd_sense.h Boaz Harrosh - Fix broken email address 2014-10-19 20:22:32 +03:00
osd_types.h Boaz Harrosh - Fix broken email address 2014-10-19 20:22:32 +03:00
sas_ata.h [SCSI] sas: unify the pointlessly separated enums sas_dev_type and sas_device_type 2013-05-10 07:47:52 -07:00
sas.h scsi: Centralise ssp frame information units 2015-11-25 22:12:50 -05:00
scsi_bsg_iscsi.h [SCSI] iscsi class: add bsg support to iscsi class 2011-08-27 08:36:21 -06:00
scsi_cmnd.h scsi: core: Avoid that ATA error handling can trigger a kernel hang or oops 2018-03-15 10:54:29 +01:00
scsi_common.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_dbg.h scsi: core: Reduce memory required for SCSI logging 2019-10-07 18:55:06 +02:00
scsi_device.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_devinfo.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_dh.h scsi_dh: add 'rescan' callback 2016-02-23 21:27:02 -05:00
scsi_driver.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_eh.h scsi: core: save/restore command resid for error handling 2019-10-29 09:17:31 +01:00
scsi_host.h scsi: core: introduce force_blk_mq 2018-08-15 18:12:47 +02:00
scsi_ioctl.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_proto.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_request.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_tcq.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_transport_fc.h scsi: fc: start decoupling fc_block_scsi_eh from scsi_cmnd 2017-08-07 14:04:02 -04:00
scsi_transport_iscsi.h scsi: libiscsi: Remove iscsi_destroy_session 2017-10-02 22:23:21 -04:00
scsi_transport_sas.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_transport_spi.h scsi: remove abuses of scsi_populate_tag 2014-11-12 11:19:41 +01:00
scsi_transport_srp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scsi_transport.h SCSI misc on 20170220 2017-02-21 11:51:42 -08:00
scsi.h scsi: core: Make SCSI Status CONDITION MET equivalent to GOOD 2018-05-25 16:17:50 +02:00
scsicam.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sg.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
srp.h IB/srp: Add 64-bit LUN support 2015-05-18 13:35:56 -04:00
viosrp.h ibmvscsis: Initial commit of IBM VSCSI Tgt Driver 2016-07-20 01:15:43 -07:00