Commit 74231870 authored by Matthew Auld's avatar Matthew Auld Committed by Lucas De Marchi

drm/xe/vm: move xa_alloc to prevent UAF

Evil user can guess the next id of the vm before the ioctl completes and
then call vm destroy ioctl to trigger UAF since create ioctl is still
referencing the same vm. Move the xa_alloc all the way to the end to
prevent this.

v2:
 - Rebase

Fixes: dd08ebf6 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: <stable@vger.kernel.org> # v6.8+
Reviewed-by: default avatarNirmoy Das <nirmoy.das@intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240925071426.144015-3-matthew.auld@intel.com
(cherry picked from commit dcfd3971327f3ee92765154baebbaece833d3ca9)
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
parent 9e3c85dd
...@@ -1765,10 +1765,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data, ...@@ -1765,10 +1765,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
if (IS_ERR(vm)) if (IS_ERR(vm))
return PTR_ERR(vm); return PTR_ERR(vm);
err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
if (err)
goto err_close_and_put;
if (xe->info.has_asid) { if (xe->info.has_asid) {
down_write(&xe->usm.lock); down_write(&xe->usm.lock);
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm, err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
...@@ -1776,12 +1772,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data, ...@@ -1776,12 +1772,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
&xe->usm.next_asid, GFP_KERNEL); &xe->usm.next_asid, GFP_KERNEL);
up_write(&xe->usm.lock); up_write(&xe->usm.lock);
if (err < 0) if (err < 0)
goto err_free_id; goto err_close_and_put;
vm->usm.asid = asid; vm->usm.asid = asid;
} }
args->vm_id = id;
vm->xef = xe_file_get(xef); vm->xef = xe_file_get(xef);
/* Record BO memory for VM pagetable created against client */ /* Record BO memory for VM pagetable created against client */
...@@ -1794,10 +1789,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data, ...@@ -1794,10 +1789,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE); args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE);
#endif #endif
/* user id alloc must always be last in ioctl to prevent UAF */
err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
if (err)
goto err_close_and_put;
args->vm_id = id;
return 0; return 0;
err_free_id:
xa_erase(&xef->vm.xa, id);
err_close_and_put: err_close_and_put:
xe_vm_close_and_put(vm); xe_vm_close_and_put(vm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment