CVE-2026-53145: drm/gem: Try to fix change_handle ioctl, attempt 4
In the Linux kernel, the following vulnerability has been resolved:
drm/gem: Try to fix changehandle ioctl, attempt 4
[airlied: just added some comments on how to reenable] On-list because the cat is out of the bag and we're clearly not good enough to figure this out in private. The story thus far:
5e28b7b94408 ("drm: Set old handle to NULL before prime swap in changehandle") tried to fix a race condition between the gemclose and gemchangehandle ioctls, but got a few things wrong:
- There's a confusion with the local variable handle, which is actually the new handle, and so the two-stage trick was actually applied to the wrong idr slot. 7164d78559b0 ("drm/gem: fix race between changehandle and handledelete") tried to fix that by adding yet another code block, but forgot to add the error handling. Which meant we now have two paths, both kinda wrong.
- dc366607c41c ("drm: Replace old pointer to new idr") tried to apply another fix, but inconsistently, again because of the handle confusion - this would be the right fix (kinda, somewhat, it's a mess) if we'd do the two-stage approach for the new handle. Except that wasn't the intent of the original fix.
We also didn't have an igt merged for the original ioctl, which is a big no-go. This was attempted to address off-list in the original bugfix, and amd QA people claimed the bug was fixed now. Very clearly that's not the case. Here's my attempt to sort this out:
- Rename the local variable to newhandle, the old aliasing with args->handle is just too dangerously confusing.
- Merge the gem obj lookup with the two-stage idrreplace so that we avoid getting ourselves confused there.
- This means we don't have a surplus temporary reference anymore, only an inherited from the idr. A concurrent gemclose on the newhandle could steal that. Fix that with the same two-stage approach createtail uses. This is a bit overkill as documented in the comment, but I also don't trust my ability to understand this all correctly, so go with the established pattern we have from other ioctls instead for maximum paranoia.
- Adjust error paths. I've tried to make the error and success paths common, because they are identical except for which handle is removed and on which we call idrreplace to (re)install the object again. But that made things messier to read, so I've left it at the more verbose version, which unfortunately hides the symmetry in the entire code flow a bit.
- While at it, also replace the 7 space indent with 1 tab.
And finally, because I flat out don't trust my abilities here at all anymore:
- Disable the ioctl until we have the igt situation and everything else sorted out on-list and with full consensus.
v2:
Sashiko noticed that I didn't handle the error path for idrreplace correctly, it must be checked with ISERRORNULL like in gemhandledelete. So yeah, definitely should just the existing paths 1:1 because this is endless amounts of tricky.
Also add the Fixes: line for the original ioctl, I forgot that too.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch dc366607c41c - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch 5e28b7b94408 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Patch 7164d78559b0 - Configuration
Fix the idr_replace error path in the existing success/error handling flows for the change_handle ioctl (Sashiko reported the error path for idr_replace was not handled).
drm/gem change_handle ioctl idr_replace error path handling = handled - Configuration
Rename the local variable used for the new handle to new_handle and avoid confusing args->handle with the local handle; use a two-stage approach for the new handle and do not leave surplus temporary references.
drm/gem change_handle ioctl new_handle handle usage = use new_handle for the new handle and avoid aliasing with handle - Configuration
Before the prime swap in the change_handle ioctl, set the old handle to NULL (as described: 'Set old handle to NULL before prime swap').
drm/gem change_handle ioctl prime swap NULL assignment = set old handle to NULL before prime swap - Configuration
Fix the race between gem_close on the new_handle and idr_replace by applying the established two-stage approach for the new handle and checking with IS_ERR_OR_NULL like in existing patterns (e.g., create_tail uses it).
drm/gem change_handle ioctl concurrent gem_close race handling = two-stage approach with IS_ERR_OR_NULL checks - Configuration
Add a Fixes: line for the original ioctl as mentioned ('And finally, because I flat out don't trust my abilities... Also add the Fixes: line for the original ioctl').
drm/gem change_handle ioctl Fixes metadata = add Fixes: line for the original ioctl
Event History
Frequently Asked Questions
What is the severity of CVE-2026-53145?
The severity of CVE-2026-53145 is classified as high with a CVSS score of 7.8.
How do I fix CVE-2026-53145?
To fix CVE-2026-53145, ensure that you apply the latest patches provided by your Linux distribution.
What types of systems are affected by CVE-2026-53145?
CVE-2026-53145 affects the Linux kernel and, consequently, systems running Red Hat Enterprise Linux and similar Linux distributions.
What kind of vulnerability is CVE-2026-53145 categorized as?
CVE-2026-53145 is categorized as a race condition vulnerability.
What components are involved in the CVE-2026-53145 vulnerability?
The vulnerability involves the drm/gem change_handle ioctl component within the Linux kernel.