Skip to content

Commit 730b724

Browse files
matt-auldrodrigovivi
authored andcommitted
drm/xe: prevent UAF around preempt fence
The fence lock is part of the queue, therefore in the current design anything locking the fence should then also hold a ref to the queue to prevent the queue from being freed. However, currently it looks like we signal the fence and then drop the queue ref, but if something is waiting on the fence, the waiter is kicked to wake up at some later point, where upon waking up it first grabs the lock before checking the fence state. But if we have already dropped the queue ref, then the lock might already be freed as part of the queue, leading to uaf. To prevent this, move the fence lock into the fence itself so we don't run into lifetime issues. Alternative might be to have device level lock, or only release the queue in the fence release callback, however that might require pushing to another worker to avoid locking issues. Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") References: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/2454 References: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/2342 References: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/2020 Signed-off-by: Matthew Auld <[email protected]> Cc: Matthew Brost <[email protected]> Cc: <[email protected]> # v6.8+ Reviewed-by: Matthew Brost <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 7116c35) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 15939ca commit 730b724

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

drivers/gpu/drm/xe/xe_exec_queue.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
643643

644644
if (xe_vm_in_preempt_fence_mode(vm)) {
645645
q->lr.context = dma_fence_context_alloc(1);
646-
spin_lock_init(&q->lr.lock);
647646

648647
err = xe_vm_add_compute_exec_queue(vm, q);
649648
if (XE_IOCTL_DBG(xe, err))

drivers/gpu/drm/xe/xe_exec_queue_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ struct xe_exec_queue {
126126
u32 seqno;
127127
/** @lr.link: link into VM's list of exec queues */
128128
struct list_head link;
129-
/** @lr.lock: preemption fences lock */
130-
spinlock_t lock;
131129
} lr;
132130

133131
/** @ops: submission backend exec queue operations */

drivers/gpu/drm/xe/xe_preempt_fence.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ xe_preempt_fence_arm(struct xe_preempt_fence *pfence, struct xe_exec_queue *q,
128128
{
129129
list_del_init(&pfence->link);
130130
pfence->q = xe_exec_queue_get(q);
131+
spin_lock_init(&pfence->lock);
131132
dma_fence_init(&pfence->base, &preempt_fence_ops,
132-
&q->lr.lock, context, seqno);
133+
&pfence->lock, context, seqno);
133134

134135
return &pfence->base;
135136
}

drivers/gpu/drm/xe/xe_preempt_fence_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ struct xe_preempt_fence {
2525
struct xe_exec_queue *q;
2626
/** @preempt_work: work struct which issues preemption */
2727
struct work_struct preempt_work;
28+
/** @lock: dma-fence fence lock */
29+
spinlock_t lock;
2830
/** @error: preempt fence is in error state */
2931
int error;
3032
};

0 commit comments

Comments
 (0)