Skip to content

Commit 3eaa952

Browse files
Dongli ZhangBrian Maly
authored andcommitted
vhost-scsi: protect vq->log_used with vq->mutex
The vhost-scsi completion path may access vq->log_base when vq->log_used is already set to false. vhost-thread QEMU-thread vhost_scsi_complete_cmd_work() -> vhost_add_used() -> vhost_add_used_n() if (unlikely(vq->log_used)) QEMU disables vq->log_used via VHOST_SET_VRING_ADDR. mutex_lock(&vq->mutex); vq->log_used = false now! mutex_unlock(&vq->mutex); QEMU gfree(vq->log_base) log_used() -> log_write(vq->log_base) Assuming the VMM is QEMU. The vq->log_base is from QEMU userpace and can be reclaimed via gfree(). As a result, this causes invalid memory writes to QEMU userspace. The control queue path has the same issue. Signed-off-by: Dongli Zhang <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Mike Christie <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> (cherry picked from commit f591cf9fce724e5075cc67488c43c6e39e8cbe27) Orabug: 37980690 Conflicts: - commit 48ae70d ("vhost_scsi: make SCSI cmd completion per vq") is not merged in UEK7 so vhost_scsi_complete_cmd_work handles all queues instead of specific ones. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Dongli Zhang <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 79f1b7d commit 3eaa952

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/vhost/scsi.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,11 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
665665
ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter);
666666
if (likely(ret == sizeof(v_rsp))) {
667667
struct vhost_scsi_virtqueue *q;
668+
669+
mutex_lock(&cmd->tvc_vq->mutex);
668670
vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0);
671+
mutex_unlock(&cmd->tvc_vq->mutex);
672+
669673
q = container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq);
670674
vq = q - vs->vqs;
671675
__set_bit(vq, vs->compl_bitmap);
@@ -1451,8 +1455,11 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
14511455
else
14521456
resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
14531457

1458+
mutex_lock(&tmf->svq->vq.mutex);
14541459
vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
14551460
tmf->vq_desc, &tmf->resp_iov, resp_code);
1461+
mutex_unlock(&tmf->svq->vq.mutex);
1462+
14561463
vhost_scsi_release_tmf_res(tmf);
14571464
}
14581465

0 commit comments

Comments
 (0)