aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Bellinger <nab@linux-iscsi.org>2017-02-06 17:28:09 -0500
committerNicholas Bellinger <nab@linux-iscsi.org>2017-02-08 11:25:39 -0500
commit9b2792c3da1e80f2d460167d319302a24c9ca2b7 (patch)
treebb4d91a9afef948324092f9d4190773de79b8d5d
parent01d4d673558985d9a118e1e05026633c3e2ade9b (diff)
target: Fix COMPARE_AND_WRITE ref leak for non GOOD status
This patch addresses a long standing bug where the commit phase of COMPARE_AND_WRITE would result in a se_cmd->cmd_kref reference leak if se_cmd->scsi_status returned non SAM_STAT_GOOD. This would manifest first as a lost SCSI response, and eventual hung task during fabric driver logout or re-login, as existing shutdown logic waited for the COMPARE_AND_WRITE se_cmd->cmd_kref to reach zero. To address this bug, compare_and_write_post() has been changed to drop the incorrect !cmd->scsi_status conditional that was preventing *post_ret = 1 for being set during non SAM_STAT_GOOD status. This patch has been tested with SAM_STAT_CHECK_CONDITION status from normal target_complete_cmd() callback path, as well as the incoming __target_execute_cmd() submission failure path when se_cmd->execute_cmd() returns non zero status. Reported-by: Donald White <dew@datera.io> Cc: Donald White <dew@datera.io> Tested-by: Gary Guo <ghg@datera.io> Cc: Gary Guo <ghg@datera.io> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: <stable@vger.kernel.org> # v3.12+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/target/target_core_sbc.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 4879e70e2eef..df7b6e95c019 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -451,6 +451,7 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
451 int *post_ret) 451 int *post_ret)
452{ 452{
453 struct se_device *dev = cmd->se_dev; 453 struct se_device *dev = cmd->se_dev;
454 sense_reason_t ret = TCM_NO_SENSE;
454 455
455 /* 456 /*
456 * Only set SCF_COMPARE_AND_WRITE_POST to force a response fall-through 457 * Only set SCF_COMPARE_AND_WRITE_POST to force a response fall-through
@@ -458,9 +459,12 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
458 * sent to the backend driver. 459 * sent to the backend driver.
459 */ 460 */
460 spin_lock_irq(&cmd->t_state_lock); 461 spin_lock_irq(&cmd->t_state_lock);
461 if ((cmd->transport_state & CMD_T_SENT) && !cmd->scsi_status) { 462 if (cmd->transport_state & CMD_T_SENT) {
462 cmd->se_cmd_flags |= SCF_COMPARE_AND_WRITE_POST; 463 cmd->se_cmd_flags |= SCF_COMPARE_AND_WRITE_POST;
463 *post_ret = 1; 464 *post_ret = 1;
465
466 if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
467 ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
464 } 468 }
465 spin_unlock_irq(&cmd->t_state_lock); 469 spin_unlock_irq(&cmd->t_state_lock);
466 470
@@ -470,7 +474,7 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
470 */ 474 */
471 up(&dev->caw_sem); 475 up(&dev->caw_sem);
472 476
473 return TCM_NO_SENSE; 477 return ret;
474} 478}
475 479
476static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool success, 480static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool success,