Skip to content

Commit a73345b

Browse files
vprosyakalexdeucher
authored andcommitted
Revert "drm/amdgpu: fix slab-use-after-free in amdgpu_userq_mgr_fini"
This reverts commit 5fb9042. The original patch moved `amdgpu_userq_mgr_fini()` to the driver's `postclose` callback, which is called after `drm_gem_release()` in the DRM file cleanup sequence.If a user application crashes or aborts without cleaning up its user queues, 'drm_gem_release()` may free GEM objects that are still referenced by active user queues, leading to use-after-free. By reverting, we ensure that user queues are disabled and cleaned up before any GEM objects are released, preventing this class of bug. However, this reintroduces a race during PCI hot-unplug, where device removal can race with per-file cleanup, leading to use-after-free in suspend/unplug paths. This will be fixed in the next patch. Fixes: 5fb9042 ("drm/amdgpu: fix slab-use-after-free in amdgpu_userq_mgr_fini+0x70c") Signed-off-by: Vitaly Prosyak <[email protected]> Acked-by: Alex Deucher <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent df27190 commit a73345b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,20 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
29112911
return ret;
29122912
}
29132913

2914+
static int amdgpu_drm_release(struct inode *inode, struct file *filp)
2915+
{
2916+
struct drm_file *file_priv = filp->private_data;
2917+
struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
2918+
2919+
if (fpriv) {
2920+
fpriv->evf_mgr.fd_closing = true;
2921+
amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
2922+
amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
2923+
}
2924+
2925+
return drm_release(inode, filp);
2926+
}
2927+
29142928
long amdgpu_drm_ioctl(struct file *filp,
29152929
unsigned int cmd, unsigned long arg)
29162930
{
@@ -2962,7 +2976,7 @@ static const struct file_operations amdgpu_driver_kms_fops = {
29622976
.owner = THIS_MODULE,
29632977
.open = drm_open,
29642978
.flush = amdgpu_flush,
2965-
.release = drm_release,
2979+
.release = amdgpu_drm_release,
29662980
.unlocked_ioctl = amdgpu_drm_ioctl,
29672981
.mmap = drm_gem_mmap,
29682982
.poll = drm_poll,

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
15011501
amdgpu_vm_bo_del(adev, fpriv->prt_va);
15021502
amdgpu_bo_unreserve(pd);
15031503
}
1504-
fpriv->evf_mgr.fd_closing = true;
1505-
amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
1506-
amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
15071504

15081505
amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
15091506
amdgpu_vm_fini(adev, &fpriv->vm);

0 commit comments

Comments
 (0)