Skip to contentSkip to conversation

drm/virtio: fix OOB in virtio_gpu_object_create

PATCH In review Jiri Slaby 2 participants 2 messages Mar 19, 2020

Subsystems (4)
lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 drm/virtio: fix OOB in virtio_gpu_object_create

After commit f651c8b05542, virtio_gpu_create_object allocates too small space to fit everything in. It is because it allocates struct virtio_gpu_object, but should allocate a newly added struct virtio_gpu_object_shmem which has 2 more members.

So fix that by using correct type in virtio_gpu_create_object.

Fixes f651c8b05542 ("drm/virtio: factor out the sg_table from virtio_gpu_object")
Cc Gurchetan Singh <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +8 -6
index 2bfb13d1932e..d9039bb7c5e3 100644
@@ -123,15 +123,17 @@ bool virtio_gpu_is_shmem(struct virtio_gpu_object *bo)
 struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
 						size_t size)
 {
-	struct virtio_gpu_object *bo;
+	struct virtio_gpu_object_shmem *shmem;
+	struct drm_gem_shmem_object *dshmem;
 
-	bo = kzalloc(sizeof(*bo), GFP_KERNEL);
-	if (!bo)
+	shmem = kzalloc(sizeof(*shmem), GFP_KERNEL);
+	if (!shmem)
 		return NULL;
 
-	bo->base.base.funcs = &virtio_gpu_shmem_funcs;
-	bo->base.map_cached = true;
-	return &bo->base.base;
+	dshmem = &shmem->base.base;
+	dshmem->base.funcs = &virtio_gpu_shmem_funcs;
+	dshmem->map_cached = true;
+	return &dshmem->base;
 }
 
 static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 11 lines · Jiri Slaby

After commit f651c8b05542, virtio_gpu_create_object allocates too small space to fit everything in. It is because it allocates struct virtio_gpu_object, but should allocate a newly added struct virtio_gpu_object_shmem which has 2 more members.

So fix that by using correct type in virtio_gpu_create_object.

Fixes f651c8b05542 ("drm/virtio: factor out the sg_table from virtio_gpu_object")
Cc Gurchetan Singh <[email protected]>
Cc Gerd Hoffmann <[email protected]>

That was fast. Yes, exactly this. Pushed to drm-misc-next.

thanks,
Gerd