virtio-gpu: fix a missing check to avoid NULL dereference
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Sun, 27 Mar 2022 05:09:45 +0000 (13:09 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:18 +0000 (14:23 +0200)
[ Upstream commit bd63f11f4c3c46afec07d821f74736161ff6e526 ]

'cache_ent' could be set NULL inside virtio_gpu_cmd_get_capset()
and it will lead to a NULL dereference by a lately use of it
(i.e., ptr = cache_ent->caps_cache). Fix it with a NULL check.

Fixes: 62fb7a5e10962 ("virtio-gpu: add 3d/virgl support")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220327050945.1614-1-xiam0nd.tong@gmail.com
[ kraxel: minor codestyle fixup ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/virtio/virtgpu_ioctl.c

index 5c1ad1596889bbcdf52f15d87db77ecb9210e1c8..15c3e63db396d1faf14fd28ce28e956e85d9e136 100644 (file)
@@ -512,8 +512,10 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
        spin_unlock(&vgdev->display_info_lock);
 
        /* not in cache - need to talk to hw */
-       virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver,
-                                 &cache_ent);
+       ret = virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver,
+                                       &cache_ent);
+       if (ret)
+               return ret;
        virtio_gpu_notify(vgdev);
 
 copy_exit: