Skip to content

Commit

Permalink
virtio-gpu: move scanout_id sanity check
Browse files Browse the repository at this point in the history
Checking scanout_id in virtio_gpu_do_set_scanout() is too late, for the
"resource_id == 0" case (aka disable scanout) the scanout_id is used
unchecked.  Move the check into the callers to fix that.

Fixes: e64d4b6 ("virtio-gpu: Refactor virtio_gpu_set_scanout")
Fixes: 32db3c6 ("virtio-gpu: Add virtio_gpu_set_scanout_blob")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/383
Reported-by: Alexander Bulekov <alxndr@bu.edu>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Message-Id: <20210604075029.1201478-1-kraxel@redhat.com>
  • Loading branch information
kraxel committed Jun 15, 2021
1 parent 25b2ef2 commit 4fa7b4c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions hw/display/virtio-gpu.c
Expand Up @@ -610,12 +610,6 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,
struct virtio_gpu_scanout *scanout;
uint8_t *data;

if (scanout_id >= g->parent_obj.conf.max_outputs) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d",
__func__, scanout_id);
*error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID;
return;
}
scanout = &g->parent_obj.scanout[scanout_id];

if (r->x > fb->width ||
Expand Down Expand Up @@ -694,6 +688,13 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g,
trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id,
ss.r.width, ss.r.height, ss.r.x, ss.r.y);

if (ss.scanout_id >= g->parent_obj.conf.max_outputs) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d",
__func__, ss.scanout_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID;
return;
}

if (ss.resource_id == 0) {
virtio_gpu_disable_scanout(g, ss.scanout_id);
return;
Expand Down Expand Up @@ -730,6 +731,13 @@ static void virtio_gpu_set_scanout_blob(VirtIOGPU *g,
ss.r.width, ss.r.height, ss.r.x,
ss.r.y);

if (ss.scanout_id >= g->parent_obj.conf.max_outputs) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d",
__func__, ss.scanout_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID;
return;
}

if (ss.resource_id == 0) {
virtio_gpu_disable_scanout(g, ss.scanout_id);
return;
Expand Down

0 comments on commit 4fa7b4c

Please sign in to comment.