Commit 7fdf478a authored by David Riley's avatar David Riley Committed by Gerd Hoffmann

drm/virtio: Ensure cached capset entries are valid before copying.

virtio_gpu_get_caps_ioctl could return success with invalid data if a
second caller to the function occurred after the entry was created in
virtio_gpu_cmd_get_capset but prior to the virtio_gpu_cmd_capset_cb
callback being called.  This could leak contents of memory as well
since the caps_cache allocation is done without zeroing.
Signed-off-by: default avatarDavid Riley <davidriley@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190605234423.11348-1-davidriley@chromium.orgSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 50f9495e
...@@ -524,7 +524,6 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, ...@@ -524,7 +524,6 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
list_for_each_entry(cache_ent, &vgdev->cap_cache, head) { list_for_each_entry(cache_ent, &vgdev->cap_cache, head) {
if (cache_ent->id == args->cap_set_id && if (cache_ent->id == args->cap_set_id &&
cache_ent->version == args->cap_set_ver) { cache_ent->version == args->cap_set_ver) {
ptr = cache_ent->caps_cache;
spin_unlock(&vgdev->display_info_lock); spin_unlock(&vgdev->display_info_lock);
goto copy_exit; goto copy_exit;
} }
...@@ -535,6 +534,7 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, ...@@ -535,6 +534,7 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver, virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver,
&cache_ent); &cache_ent);
copy_exit:
ret = wait_event_timeout(vgdev->resp_wq, ret = wait_event_timeout(vgdev->resp_wq,
atomic_read(&cache_ent->is_valid), 5 * HZ); atomic_read(&cache_ent->is_valid), 5 * HZ);
if (!ret) if (!ret)
...@@ -542,7 +542,6 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, ...@@ -542,7 +542,6 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
ptr = cache_ent->caps_cache; ptr = cache_ent->caps_cache;
copy_exit:
if (copy_to_user(u64_to_user_ptr(args->addr), ptr, size)) if (copy_to_user(u64_to_user_ptr(args->addr), ptr, size))
return -EFAULT; return -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment