drm/amdgpu/userq: reject mappings without a backing BO
Subsystems (2)
PATCH 1/1 drm/amdgpu/userq: reject mappings without a backing BO
PRT mappings have a bo_va but no backing BO. Reject them when validating queue buffers and when looking up the WPTR for MES or USERQ_SIGNAL, before passing the BO to the reservation or CPU mapping helpers.
Repeat the check at the WPTR lookups because the VM reservation is dropped between initial validation and use.
Without this, pointing a user queue's WPTR at a PRT (sparse) VA mapping makes mes_userq_create_wptr_mapping() dereference a NULL bo (base.bo) and oops in the reservation helper:
BUG: kernel NULL pointer dereference, address: 0000000000000158 Oops: 0000 [#1] SMP NOPTI CPU: 0 UID: 0 PID: 4558 Comm: amd_fuzzing Tainted: G E 7.1.0+ RIP: 0010:drm_exec_lock_obj+0x2b/0x140 [drm_exec] CR2: 0000000000000158 Call Trace: drm_exec_prepare_obj+0x25/0x60 [drm_exec] mes_userq_create_wptr_mapping+0xc4/0x1c0 [amdgpu] mes_userq_mqd_create+0x351/0x870 [amdgpu] amdgpu_userq_ioctl+0x7ef/0xf80 [amdgpu] drm_ioctl_kernel+0xac/0x110 [drm] drm_ioctl+0x2c6/0x5b0 [drm] amdgpu_drm_ioctl+0x4f/0x90 [amdgpu] __x64_sys_ioctl+0xa0/0xf0 do_syscall_64+0xa3/0x4d0
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
@@ -253,7 +253,7 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,return -EINVAL ; va_map =amdgpu_vm_bo_lookup_mapping (vm, start_addr); -if (!va_map) +if (!va_map || !va_map->bo_va->base.bo)return -EINVAL ;/* Lookup guarantees start_addr is mapped; ensure full span is covered. */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -1
@@ -386,7 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev, goto lock_error; mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, addr); -if (!mapping) { +if (!mapping || !mapping->bo_va->base.bo) { ret = -EINVAL ; goto lock_error; }
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -1
@@ -54,7 +54,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev, goto fail_lock; wptr_mapping =amdgpu_vm_bo_lookup_mapping (vm, wptr); -if (!wptr_mapping) { +if (!wptr_mapping || !wptr_mapping->bo_va->base.bo) { ret = -EINVAL ; goto fail_lock; }
Signature · 1 line
2.50.1
Quoted 27 lines · Jesse Zhang
PRT mappings have a
bo_vabut no backing BO. Reject them when validating queue buffers and when looking up the WPTR for MES orUSERQ_SIGNAL, before passing the BO to the reservation or CPU mapping helpers.Repeat the check at the WPTR lookups because the VM reservation is dropped between initial validation and use.
Without this, pointing a user queue's WPTR at a PRT (sparse) VA mapping makes
mes_userq_create_wptr_mapping()dereference a NULL bo (base.bo) and oops in the reservation helper:BUG: kernel NULL pointer dereference, address: 0000000000000158 Oops: 0000 [#1] SMP NOPTI CPU: 0 UID: 0 PID: 4558 Comm: amd_fuzzing Tainted: G E 7.1.0+ RIP: 0010:drm_exec_lock_obj+0x2b/0x140 [drm_exec] CR2: 0000000000000158 Call Trace: drm_exec_prepare_obj+0x25/0x60 [drm_exec] mes_userq_create_wptr_mapping+0xc4/0x1c0 [amdgpu] mes_userq_mqd_create+0x351/0x870 [amdgpu] amdgpu_userq_ioctl+0x7ef/0xf80 [amdgpu] drm_ioctl_kernel+0xac/0x110 [drm] drm_ioctl+0x2c6/0x5b0 [drm] amdgpu_drm_ioctl+0x4f/0x90 [amdgpu] __x64_sys_ioctl+0xa0/0xf0 do_syscall_64+0xa3/0x4d0
Quoted 1 line
Signed-off-by Jesse Zhang <[email protected]>
Quoted 45 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -253,7 +253,7 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,return -EINVAL ; va_map =amdgpu_vm_bo_lookup_mapping (vm, start_addr); -if (!va_map) +if (!va_map || !va_map->bo_va->base.bo)return -EINVAL ;/* Lookup guarantees start_addr is mapped; ensure full span is covered. */ drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1
-1@@ -386,7 +386,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev, goto lock_error; mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, addr); -if (!mapping) { +if (!mapping || !mapping->bo_va->base.bo) { ret = -EINVAL ; goto lock_error; }drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-1@@ -54,7 +54,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev, goto fail_lock; wptr_mapping =amdgpu_vm_bo_lookup_mapping (vm, wptr); -if (!wptr_mapping) { +if (!wptr_mapping || !wptr_mapping->bo_va->base.bo) { ret = -EINVAL ; goto fail_lock; }