Skip to content

Commit 41d4193

Browse files
robclarkrodrigovivi
authored andcommitted
drm/i915: Avoid potential vm use-after-free
Adding the vm to the vm_xa table makes it visible to userspace, which could try to race with us to close the vm. So we need to take our extra reference before putting it in the table. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Fixes: 9ec8795 ("drm/i915: Drop __rcu from gem_context->vm") Cc: <[email protected]> # v5.16+ Signed-off-by: Tvrtko Ursulin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 99343c4) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 6d796c5 commit 41d4193

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,11 +1861,19 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv,
18611861
vm = ctx->vm;
18621862
GEM_BUG_ON(!vm);
18631863

1864+
/*
1865+
* Get a reference for the allocated handle. Once the handle is
1866+
* visible in the vm_xa table, userspace could try to close it
1867+
* from under our feet, so we need to hold the extra reference
1868+
* first.
1869+
*/
1870+
i915_vm_get(vm);
1871+
18641872
err = xa_alloc(&file_priv->vm_xa, &id, vm, xa_limit_32b, GFP_KERNEL);
1865-
if (err)
1873+
if (err) {
1874+
i915_vm_put(vm);
18661875
return err;
1867-
1868-
i915_vm_get(vm);
1876+
}
18691877

18701878
GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */
18711879
args->value = id;

0 commit comments

Comments
 (0)