aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorRoland Dreier <roland@purestorage.com>2013-01-02 15:47:58 -0500
committerNicholas Bellinger <nab@linux-iscsi.org>2013-01-11 00:00:35 -0500
commit72b59d6ee8adaa51f70377db0a1917ed489bead8 (patch)
treefcfc00e42478a608a24ae4df9795568abc808f4c /drivers/target
parente627c615553a356f6f70215ebb3933c6e057553e (diff)
target: Fix use-after-free in LUN RESET handling
If a backend IO takes a really long then an initiator might abort a command, and then when it gives up on the abort, send a LUN reset too, all before we process any of the original command or the abort. (The abort will wait for the backend IO to complete too) When the backend IO final completes (or fails), the abort handling will proceed and queue up a "return aborted status" operation. Then, while that's still pending, the LUN reset might find the original command still on the LUN's list of commands and try to return aborted status again, which leads to a use-after free when the first se_tfo->queue_status call frees the command and then the second se_tfo->queue_status call runs. Fix this by removing a command from the LUN state_list when we first are about to queue aborted status; we shouldn't do anything LUN-related after we've started returning status, so this seems like the correct thing to do. Signed-off-by: Roland Dreier <roland@purestorage.com> Cc: stable@vger.kernel.org Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/target_core_transport.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 1775bda6c43c..489bd1678d87 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -541,9 +541,6 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd)
541 541
542void transport_cmd_finish_abort(struct se_cmd *cmd, int remove) 542void transport_cmd_finish_abort(struct se_cmd *cmd, int remove)
543{ 543{
544 if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB))
545 transport_lun_remove_cmd(cmd);
546
547 if (transport_cmd_check_stop_to_fabric(cmd)) 544 if (transport_cmd_check_stop_to_fabric(cmd))
548 return; 545 return;
549 if (remove) 546 if (remove)
@@ -2815,6 +2812,8 @@ void transport_send_task_abort(struct se_cmd *cmd)
2815 } 2812 }
2816 cmd->scsi_status = SAM_STAT_TASK_ABORTED; 2813 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
2817 2814
2815 transport_lun_remove_cmd(cmd);
2816
2818 pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x," 2817 pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x,"
2819 " ITT: 0x%08x\n", cmd->t_task_cdb[0], 2818 " ITT: 0x%08x\n", cmd->t_task_cdb[0],
2820 cmd->se_tfo->get_task_tag(cmd)); 2819 cmd->se_tfo->get_task_tag(cmd));