scsi: target: tcmu: Fix a use after free in tcmu_check_expired_queue_cmd()
Subsystems (4)
PATCH 1/1 scsi: target: tcmu: Fix a use after free in tcmu_check_expired_queue_cmd()
The pr_debug() dereferences "cmd" after we already freed it by calling tcmu_free_cmd(cmd). The debug printk needs to be done earlier.
--- drivers/target/target_core_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/target/target_core_user.c +3 -3
@@ -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 ); }
Signature · 1 line
2.26.2
Quoted 5 lines · Dan Carpenter
The
pr_debug()dereferences "cmd" after we already freed it by callingtcmu_free_cmd(cmd). The debug printk needs to be done earlier.Fixes 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands")Signed-off-by Dan Carpenter <[email protected]>
Looks like this could be squashed in with the change that it fixes, given that 5.8/scsi-queue hasn't gone out yet.
Cheers, David
Quoted 20 lines · Dan Carpenter
The
pr_debug()dereferences "cmd" after we already freed it by callingtcmu_free_cmd(cmd). The debug printk needs to be done earlier.Fixes 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands")Signed-off-by Dan Carpenter <[email protected]>--- drivers/target/target_core_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/target/target_core_user.c +3
-0@@ -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); +
drivers/target/target_core_user.c static void tcmu_check_expired_queue_cmd(struct tcmu_cmd *cmd) · line 1304
Quoted 10 lines
drivers/target/target_core_user.c +0
-3list_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 ); }
Thanks.
Quoted 9 lines · Dan Carpenter
The
pr_debug()dereferences "cmd" after we already freed it by callingtcmu_free_cmd(cmd). The debug printk needs to be done earlier.Fixes 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands")Signed-off-by Dan Carpenter <[email protected]>--- drivers/target/target_core_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Thank you.
I'm very sorry for this stupid bug.
BR, Bodo
Quoted 11 lines · Bodo Stroesser
Quoted 9 lines · Dan Carpenter
The
pr_debug()dereferences "cmd" after we already freed it by callingtcmu_free_cmd(cmd). The debug printk needs to be done earlier.Fixes 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands")Signed-off-by Dan Carpenter <[email protected]>--- drivers/target/target_core_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 3 lines
Thank you.
I'm very sorry for this stupid bug.
Bugs like this are super common. Part of being human. It would have been hard to discover via testing because you have disable memory poisoning on free and debugging at the same time.
regards,
dan carpenter
Martin K. Petersen
AppliedQuoted 2 lines · Dan Carpenter
The
pr_debug()dereferences "cmd" after we already freed it by callingtcmu_free_cmd(cmd). The debug printk needs to be done earlier.
Applied to 5.8/scsi-queue, thanks!
[1/1] scsi: target: tcmu: Fix a use after free in tcmu_check_expired_queue_cmd()
https://git.kernel.org/mkp/scsi/c/9d7464b18892
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering