linux-stable/drivers/target
Roland Dreier bc187ea6c3 target: Check sess_tearing_down in target_get_sess_cmd()
Target core code assumes that target_splice_sess_cmd_list() has set
sess_tearing_down and moved the list of pending commands to
sess_wait_list, no more commands will be added to the session; if any
are added, nothing keeps the se_session from being freed while the
command is still in flight, which e.g. leads to use-after-free of
se_cmd->se_sess in target_release_cmd_kref().

To enforce this invariant, put a check of sess_tearing_down inside of
sess_cmd_lock in target_get_sess_cmd(); any checks before this are
racy and can lead to the use-after-free described above.  For example,
the qla_target check in qlt_do_work() checks sess_tearing_down from
work thread context but then drops all locks before calling
target_submit_cmd() (as it must, since that is a sleeping function).

However, since no locks are held, anything can happen with respect to
the session it has looked up -- although it does correctly get
sess_kref within its lock, so the memory won't be freed while
target_submit_cmd() is actually running, nothing stops eg an ACL from
being dropped and calling ->shutdown_session() (which calls into
target_splice_sess_cmd_list()) before we get to target_get_sess_cmd().
Once this happens, the se_session memory can be freed as soon as
target_submit_cmd() returns and qlt_do_work() drops its reference,
even though we've just added a command to sess_cmd_list.

To prevent this use-after-free, check sess_tearing_down inside of
sess_cmd_lock right before target_get_sess_cmd() adds a command to
sess_cmd_list; this is synchronized with target_splice_sess_cmd_list()
so that every command is either waited for or not added to the queue.

(nab: Keep target_submit_cmd() returning void for now..)

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
2012-07-16 17:35:26 -07:00
..
iscsi target: Misc retval cleanups 2012-07-16 17:35:23 -07:00
loopback target: remove transport_generic_process_write 2012-07-16 17:35:16 -07:00
sbp sbp-target: Consolidate duplicated error path code in sbp_handle_command() 2012-07-16 17:35:26 -07:00
tcm_fc tcm_fc: Offload WRITE I/O backend submission to tpg workqueue 2012-07-16 17:35:19 -07: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: Return error to initiator if SET TARGET PORT GROUPS emulation fails 2012-06-12 20:12:25 -07:00
target_core_alua.h target: Add MI_REPORT_TARGET_PGS ext. header + implict_trans_secs attribute 2012-05-17 00:45:58 -07:00
target_core_configfs.c Revert "target: Do not special-case loop and iscsi fabric module loads" 2012-07-16 17:35:14 -07:00
target_core_device.c target: Make core_disable_device_list_for_node use pre-refactoring lock ordering 2012-07-16 17:35:24 -07:00
target_core_fabric_configfs.c target: Remove hba param from core_dev_add_lun 2012-07-16 17:35:22 -07:00
target_core_fabric_lib.c target: remove useless casts 2011-12-14 11:28:07 +00:00
target_core_file.c target: move sync_cache to struct spc_ops 2012-07-16 17:29:12 -07:00
target_core_file.h target/file: Use O_DSYNC by default for FILEIO backends 2012-06-02 23:47:20 -07:00
target_core_hba.c target: header reshuffle, part2 2011-12-14 11:26:05 +00:00
target_core_iblock.c target: move unmap to struct spc_ops 2012-07-16 17:35:14 -07:00
target_core_iblock.h target/iblock: Add parameter to specify read-only devices 2012-07-16 17:29:11 -07:00
target_core_internal.h target: refactor core_update_device_list_for_node() 2012-07-16 17:35:24 -07:00
target_core_pr.c target: Remove unneeded double parentheses 2012-07-16 17:35:22 -07:00
target_core_pr.h target: replace ->execute_task with ->execute_cmd 2012-05-06 15:11:14 -07:00
target_core_pscsi.c target: add struct spc_ops + initial ->execute_rw pointer usage 2012-07-16 17:29:12 -07:00
target_core_pscsi.h target: remove struct se_task 2012-05-06 15:11:26 -07:00
target_core_rd.c target: add struct spc_ops + initial ->execute_rw pointer usage 2012-07-16 17:29:12 -07:00
target_core_rd.h target: don't limit transfer sizes for the ramdisk backend 2012-04-14 17:40:30 -07:00
target_core_sbc.c target: move unmap to struct spc_ops 2012-07-16 17:35:14 -07:00
target_core_spc.c target: Move MAINTENANCE_[IN,OUT] from pscsi_parse_cdb -> spc_parse_cdb 2012-07-16 17:28:40 -07:00
target_core_stat.c target: remove obvious warnings 2012-03-15 19:16:09 -07:00
target_core_tmr.c target: replace the processing thread with a TMR work queue 2012-07-16 17:35:21 -07:00
target_core_tpg.c target: refactor core_update_device_list_for_node() 2012-07-16 17:35:24 -07:00
target_core_transport.c target: Check sess_tearing_down in target_get_sess_cmd() 2012-07-16 17:35:26 -07:00
target_core_ua.c target: Use array_zalloc for device_list 2012-03-15 19:15:51 -07:00
target_core_ua.h