Skip to content

Commit 44b6535

Browse files
vivekkreddydigetx
authored andcommitted
drm/virtio: Fix NULL pointer deref in virtgpu_dma_buf_free_obj()
There is a chance that obj->dma_buf would be NULL by the time virtgpu_dma_buf_free_obj() is called. This can happen for imported prime objects, when drm_gem_object_exported_dma_buf_free() gets called on them before drm_gem_object_free(). This is because drm_gem_object_exported_dma_buf_free() explicitly sets obj->dma_buf to NULL. Therefore, fix this issue by storing the dma_buf pointer in the virtio_gpu_object instance and using it in virtgpu_dma_buf_free_obj. This stored pointer is guaranteed to be valid until the object is freed as we took a reference on it in virtgpu_gem_prime_import(). Fixes: 415cb45 ("drm/virtio: Use dma_buf from GEM object instance") Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com> Cc: Thomas Zimmermann <tzimmermann@suse.de> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Link: https://lore.kernel.org/r/20250501232419.180337-1-vivek.kasireddy@intel.com
1 parent 9b8f320 commit 44b6535

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

drivers/gpu/drm/virtio/virtgpu_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct virtio_gpu_object_params {
8888

8989
struct virtio_gpu_object {
9090
struct drm_gem_shmem_object base;
91+
struct dma_buf *dma_buf;
9192
struct sg_table *sgt;
9293
uint32_t hw_res_handle;
9394
bool dumb;

drivers/gpu/drm/virtio/virtgpu_prime.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void virtgpu_dma_buf_free_obj(struct drm_gem_object *obj)
206206
struct virtio_gpu_device *vgdev = obj->dev->dev_private;
207207

208208
if (drm_gem_is_imported(obj)) {
209-
struct dma_buf *dmabuf = obj->dma_buf;
209+
struct dma_buf *dmabuf = bo->dma_buf;
210210

211211
dma_resv_lock(dmabuf->resv, NULL);
212212
virtgpu_dma_buf_unmap(bo);
@@ -332,6 +332,7 @@ struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
332332

333333
obj->import_attach = attach;
334334
get_dma_buf(buf);
335+
bo->dma_buf = buf;
335336

336337
ret = virtgpu_dma_buf_init_obj(dev, bo, attach);
337338
if (ret < 0)

0 commit comments

Comments
 (0)