scsi: target: tcmu: Fix a use after free in tcmu_check_expired_queue_cmd()
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 23 May 2020 10:11:29 +0000 (13:11 +0300)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 26 May 2020 19:54:39 +0000 (15:54 -0400)
The pr_debug() dereferences "cmd" after we already freed it by calling
tcmu_free_cmd(cmd).  The debug printk needs to be done earlier.

Link: https://lore.kernel.org/r/20200523101129.GB98132@mwanda
Fixes: 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands")
Reviewed-by: Mike Christie <mchristi@redhat.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/target_core_user.c

index 1d030d57c28cdbb322ab44e8d44f5152d3a57f44..0e281d30d81efbdd98012d4f810cb4dfdcbd9c55 100644 (file)
@@ -1292,13 +1292,13 @@ static void tcmu_check_expired_queue_cmd(struct tcmu_cmd *cmd)
        if (!time_after(jiffies, cmd->deadline))
                return;
 
+       pr_debug("Timing out queued cmd %p on dev %s.\n",
+                 cmd, cmd->tcmu_dev->name);
+
        list_del_init(&cmd->queue_entry);
        se_cmd = cmd->se_cmd;
        tcmu_free_cmd(cmd);
 
-       pr_debug("Timing out queued cmd %p on dev %s.\n",
-                 cmd, cmd->tcmu_dev->name);
-
        target_complete_cmd(se_cmd, SAM_STAT_TASK_SET_FULL);
 }