Skip to contentSkip to conversation

drm/amdgpu: bounds check xcp_id in release_sched

PATCH In review Lijo Lazar 2 participants 2 messages Jun 16

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amdgpu: bounds check xcp_id in release_sched

Avoid out-of-bounds xcp[] access, e.g. when xcp_id is AMDGPU_XCP_NO_PARTITION.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +2 -1
index 389f69c7d5c3..14cef0264c17 100644
@@ -475,7 +475,8 @@ void amdgpu_xcp_release_sched(struct amdgpu_device *adev,
 	sched = entity->entity.rq->sched;
 	if (drm_sched_wqueue_ready(sched)) {
 		ring = to_amdgpu_ring(entity->entity.rq->sched);
-		atomic_dec(&adev->xcp_mgr->xcp[ring->xcp_id].ref_cnt);
+		if (ring->xcp_id < MAX_XCP)
+			atomic_dec(&adev->xcp_mgr->xcp[ring->xcp_id].ref_cnt);
 	}
 }
 
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lijo Lazar

Avoid out-of-bounds xcp[] access, e.g. when xcp_id is AMDGPU_XCP_NO_PARTITION.

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +2 -2
index 389f69c7d5c3..14cef0264c17 100644
@@ -475,7 +475,8 @@ void amdgpu_xcp_release_sched(struct amdgpu_device *adev,
        sched = entity->entity.rq->sched;
        if (drm_sched_wqueue_ready(sched)) {
                ring = to_amdgpu_ring(entity->entity.rq->sched);
-               atomic_dec(&adev->xcp_mgr->xcp[ring->xcp_id].ref_cnt);
+               if (ring->xcp_id < MAX_XCP)
+                       atomic_dec(&adev->xcp_mgr->xcp[ring->xcp_id].ref_cnt);
        }
 }
 
--

2.49.0