[PATCH 2/5] drm/amdgpu: reject PRT mappings as user queue buffer VAs
Junrui Luo via B4 Relay <[email protected]>
| Newsgroups | org.kernel.vger.linux-media,org.freedesktop.lists.amd-gfx,org.freedesktop.lists.dri-devel,org.kernel.feeds.b4-sent,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
From: Junrui Luo <[email protected]> amdgpu_userq_input_va_validate() resolves a user-supplied queue_va, rptr_va or wptr_va to a VM mapping and latches userq_va_mapped on the owning bo_va. It only checks that a mapping exists and that the requested span is contained in it, never that the mapping has a backing BO. PRT mappings do not: amdgpu_gem_va_ioctl() routes every AMDGPU_VM_PAGE_PRT map through fpriv->prt_va, created via amdgpu_vm_bo_add(adev, vm, NULL), so base.bo stays NULL while amdgpu_vm_bo_insert_map() still sets mapping->bo_va. A VA inside such a mapping therefore passes validation and marks fpriv->prt_va as userq mapped. The flag is never cleared. On the next unmap of any PRT mapping in that VM, amdgpu_vm_bo_unmap() sees userq_va_mapped and calls amdgpu_userq_gem_va_unmap_validate(), which reads bo_va->base.bo->tbo.base.resv before its ip_mask guard, leading to a NULL pointer dereference. Fix by rejecting a mapping without a backing BO in the validation helper, so the invariant amdgpu_userq_gem_va_unmap_validate() relies on holds by construction. A sparse mapping has no memory behind it and cannot serve as a ring, rptr or wptr buffer. Fixes: 2e7ceac0ea41 ("drm/amdgpu: validate userq va for GEM unmap") Reported-by: Yuhao Jiang <[email protected]> Assisted-by: Claude:claude-opus-5 Cc: [email protected] Signed-off-by: Junrui Luo <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index 6d3ed55e9ab4..bec107216811 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -259,6 +259,14 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev, if (!va_map) return -EINVAL; + /* + * A PRT mapping has no backing BO and so can't carry the eviction + * fence which amdgpu_userq_gem_va_unmap_validate() waits on. Reject it + * here, otherwise that helper dereferences a NULL bo on GEM unmap. + */ + if (!va_map->bo_va->base.bo) + return -EINVAL; + /* Lookup guarantees start_page is mapped; ensure full span is covered. */ if ((end_addr >> AMDGPU_GPU_PAGE_SHIFT) <= va_map->last) { va_map->bo_va->userq_va_mapped = true; -- 2.51.2