Skip to contentSkip to conversation

drm/amdgpu: check a user-provided number of BOs in list

PATCH New Alex Deucher 1 participant 1 message Apr 28, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: check a user-provided number of BOs in list

From: Denis Arefev <[email protected]>

The user can set any value to the variable ‘bo_number’, via the ioctl command DRM_IOCTL_AMDGPU_BO_LIST. This will affect the arithmetic expression ‘in->bo_number * in->bo_info_size’, which is prone to overflow. Add a valid value check.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

v2: drop 0 check as a BO list of 0 is valid (Alex)

Fixes 964d0fbf6301 ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +3 -0
index 702f6610d0243..81875df6295bb 100644
@@ -189,6 +189,9 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
 	struct drm_amdgpu_bo_list_entry *info;
 	int r;
 
+	if (in->bo_number > USHRT_MAX)
+		return -EINVAL;
+
 	info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
Signature · 1 line
2.49.0