Commit 66085e20 authored by Benjamin Cheng's avatar Benjamin Cheng Committed by Alex Deucher
Browse files

drm/amdgpu: Add bounds checking to ib_{get,set}_value



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: default avatarBenjamin Cheng <benjamin.cheng@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarRuijing Dong <ruijing.dong@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
parent 4e819742
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -559,14 +559,17 @@ 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)
{
	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)
{
	if (idx < ib->length_dw)
		ib->ptr[idx] = value;
}