Skip to content

Commit a018d18

Browse files
avasummeralexdeucher
authored andcommitted
drm/amdgpu: validate doorbell_offset in user queue creation
amdgpu_userq_get_doorbell_index() passes the user-provided doorbell_offset to amdgpu_doorbell_index_on_bar() without bounds checking. An arbitrarily large doorbell_offset can cause the calculated doorbell index to fall outside the allocated doorbell BO, potentially corrupting kernel doorbell space. Validate that doorbell_offset falls within the doorbell BO before computing the BAR index, using u64 arithmetic to prevent overflow. Fixes: f09c1e6 ("drm/amdgpu: generate doorbell index for userqueue") Reported-by: Yuhao Jiang <[email protected]> Signed-off-by: Junrui Luo <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit de1ef4f) Cc: [email protected]
1 parent a3ffaa5 commit a018d18

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
600600
goto unpin_bo;
601601
}
602602

603+
/* Validate doorbell_offset is within the doorbell BO */
604+
if ((u64)db_info->doorbell_offset * db_size + db_size >
605+
amdgpu_bo_size(db_obj->obj)) {
606+
r = -EINVAL;
607+
goto unpin_bo;
608+
}
609+
603610
index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
604611
db_info->doorbell_offset, db_size);
605612
drm_dbg_driver(adev_to_drm(uq_mgr->adev),

0 commit comments

Comments
 (0)