Skip to contentSkip to conversation

drm/i915: Fix UAF race between relocation and GEM_CLOSE

PATCH In review Yassine Mounir 3 participants 6 messages Mar 24 – Mar 25

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

PATCH 1/1 drm/i915: Fix UAF race between relocation and GEM_CLOSE

A use-after-free (UAF) vulnerability was identified in the i915 driver within eb_relocate_vma. The issue arises from a race condition where a concurrent DRM_IOCTL_GEM_CLOSE can drop the GEM object's reference count to zero while the relocation thread is still processing entries.

This results in the kernel attempting to access freed memory in eb_relocate_entry, leading to a display pipeline hang and potential system instability.

Fix:
Wrap the relocation phase with i915_gem_object_get() and i915_gem_object_put() to ensure the object remains valid throughout the operation, even if user-space requests to close the handle.

---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +4 -0
@@ -1542,7 +1542,11 @@ eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma)
 		if (ret)
 			return ret;
 
+		/* Hold a reference to prevent UAF during concurrent GEM_CLOSE */
+		i915_gem_object_get(vma->obj);
 		ret = eb_relocate_entry(eb, vma, rel);
+		i915_gem_object_put(vma->obj);
+
 		if (ret)
 			return ret;
 	}
#1 lore raw
Quoted 9 lines · Yassine Mounir

A use-after-free (UAF) vulnerability was identified in the i915 driver within eb_relocate_vma. The issue arises from a race condition where a concurrent DRM_IOCTL_GEM_CLOSE can drop the GEM object's reference count to zero while the relocation thread is still processing entries.

This results in the kernel attempting to access freed memory in eb_relocate_entry, leading to a display pipeline hang and potential system instability.

Quoted 7 lines

Fix:
Wrap the relocation phase with i915_gem_object_get() and i915_gem_object_put() to ensure the object remains valid throughout the operation, even if user-space requests to close the handle.

No need for a reported-by when you create and sign off on a change.

drivers/gpu/drm/i915/i915_gem_execbuffer.c

Quoted 6 lines
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -0

There is no such file name in the current kernel tree, what version did you make this against?

drivers/gpu/drm/i915/i915_gem_execbuffer.c eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma) · line 1549

Quoted 9 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +4 -0
@@ -1542,7 +1542,11 @@ eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma)
 		if (ret)
 			return ret;
 
+		/* Hold a reference to prevent UAF during concurrent GEM_CLOSE */
+		i915_gem_object_get(vma->obj);
 		ret = eb_relocate_entry(eb, vma, rel);
+		i915_gem_object_put(vma->obj);
+

What prevents the object from going away right after the put call here?

thanks,

greg k-h

#2 lore raw

*Hi Greg,*

*My apologies for the confusion. I realized I was developing against a distribution kernel (6.18.12-kali). I understand now why the file paths do not match the current upstream tree.*

*Regarding the logic: The race condition happens specifically during the eb_relocate_entry call when a concurrent GEM_CLOSE drops the reference count to zero. The i915_gem_object_get is intended to pin the object's lifetime during this critical relocation window.*

*I will now rebase this fix against the latest drm-tip / mainline tree, remove the 'Reported-by' tag as suggested, and submit a v2 for review.*

*Thank you for your guidance.* *Best regards,*

*Yassine (Toji1)*

Quoted 49 lines · Greg KH
Quoted 9 lines · Yassine Mounir

A use-after-free (UAF) vulnerability was identified in the i915 driver within eb_relocate_vma. The issue arises from a race condition where a concurrent DRM_IOCTL_GEM_CLOSE can drop the GEM object's reference count to zero while the relocation thread is still processing entries.

This results in the kernel attempting to access freed memory in eb_relocate_entry, leading to a display pipeline hang and potential system instability.

Quoted 7 lines

Fix:
Wrap the relocation phase with i915_gem_object_get() and i915_gem_object_put() to ensure the object remains valid throughout the operation, even if user-space requests to close the handle.

No need for a reported-by when you create and sign off on a change.

drivers/gpu/drm/i915/i915_gem_execbuffer.c

Quoted 6 lines
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -0

There is no such file name in the current kernel tree, what version did you make this against?

drivers/gpu/drm/i915/i915_gem_execbuffer.c eb_relocate_vma(struct i915_execbuffer *eb,

Quoted 1 line
drivers/gpu/drm/i915/i915_gem_execbuffer.c +0 -0
@@ -1542,7 +1542,11 @@ eb_relocate_vma(struct i915_execbuffer *eb,

struct i915_vma *vma)

drivers/gpu/drm/i915/i915_gem_execbuffer.c eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma)

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
              if (ret)
                      return ret;
 
+             /* Hold a reference to prevent UAF during concurrent

GEM_CLOSE */

drivers/gpu/drm/i915/i915_gem_execbuffer.c eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma) · line 1549

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 -0
+             i915_gem_object_get(vma->obj);
              ret = eb_relocate_entry(eb, vma, rel);
+             i915_gem_object_put(vma->obj);
+

What prevents the object from going away right after the put call here?

thanks,

greg k-h

#3 lore raw
Quoted 1 line · Yassine Mounir

*Hi Greg,*

Hi, but please do not top-post nor send html email, that gets dropped by the mailing lists.

Quoted 8 lines

*My apologies for the confusion. I realized I was developing against a distribution kernel (6.18.12-kali). I understand now why the file paths do not match the current upstream tree.*

*Regarding the logic: The race condition happens specifically during the eb_relocate_entry call when a concurrent GEM_CLOSE drops the reference count to zero. The i915_gem_object_get is intended to pin the object's lifetime during this critical relocation window.*

But what happens if the object is dropped right after your call to put? It will now be gone and not be around to work for the rest of the loop.

thnaks,

greg k-h

#4 lore raw
Quoted 16 lines · Greg KH
Quoted 1 line · Yassine Mounir

*Hi Greg,*

Hi, but please do not top-post nor send html email, that gets dropped by the mailing lists.

Quoted 2 lines

*My apologies for the confusion. I realized I was developing against a distribution kernel (6.18.12-kali). I understand now why the file paths

do

Quoted 6 lines

not match the current upstream tree.*

*Regarding the logic: The race condition happens specifically during the eb_relocate_entry call when a concurrent GEM_CLOSE drops the reference count to zero. The i915_gem_object_get is intended to pin the object's lifetime during this critical relocation window.*

Quoted 7 lines

But what happens if the object is dropped right after your call to put? It will now be gone and not be around to work for the rest of the loop.

thnaks,

greg k-h

Hi Greg,

You are absolutely right about v1. I have just submitted v2 which addresses this concern.

In the new version, I moved i915_gem_object_get() to before the relocation loop starts and i915_gem_object_put() to the common exit path ('out' label). This ensures the object's lifetime is guaranteed and pinned throughout the entire relocation phase, regardless of concurrent GEM_CLOSE calls.

I also fixed the directory path and removed the Reported-by tag.

Thanks,

Yassine(toji1)

#5 lore raw

✗ LGCI.VerificationFailed: failure for drm/i915: Fix UAF race between relocation and GEM_CLOSE

In reply to Yassine Mounir
== Series Details ==

== Series Details ==

Series: drm/i915: Fix UAF race between relocation and GEM_CLOSE
URL : https://patchwork.freedesktop.org/series/163842/
State : failure

== Summary ==

Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!