Skip to content

Commit b513b0d

Browse files
Jiri Slabykraxel
authored andcommitted
drm/virtio: fix OOB in virtio_gpu_object_create
After commit f651c8b ("drm/virtio: factor out the sg_table from virtio_gpu_object"), 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. Signed-off-by: Jiri Slaby <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Fixes: f651c8b ("drm/virtio: factor out the sg_table from virtio_gpu_object") Cc: Gurchetan Singh <[email protected]> Cc: Gerd Hoffmann <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]> (cherry picked from commit 0666a8d)
1 parent c0f83d1 commit b513b0d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/gpu/drm/virtio/virtgpu_object.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,17 @@ bool virtio_gpu_is_shmem(struct virtio_gpu_object *bo)
123123
struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
124124
size_t size)
125125
{
126-
struct virtio_gpu_object *bo;
126+
struct virtio_gpu_object_shmem *shmem;
127+
struct drm_gem_shmem_object *dshmem;
127128

128-
bo = kzalloc(sizeof(*bo), GFP_KERNEL);
129-
if (!bo)
129+
shmem = kzalloc(sizeof(*shmem), GFP_KERNEL);
130+
if (!shmem)
130131
return NULL;
131132

132-
bo->base.base.funcs = &virtio_gpu_shmem_funcs;
133-
bo->base.map_cached = true;
134-
return &bo->base.base;
133+
dshmem = &shmem->base.base;
134+
dshmem->base.funcs = &virtio_gpu_shmem_funcs;
135+
dshmem->map_cached = true;
136+
return &dshmem->base;
135137
}
136138

137139
static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,

0 commit comments

Comments
 (0)