]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Fix error cleanup in xe_exec_queue_create_ioctl()
authorShuicheng Lin <shuicheng.lin@intel.com>
Wed, 8 Apr 2026 02:06:47 +0000 (02:06 +0000)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Wed, 29 Apr 2026 16:51:20 +0000 (12:51 -0400)
Two error handling issues exist in xe_exec_queue_create_ioctl():

1. When xe_hw_engine_group_add_exec_queue() fails, the error path jumps
   to put_exec_queue which skips xe_exec_queue_kill(). If the VM is in
   preempt fence mode, xe_vm_add_compute_exec_queue() has already added
   the queue to the VM's compute exec queue list. Skipping the kill
   leaves the queue on that list, leading to a dangling pointer after
   the queue is freed.

2. When xa_alloc() fails after xe_hw_engine_group_add_exec_queue() has
   succeeded, the error path does not call
   xe_hw_engine_group_del_exec_queue() to remove the queue from the hw
   engine group list. The queue is then freed while still linked into
   the hw engine group, causing a use-after-free.

Fix both by:
- Changing the xe_hw_engine_group_add_exec_queue() failure path to jump
  to kill_exec_queue so that xe_exec_queue_kill() properly removes the
  queue from the VM's compute list.
- Adding a del_hw_engine_group label before kill_exec_queue for the
  xa_alloc() failure path, which removes the queue from the hw engine
  group before proceeding with the rest of the cleanup.

Fixes: 7970cb36966c ("'drm/xe/hw_engine_group: Register hw engine group's exec queues")
Cc: Francois Dugast <francois.dugast@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Assisted-by: Claude:claude-opus-4.6
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20260408020647.3397933-1-shuicheng.lin@intel.com
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
(cherry picked from commit 37c831f401746a45d510b312b0ed7a77b1e06ec8)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_exec_queue.c

index 8de8ec784a039d2ba35b3a7f25daec39a2231ee9..071b8c41df43ed4fa1e7747ba0f3967ed415472b 100644 (file)
@@ -1405,7 +1405,7 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
                if (q->vm && q->hwe->hw_engine_group) {
                        err = xe_hw_engine_group_add_exec_queue(q->hwe->hw_engine_group, q);
                        if (err)
-                               goto put_exec_queue;
+                               goto kill_exec_queue;
                }
        }
 
@@ -1416,12 +1416,15 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
        /* user id alloc must always be last in ioctl to prevent UAF */
        err = xa_alloc(&xef->exec_queue.xa, &id, q, xa_limit_32b, GFP_KERNEL);
        if (err)
-               goto kill_exec_queue;
+               goto del_hw_engine_group;
 
        args->exec_queue_id = id;
 
        return 0;
 
+del_hw_engine_group:
+       if (q->vm && q->hwe && q->hwe->hw_engine_group)
+               xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
 kill_exec_queue:
        xe_exec_queue_kill(q);
 delete_queue_group: