Skip to contentSkip to conversation

accel/amdxdna: Fix double drm_gem_object_put() in dma-buf mmap error path

PATCH New Jhonraushan 1 participant 1 message Jul 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 accel/amdxdna: Fix double drm_gem_object_put() in dma-buf mmap error path

amdxdna_gem_dmabuf_mmap() takes a reference with drm_gem_object_get() and, on the vm_insert_pages() failure path, jumps to close_vma which calls vma->vm_ops->close(). For a shmem GEM object vm_ops is drm_gem_shmem_vm_ops, whose .close (drm_gem_shmem_vm_close -> drm_gem_vm_close) already drops that reference. Execution then falls through to put_obj and drops it a second time.

This underflows the GEM object refcount and frees it prematurely while the dma-buf still references it, leading to a use-after-free.

Return directly after vm_ops->close() instead of falling through to the extra drm_gem_object_put(), matching the sibling amdxdna_insert_pages() error path.

Fixes e486147c912f ("accel/amdxdna: Add BO import and export")
---
 drivers/accel/amdxdna/amdxdna_gem.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/accel/amdxdna/amdxdna_gem.c +5 -0
index 891112c2cddf..3ac8c345b25b 100644
@@ -526,7 +526,12 @@ static int amdxdna_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struc
 	return 0;
 
 close_vma:
+	/* vm_ops->close() drops the reference taken by drm_gem_object_get()
+	 * above, so return directly instead of falling through to put_obj
+	 * and dropping it a second time.
+	 */
 	vma->vm_ops->close(vma);
+	return ret;
 put_obj:
 	drm_gem_object_put(gobj);
 	return ret;
Signature · 1 line
2.43.0