Skip to content

Commit 7423187

Browse files
matt-auldlucasdemarchi
authored andcommitted
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: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Signed-off-by: Matthew Auld <[email protected]> Cc: Matthew Brost <[email protected]> Cc: <[email protected]> # v6.8+ Reviewed-by: Nirmoy Das <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit dcfd397) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 9e3c85d commit 7423187

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,23 +1765,18 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
17651765
if (IS_ERR(vm))
17661766
return PTR_ERR(vm);
17671767

1768-
err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
1769-
if (err)
1770-
goto err_close_and_put;
1771-
17721768
if (xe->info.has_asid) {
17731769
down_write(&xe->usm.lock);
17741770
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
17751771
XA_LIMIT(1, XE_MAX_ASID - 1),
17761772
&xe->usm.next_asid, GFP_KERNEL);
17771773
up_write(&xe->usm.lock);
17781774
if (err < 0)
1779-
goto err_free_id;
1775+
goto err_close_and_put;
17801776

17811777
vm->usm.asid = asid;
17821778
}
17831779

1784-
args->vm_id = id;
17851780
vm->xef = xe_file_get(xef);
17861781

17871782
/* Record BO memory for VM pagetable created against client */
@@ -1794,10 +1789,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
17941789
args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE);
17951790
#endif
17961791

1792+
/* user id alloc must always be last in ioctl to prevent UAF */
1793+
err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
1794+
if (err)
1795+
goto err_close_and_put;
1796+
1797+
args->vm_id = id;
1798+
17971799
return 0;
17981800

1799-
err_free_id:
1800-
xa_erase(&xef->vm.xa, id);
18011801
err_close_and_put:
18021802
xe_vm_close_and_put(vm);
18031803

0 commit comments

Comments
 (0)