linux/drivers/target
Nicholas Bellinger 3909b4011c target: Fix kref->refcount underflow in transport_cmd_finish_abort
commit 73d4e580cc upstream.

This patch fixes a se_cmd->cmd_kref underflow during CMD_T_ABORTED
when a fabric driver drops it's second reference from below the
target_core_tmr.c based callers of transport_cmd_finish_abort().

Recently with the conversion of kref to refcount_t, this bug was
manifesting itself as:

[705519.601034] refcount_t: underflow; use-after-free.
[705519.604034] INFO: NMI handler (kgdb_nmi_handler) took too long to run: 20116.512 msecs
[705539.719111] ------------[ cut here ]------------
[705539.719117] WARNING: CPU: 3 PID: 26510 at lib/refcount.c:184 refcount_sub_and_test+0x33/0x51

Since the original kref atomic_t based kref_put() didn't check for
underflow and only invoked the final callback when zero was reached,
this bug did not manifest in practice since all se_cmd memory is
using preallocated tags.

To address this, go ahead and propigate the existing return from
transport_put_cmd() up via transport_cmd_finish_abort(), and
change transport_cmd_finish_abort() + core_tmr_handle_tas_abort()
callers to only do their local target_put_sess_cmd() if necessary.

Reported-by: Bart Van Assche <bart.vanassche@sandisk.com>
Tested-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Mike Christie <mchristi@redhat.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Himanshu Madhani <himanshu.madhani@qlogic.com>
Cc: Sagi Grimberg <sagig@mellanox.com>
Tested-by: Gary Guo <ghg@datera.io>
Tested-by: Chu Yuan Lin <cyl@datera.io>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2017-09-15 18:30:07 +01:00
..
iscsi iscsi-target: Always wait for kthread_should_stop() before kthread exit 2017-09-15 18:29:53 +01:00
loopback tcm_loop: Fixup tag handling 2015-01-22 16:33:35 +00:00
sbp target: Pass in transport supported PI at session initialization 2014-04-07 01:48:54 -07:00
tcm_fc tcm_fc: missing curly braces in ft_invl_hw_context() 2015-03-30 11:11:42 +01:00
Kconfig target/iblock: Add blk_integrity + BIP passthrough support 2014-01-18 10:14:22 +00:00
Makefile target: Add support for EXTENDED_COPY copy offload emulation 2013-09-10 16:48:43 -07:00
target_core_alua.c Merge branch 'next' (accumulated 3.16 merge window patches) into master 2014-06-08 11:31:16 -07:00
target_core_alua.h target_core_alua: Referrals configfs integration 2014-01-09 21:48:35 -08:00
target_core_configfs.c target: Fix a memory leak in target_dev_lba_map_store() 2016-02-02 19:48:58 +00:00
target_core_device.c target: Fix max_unmap_lba_count calc overflow 2016-11-20 01:16:55 +00:00
target_core_fabric_configfs.c target: Fix sizeof in kmalloc for some default_groups arrays 2013-12-16 12:42:20 -08:00
target_core_fabric_lib.c target: Update copyright ownership/year information to 2013 2013-09-10 20:23:36 -07:00
target_core_file.c target/fileio: Fix zero-length READ and WRITE handling 2017-08-26 02:14:46 +01:00
target_core_file.h Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2014-01-31 15:31:23 -08:00
target_core_hba.c target: Update copyright ownership/year information to 2013 2013-09-10 20:23:36 -07:00
target_core_iblock.c target: Fix max_unmap_lba_count calc overflow 2016-11-20 01:16:55 +00:00
target_core_iblock.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_internal.h target: Fix kref->refcount underflow in transport_cmd_finish_abort 2017-09-15 18:30:07 +01:00
target_core_pr.c target: Allow Write Exclusive non-reservation holders to READ 2015-03-03 14:24:08 +00:00
target_core_pr.h target: Fix APTPL metadata handling for dynamic MappedLUNs 2014-11-05 11:43:05 +00:00
target_core_pscsi.c target/pscsi: Fix TYPE_TAPE + TYPE_MEDIMUM_CHANGER export 2017-07-18 18:40:08 +01:00
target_core_pscsi.h target/pscsi: Don't leak scsi_host if hba is VIRTUAL_HOST 2015-06-03 14:30:06 +01:00
target_core_rd.c target/rd: T10-Dif: RAM disk is allocating more space than required. 2014-04-07 01:48:53 -07:00
target_core_rd.h target/rd: Add support for protection SGL setup + release 2014-01-19 02:22:05 +00:00
target_core_sbc.c target: Fix VERIFY_16 handling in sbc_parse_cdb 2017-07-18 18:40:09 +01:00
target_core_spc.c target: REPORT LUNS should return LUN 0 even for dynamic ACLs 2015-08-31 14:14:07 +01:00
target_core_stat.c target: Convert se_device statistics to atomic_long_t 2013-11-13 18:34:55 -08:00
target_core_tmr.c target: Fix kref->refcount underflow in transport_cmd_finish_abort 2017-09-15 18:30:07 +01:00
target_core_tpg.c target: Fix APTPL metadata handling for dynamic MappedLUNs 2014-11-05 11:43:05 +00:00
target_core_transport.c target: Fix kref->refcount underflow in transport_cmd_finish_abort 2017-09-15 18:30:07 +01:00
target_core_ua.c arch: Mass conversion of smp_mb__*() 2014-04-18 14:20:48 +02:00
target_core_ua.h target core: rename (ex,im)plict -> (ex,im)plicit 2013-11-20 11:24:40 -08:00
target_core_xcopy.c target: Use correct SCSI status during EXTENDED_COPY exception 2017-03-16 02:27:11 +00:00
target_core_xcopy.h target: Add support for EXTENDED_COPY copy offload emulation 2013-09-10 16:48:43 -07:00