[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aedbcd77-3cb6-48a6-b7ec-b2e5d3d0996c@amd.com>
Date: Mon, 14 Apr 2025 11:27:45 +0200
From: Christian König <christian.koenig@....com>
To: Denis Arefev <arefev@...mel.ru>, Alex Deucher <alexander.deucher@....com>
Cc: David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
amd-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, lvc-project@...uxtesting.org,
stable@...r.kernel.org
Subject: Re: [PATCH] drm/amdgpu: check a user-provided number of BOs in list
Coming back to the original patch.
Am 08.04.25 um 11:17 schrieb Denis Arefev:
> 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.
>
> Fixes: 964d0fbf6301 ("drm/amdgpu: Allow to create BO lists in CS ioctl v3")
> Cc: stable@...r.kernel.org
> Signed-off-by: Denis Arefev <arefev@...mel.ru>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 702f6610d024..dd30d2426ff7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -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 || in->bo_number > UINT_MAX / info_size)
> + return -EINVAL;
> +
As discussed with Linus the goal here is not to avoid the warning, but rather to apply a reasonable limit.
Since we already use an u16 for the number of BOs in other cases it is probably reasonable to assume that we will never have more than USHRT_MAX number of BOs here as well.
So please change the patch accordingly and hopefully nobody will complain.
Regards,
Christian.
> info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
> if (!info)
> return -ENOMEM;
Powered by blists - more mailing lists