Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Fix off by one in current_memory_partition_show()

The >= ARRAY_SIZE() should be > ARRAY_SIZE() to prevent an out of
bounds read.

Fixes: 012be6f22c01 ("drm/amdgpu: Add sysfs interfaces for NPS mode")
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Dan Carpenter and committed by
Alex Deucher
9f7e94af 336568de

+1 -1
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
··· 1199 1199 enum amdgpu_memory_partition mode; 1200 1200 1201 1201 mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev); 1202 - if ((mode > ARRAY_SIZE(nps_desc)) || 1202 + if ((mode >= ARRAY_SIZE(nps_desc)) || 1203 1203 (BIT(mode) & AMDGPU_ALL_NPS_MASK) != BIT(mode)) 1204 1204 return sysfs_emit(buf, "UNKNOWN\n"); 1205 1205