Skip to content

Commit 0fb5cb5

Browse files
lolzballsgregkh
authored andcommitted
drm/amdgpu: Add bounds checking to ib_{get,set}_value
commit 66085e2 upstream. 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4a8093c commit 0fb5cb5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,18 @@ void amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
440440

441441
int amdgpu_ring_init_mqd(struct amdgpu_ring *ring);
442442

443-
static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, int idx)
443+
static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, uint32_t idx)
444444
{
445-
return ib->ptr[idx];
445+
if (idx < ib->length_dw)
446+
return ib->ptr[idx];
447+
return 0;
446448
}
447449

448-
static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, int idx,
450+
static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, uint32_t idx,
449451
uint32_t value)
450452
{
451-
ib->ptr[idx] = value;
453+
if (idx < ib->length_dw)
454+
ib->ptr[idx] = value;
452455
}
453456

454457
int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,

0 commit comments

Comments
 (0)