Skip to content

Commit e208a1d

Browse files
Yuan Canmartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix possible UAF in sdebug_add_host_helper()
If device_register() fails in sdebug_add_host_helper(), it will goto clean and sdbg_host will be freed, but sdbg_host->host_list will not be removed from sdebug_host_list, then list traversal may cause UAF. Fix it. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Yuan Can <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent bc68e42 commit e208a1d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7323,8 +7323,12 @@ static int sdebug_add_host_helper(int per_host_idx)
73237323
dev_set_name(&sdbg_host->dev, "adapter%d", sdebug_num_hosts);
73247324

73257325
error = device_register(&sdbg_host->dev);
7326-
if (error)
7326+
if (error) {
7327+
spin_lock(&sdebug_host_list_lock);
7328+
list_del(&sdbg_host->host_list);
7329+
spin_unlock(&sdebug_host_list_lock);
73277330
goto clean;
7331+
}
73287332

73297333
++sdebug_num_hosts;
73307334
return 0;

0 commit comments

Comments
 (0)