Skip to content

Commit 04ed4a9

Browse files
Nicholas Bellingergregkh
authored andcommitted
target: Fix COMPARE_AND_WRITE ref leak for non GOOD status
commit 9b2792c3da1e80f2d460167d319302a24c9ca2b7 upstream. 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> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0c863ac commit 04ed4a9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/target/target_core_sbc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,20 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
442442
int *post_ret)
443443
{
444444
struct se_device *dev = cmd->se_dev;
445+
sense_reason_t ret = TCM_NO_SENSE;
445446

446447
/*
447448
* Only set SCF_COMPARE_AND_WRITE_POST to force a response fall-through
448449
* within target_complete_ok_work() if the command was successfully
449450
* sent to the backend driver.
450451
*/
451452
spin_lock_irq(&cmd->t_state_lock);
452-
if ((cmd->transport_state & CMD_T_SENT) && !cmd->scsi_status) {
453+
if (cmd->transport_state & CMD_T_SENT) {
453454
cmd->se_cmd_flags |= SCF_COMPARE_AND_WRITE_POST;
454455
*post_ret = 1;
456+
457+
if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
458+
ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
455459
}
456460
spin_unlock_irq(&cmd->t_state_lock);
457461

@@ -461,7 +465,7 @@ static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success,
461465
*/
462466
up(&dev->caw_sem);
463467

464-
return TCM_NO_SENSE;
468+
return ret;
465469
}
466470

467471
static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool success,

0 commit comments

Comments
 (0)