kernel-ark/drivers/target
Roland Dreier e627c61555 target: Fix missing CMD_T_ACTIVE bit regression for pending WRITEs
This patch fixes a regression bug introduced during v3.6.x code with
the following commit to drop transport_add_cmd_to_queue(), which
originally re-set CMD_T_ACTIVE during pending WRITE I/O submission:

commit af8772926f
Author: Christoph Hellwig <hch@infradead.org>
Date:   Sun Jul 8 15:58:49 2012 -0400

    target: replace the processing thread with a TMR work queue

The following sequence happens for write commands (or any other
commands with a data out phase):

 - The transport calls target_submit_cmd(), which sets CMD_T_ACTIVE in
   cmd->transport_state and sets cmd->t_state to TRANSPORT_NEW_CMD.
 - Things go on transport_generic_new_cmd(), which notices that the
   command needs to transfer data, so it sets cmd->t_state to
   TRANSPORT_WRITE_PENDING and calls transport_cmd_check_stop().
 - transport_cmd_check_stop() clears CMD_T_ACTIVE in cmd->transport_state
   and returns in the normal case.
 - Then we continue on to call ->se_tfo->write_pending().
 - The data comes back from the initiator, and the transport calls
   target_execute_cmd(), which sets cmd->t_state to TRANSPORT_PROCESSING
   and calls into the backend to actually write the data.

At this point, the backend might take a long time to complete the
command, since it has to do real IO.  If an abort request comes in for
this command at this point, it will not wait for the command to finish
since CMD_T_ACTIVE is not set.  Then when the command does finally
finish, we blow up with use-after-free.

Avoid this by setting CMD_T_ACTIVE in target_execute_cmd() so that
transport_wait_for_tasks() waits for the command to finish executing.
This matches the behavior from before commit 1389533ef9 ("target:
remove transport_generic_handle_data"), when data was signaled via
transport_generic_handle_data(), which set CMD_T_ACTIVE because it
called transport_add_cmd_to_queue().

Signed-off-by: Roland Dreier <roland@purestorage.com>
Reported-by: Martin Svec <martin.svec@zoner.cz>
Cc: Christoph Hellwig <hch@lst.de>
Cc: stable@vger.kernel.org
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
2013-01-10 21:00:07 -08:00
..
iscsi Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2012-12-15 14:25:10 -08:00
loopback target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
sbp sbp-target: fix error path in sbp_make_tpg() 2012-12-12 21:17:25 -08:00
tcm_fc tcm_fc: Do not report target role when target is not defined 2013-01-10 20:08:58 -08:00
Kconfig sbp-target: Initial merge of firewire/ieee-1394 target mode support 2012-05-09 15:25:17 -07:00
Makefile target: move code for CDB emulation 2012-07-16 17:27:45 -07:00
target_core_alua.c target: Use TCM_NO_SENSE for initialisation 2013-01-10 20:07:10 -08:00
target_core_alua.h target: pass sense_reason as a return value 2012-11-06 20:55:46 -08:00
target_core_configfs.c target/configfs: use kmalloc() instead of kzalloc() for default groups 2012-11-27 22:49:24 -08:00
target_core_device.c target: Add link_magic for fabric allow_link destination target_items 2012-12-05 00:11:36 -08:00
target_core_fabric_configfs.c target: Add link_magic for fabric allow_link destination target_items 2012-12-05 00:11:36 -08:00
target_core_fabric_lib.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_file.c target/file: merge fd_do_readv() and fd_do_writev() 2012-12-05 13:09:45 -08:00
target_core_file.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_hba.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_iblock.c target: Make spc_get_write_same_sectors return sector_t 2012-11-27 22:49:25 -08:00
target_core_iblock.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_internal.h target: Add/check max_write_same_len device attribute + update block limits VPD 2012-11-15 12:27:21 -08:00
target_core_pr.c target: Use TCM_NO_SENSE for initialisation 2013-01-10 20:07:10 -08:00
target_core_pr.h target: pass sense_reason as a return value 2012-11-06 20:55:46 -08:00
target_core_pscsi.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_pscsi.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_rd.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_rd.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_sbc.c target: Make spc_get_write_same_sectors return sector_t 2012-11-27 22:49:25 -08:00
target_core_spc.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_stat.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_tmr.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_tpg.c target/iscsi_target: Add NodeACL tags for initiator group support 2012-12-13 14:18:09 -08:00
target_core_transport.c target: Fix missing CMD_T_ACTIVE bit regression for pending WRITEs 2013-01-10 21:00:07 -08:00
target_core_ua.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_ua.h target: pass sense_reason as a return value 2012-11-06 20:55:46 -08:00