Skip to content

Commit e508efc

Browse files
mikechristiemstsirkin
authored andcommitted
vhost-scsi: Fix vhost_scsi struct use after free
If vhost_scsi_setup_vq_cmds fails we leave the tpg->vhost_scsi pointer set. If the device is freed and then the user unmaps the LUN, the call to vhost_scsi_port_unlink -> vhost_scsi_hotunplug will see the that tpg->vhost_scsi is still set and try to use it. This has us clear the vhost_scsi pointer in the failure path. It also has us take tv_tpg_mutex in this failure path, because tv_tpg_vhost_count is accessed under this mutex in vhost_scsi_drop_nexus and in the future we will want to serialize access to tpg->vhost_scsi with that mutex instead of the vhost_scsi_mutex. Signed-off-by: Mike Christie <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 10805eb commit e508efc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/vhost/scsi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,10 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
16581658
for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) {
16591659
tpg = vs_tpg[i];
16601660
if (tpg) {
1661+
mutex_lock(&tpg->tv_tpg_mutex);
1662+
tpg->vhost_scsi = NULL;
16611663
tpg->tv_tpg_vhost_count--;
1664+
mutex_unlock(&tpg->tv_tpg_mutex);
16621665
target_undepend_item(&tpg->se_tpg.tpg_group.cg_item);
16631666
}
16641667
}

0 commit comments

Comments
 (0)