Skip to content

Commit db60df8

Browse files
author
Nicholas Bellinger
committed
target: Fail on non zero scsi_status in compare_and_write_callback
This patch addresses a bug for backends such as IBLOCK that perform asynchronous completion via transport_complete_cmd(), that will call target_complete_failure_work() -> transport_generic_request_failure(), upon exception status and invoke cmd->transport_complete_callback() -> compare_and_write_callback() incorrectly during the failure case. It adds a check for a non zero se_cmd->scsi_status within the first invocation of compare_and_write_callback(), and will jump to out plus up se_device->caw_sem before exiting the callback. Reported-by: Thomas Glanzmann <[email protected]> Tested-by: Thomas Glanzmann <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent d8855c1 commit db60df8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/target/target_core_sbc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd)
372372
{
373373
struct se_device *dev = cmd->se_dev;
374374
struct scatterlist *write_sg = NULL, *sg;
375-
unsigned char *buf, *addr;
375+
unsigned char *buf = NULL, *addr;
376376
struct sg_mapping_iter m;
377377
unsigned int offset = 0, len;
378378
unsigned int nlbas = cmd->t_task_nolb;
@@ -387,6 +387,15 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd)
387387
*/
388388
if (!cmd->t_data_sg || !cmd->t_bidi_data_sg)
389389
return TCM_NO_SENSE;
390+
/*
391+
* Immediately exit + release dev->caw_sem if command has already
392+
* been failed with a non-zero SCSI status.
393+
*/
394+
if (cmd->scsi_status) {
395+
pr_err("compare_and_write_callback: non zero scsi_status:"
396+
" 0x%02x\n", cmd->scsi_status);
397+
goto out;
398+
}
390399

391400
buf = kzalloc(cmd->data_length, GFP_KERNEL);
392401
if (!buf) {

0 commit comments

Comments
 (0)