Skip to content

Commit 59614c5

Browse files
Dongli Zhanggregkh
authored andcommitted
vhost-scsi: protect vq->log_used with vq->mutex
commit f591cf9fce724e5075cc67488c43c6e39e8cbe27 upstream. 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]> [ resoloved conflicts in drivers/vhost/scsi.c bacause vhost_scsi_complete_cmd_work() has been refactored. ] Signed-off-by: Xinyu Zheng <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c9d87f4 commit 59614c5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/vhost/scsi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
568568
ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter);
569569
if (likely(ret == sizeof(v_rsp))) {
570570
struct vhost_scsi_virtqueue *q;
571-
vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0);
572571
q = container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq);
572+
mutex_lock(&q->vq.mutex);
573+
vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0);
574+
mutex_unlock(&q->vq.mutex);
573575
vq = q - vs->vqs;
574576
__set_bit(vq, vs->compl_bitmap);
575577
} else
@@ -1173,8 +1175,11 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
11731175
else
11741176
resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
11751177

1178+
mutex_lock(&tmf->svq->vq.mutex);
11761179
vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
11771180
tmf->vq_desc, &tmf->resp_iov, resp_code);
1181+
mutex_unlock(&tmf->svq->vq.mutex);
1182+
11781183
vhost_scsi_release_tmf_res(tmf);
11791184
}
11801185

0 commit comments

Comments
 (0)