]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
drm/gem: fix race between change_handle and handle_delete
authorZhenghang Xiao <kipreyyy@gmail.com>
Tue, 26 May 2026 08:53:13 +0000 (16:53 +0800)
committerDave Airlie <airlied@redhat.com>
Fri, 29 May 2026 21:01:39 +0000 (07:01 +1000)
commit7164d78559b0ff29931a366a840a9e5dd53d4b7c
treed3e48551711e666c87e29e29cc2fb17867a7a4ee
parent6e40c937893338ed0b627c08f712ce7d66ddcf84
drm/gem: fix race between change_handle and handle_delete

drm_gem_change_handle_ioctl leaves the old handle live in the IDR
during the window between spin_unlock(table_lock) and the final
spin_lock(table_lock). A concurrent drm_gem_handle_delete on the old
handle succeeds in this window, decrements handle_count to 0, and frees
the GEM object while the new handle's IDR entry still references it.

NULL the old handle's IDR entry before dropping table_lock so that any
concurrent GEM_CLOSE on the old handle sees NULL and returns -EINVAL.
Restore the old entry on the prime-bookkeeping error path.

Fixes: 5e28b7b94408 ("drm: Set old handle to NULL before prime swap in change_handle")
Signed-off-by: Zhenghang Xiao <kipreyyy@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patch.msgid.link/20260526085313.26791-1-kipreyyy@gmail.com
drivers/gpu/drm/drm_gem.c