]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: Add bounds checking to ib_{get,set}_value
authorBenjamin Cheng <benjamin.cheng@amd.com>
Wed, 25 Mar 2026 12:39:19 +0000 (08:39 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 3 Apr 2026 17:48:10 +0000 (13:48 -0400)
The uvd/vce/vcn code accesses the IB at predefined offsets without
checking that the IB is large enough. Check the bounds here. The caller
is responsible for making sure it can handle arbitrary return values.

Also make the idx a uint32_t to prevent overflows causing the condition
to fail.

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ruijing Dong <ruijing.dong@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h

index ce5af137ee400e28d4191875931a5b9fbe5af84a..715c9e43e13aa471a3e9d2e6f618551b4dd85878 100644 (file)
@@ -559,15 +559,18 @@ void amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
 
 int amdgpu_ring_init_mqd(struct amdgpu_ring *ring);
 
-static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, int idx)
+static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, uint32_t idx)
 {
-       return ib->ptr[idx];
+       if (idx < ib->length_dw)
+               return ib->ptr[idx];
+       return 0;
 }
 
-static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, int idx,
+static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, uint32_t idx,
                                       uint32_t value)
 {
-       ib->ptr[idx] = value;
+       if (idx < ib->length_dw)
+               ib->ptr[idx] = value;
 }
 
 int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,