Commit a018d181 authored by Junrui Luo's avatar Junrui Luo Committed by Alex Deucher
Browse files

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: f09c1e60 ("drm/amdgpu: generate doorbell index for userqueue")
Reported-by: default avatarYuhao Jiang <danisjiang@gmail.com>
Signed-off-by: default avatarJunrui Luo <moonafterrain@outlook.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
(cherry picked from commit de1ef4ff)
Cc: stable@vger.kernel.org
parent a3ffaa5b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -600,6 +600,13 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
		goto unpin_bo;
	}

	/* Validate doorbell_offset is within the doorbell BO */
	if ((u64)db_info->doorbell_offset * db_size + db_size >
	    amdgpu_bo_size(db_obj->obj)) {
		r = -EINVAL;
		goto unpin_bo;
	}

	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_obj->obj,
					     db_info->doorbell_offset, db_size);
	drm_dbg_driver(adev_to_drm(uq_mgr->adev),