]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
Fix use after free in get_capset_info callback.
authorDoug Horn <doughorn@google.com>
Wed, 2 Sep 2020 21:08:25 +0000 (14:08 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 08:58:07 +0000 (09:58 +0100)
[ Upstream commit e219688fc5c3d0d9136f8d29d7e0498388f01440 ]

If a response to virtio_gpu_cmd_get_capset_info takes longer than
five seconds to return, the callback will access freed kernel memory
in vg->capsets.

Signed-off-by: Doug Horn <doughorn@google.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200902210847.2689-2-gurchetansingh@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/virtio/virtgpu_kms.c
drivers/gpu/drm/virtio/virtgpu_vq.c

index c190702fab72642de0af57e9f1a257445c90cbef..6dcc05ab31eba73360b144a3fabbcfce10fd2e37 100644 (file)
@@ -96,8 +96,10 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
                                         vgdev->capsets[i].id > 0, 5 * HZ);
                if (ret == 0) {
                        DRM_ERROR("timed out waiting for cap set %d\n", i);
+                       spin_lock(&vgdev->display_info_lock);
                        kfree(vgdev->capsets);
                        vgdev->capsets = NULL;
+                       spin_unlock(&vgdev->display_info_lock);
                        return;
                }
                DRM_INFO("cap set %d: id %d, max-version %d, max-size %d\n",
index 7ac20490e1b4c779fe34a3bbda9008e7307ae811..92022a83bbd5e684b775f7d96ca318f627497cbf 100644 (file)
@@ -572,9 +572,13 @@ static void virtio_gpu_cmd_get_capset_info_cb(struct virtio_gpu_device *vgdev,
        int i = le32_to_cpu(cmd->capset_index);
 
        spin_lock(&vgdev->display_info_lock);
-       vgdev->capsets[i].id = le32_to_cpu(resp->capset_id);
-       vgdev->capsets[i].max_version = le32_to_cpu(resp->capset_max_version);
-       vgdev->capsets[i].max_size = le32_to_cpu(resp->capset_max_size);
+       if (vgdev->capsets) {
+               vgdev->capsets[i].id = le32_to_cpu(resp->capset_id);
+               vgdev->capsets[i].max_version = le32_to_cpu(resp->capset_max_version);
+               vgdev->capsets[i].max_size = le32_to_cpu(resp->capset_max_size);
+       } else {
+               DRM_ERROR("invalid capset memory.");
+       }
        spin_unlock(&vgdev->display_info_lock);
        wake_up(&vgdev->resp_wq);
 }