mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
@ 2025-04-18  8:31 Denis Arefev
  2025-04-22  9:12 ` AW: " Koenig, Christian
  0 siblings, 1 reply; 7+ messages in thread
From: Denis Arefev @ 2025-04-18  8:31 UTC (permalink / raw)
  To: Alex Deucher
  Cc: Christian König, David Airlie, Simona Vetter,
	Andrey Grodzovsky, Chunming Zhou, amd-gfx, dri-devel,
	linux-kernel, lvc-project, stable

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@vger.kernel.org
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
V1 -> V2:
Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian König <christian.koenig@amd.com> suggested

 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..85f7ee1e085d 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 > USHRT_MAX)
+		return -EINVAL;
+
 	info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* AW: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-18  8:31 [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list Denis Arefev
@ 2025-04-22  9:12 ` Koenig, Christian
  2025-04-22 13:46   ` Alex Deucher
  0 siblings, 1 reply; 7+ messages in thread
From: Koenig, Christian @ 2025-04-22  9:12 UTC (permalink / raw)
  To: Denis Arefev, Deucher, Alexander
  Cc: David Airlie, Simona Vetter, Andrey Grodzovsky, Chunming Zhou,
	amd-gfx, dri-devel, linux-kernel, lvc-project, stable

[AMD Official Use Only - AMD Internal Distribution Only]

Reviewed-by: Christian König <christian.koenig@amd.com>

________________________________________
Von: Denis Arefev <arefev@swemel.ru>
Gesendet: Freitag, 18. April 2025 10:31
An: Deucher, Alexander
Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky; Chunming Zhou; amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-project@linuxtesting.org; stable@vger.kernel.org
Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list

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@vger.kernel.org
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
V1 -> V2:
Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian König <christian.koenig@amd.com> suggested

 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..85f7ee1e085d 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 > USHRT_MAX)
+               return -EINVAL;
+
        info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
        if (!info)
                return -ENOMEM;
--
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-22  9:12 ` AW: " Koenig, Christian
@ 2025-04-22 13:46   ` Alex Deucher
  2025-04-22 16:26     ` Deucher, Alexander
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Deucher @ 2025-04-22 13:46 UTC (permalink / raw)
  To: Koenig, Christian
  Cc: Denis Arefev, Deucher, Alexander, David Airlie, Simona Vetter,
	Andrey Grodzovsky, Chunming Zhou, amd-gfx, dri-devel,
	linux-kernel, lvc-project, stable

Applied.  Thanks!

On Tue, Apr 22, 2025 at 5:13 AM Koenig, Christian
<Christian.Koenig@amd.com> wrote:
>
> [AMD Official Use Only - AMD Internal Distribution Only]
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> ________________________________________
> Von: Denis Arefev <arefev@swemel.ru>
> Gesendet: Freitag, 18. April 2025 10:31
> An: Deucher, Alexander
> Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky; Chunming Zhou; amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-project@linuxtesting.org; stable@vger.kernel.org
> Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
>
> 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@vger.kernel.org
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
> V1 -> V2:
> Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian König <christian.koenig@amd.com> suggested
>
>  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..85f7ee1e085d 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 > USHRT_MAX)
> +               return -EINVAL;
> +
>         info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
>         if (!info)
>                 return -ENOMEM;
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-22 13:46   ` Alex Deucher
@ 2025-04-22 16:26     ` Deucher, Alexander
  2025-04-23 14:29       ` Christian König
  0 siblings, 1 reply; 7+ messages in thread
From: Deucher, Alexander @ 2025-04-22 16:26 UTC (permalink / raw)
  To: Alex Deucher, Koenig, Christian
  Cc: Denis Arefev, David Airlie, Simona Vetter, Andrey Grodzovsky,
	Chunming Zhou, amd-gfx, dri-devel, linux-kernel, lvc-project,
	stable

[Public]

> -----Original Message-----
> From: Alex Deucher <alexdeucher@gmail.com>
> Sent: Tuesday, April 22, 2025 9:46 AM
> To: Koenig, Christian <Christian.Koenig@amd.com>
> Cc: Denis Arefev <arefev@swemel.ru>; Deucher, Alexander
> <Alexander.Deucher@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter
> <simona@ffwll.ch>; Andrey Grodzovsky <andrey.grodzovsky@amd.com>;
> Chunming Zhou <david1.zhou@amd.com>; amd-gfx@lists.freedesktop.org; dri-
> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-
> project@linuxtesting.org; stable@vger.kernel.org
> Subject: Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
>
> Applied.  Thanks!

This change beaks the following IGT tests:

igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-create
igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-decode
igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-destroy
igt@amdgpu/amd_jpeg_dec@amdgpu_cs_jpeg_decode
igt@amdgpu/amd_cs_nop@cs-nops-with-nop-compute0@cs-nop-with-nop-compute0
igt@amdgpu/amd_cs_nop@cs-nops-with-sync-compute0@cs-nop-with-sync-compute0
igt@amdgpu/amd_cs_nop@cs-nops-with-fork-compute0@cs-nop-with-fork-compute0
igt@amdgpu/amd_cs_nop@cs-nops-with-sync-fork-compute0@cs-nop-with-sync-fork-compute0
igt@amdgpu/amd_basic@userptr-with-ip-dma@userptr
igt@amdgpu/amd_basic@cs-compute-with-ip-compute@cs-compute
igt@amdgpu/amd_basic@cs-sdma-with-ip-dma@cs-sdma
igt@amdgpu/amd_basic@eviction-test-with-ip-dma@eviction_test
igt@amdgpu/amd_cp_dma_misc@gtt_to_vram-amdgpu_hw_ip_compute0
igt@amdgpu/amd_cp_dma_misc@vram_to_gtt-amdgpu_hw_ip_compute0
igt@amdgpu/amd_cp_dma_misc@vram_to_vram-amdgpu_hw_ip_compute0

Alex

>
> On Tue, Apr 22, 2025 at 5:13 AM Koenig, Christian <Christian.Koenig@amd.com>
> wrote:
> >
> > [AMD Official Use Only - AMD Internal Distribution Only]
> >
> > Reviewed-by: Christian König <christian.koenig@amd.com>
> >
> > ________________________________________
> > Von: Denis Arefev <arefev@swemel.ru>
> > Gesendet: Freitag, 18. April 2025 10:31
> > An: Deucher, Alexander
> > Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky;
> > Chunming Zhou; amd-gfx@lists.freedesktop.org;
> > dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org;
> > lvc-project@linuxtesting.org; stable@vger.kernel.org
> > Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in
> > list
> >
> > 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@vger.kernel.org
> > Signed-off-by: Denis Arefev <arefev@swemel.ru>
> > ---
> > V1 -> V2:
> > Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian
> > König <christian.koenig@amd.com> suggested
> >
> >  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..85f7ee1e085d 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 > USHRT_MAX)
> > +               return -EINVAL;
> > +
> >         info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
> >         if (!info)
> >                 return -ENOMEM;
> > --
> > 2.43.0
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-22 16:26     ` Deucher, Alexander
@ 2025-04-23 14:29       ` Christian König
  2025-04-24 13:40         ` Alex Deucher
  0 siblings, 1 reply; 7+ messages in thread
From: Christian König @ 2025-04-23 14:29 UTC (permalink / raw)
  To: Deucher, Alexander, Alex Deucher
  Cc: Denis Arefev, David Airlie, Simona Vetter, Andrey Grodzovsky,
	Chunming Zhou, amd-gfx, dri-devel, linux-kernel, lvc-project,
	stable

On 4/22/25 18:26, Deucher, Alexander wrote:
> [Public]
> 
>> -----Original Message-----
>> From: Alex Deucher <alexdeucher@gmail.com>
>> Sent: Tuesday, April 22, 2025 9:46 AM
>> To: Koenig, Christian <Christian.Koenig@amd.com>
>> Cc: Denis Arefev <arefev@swemel.ru>; Deucher, Alexander
>> <Alexander.Deucher@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter
>> <simona@ffwll.ch>; Andrey Grodzovsky <andrey.grodzovsky@amd.com>;
>> Chunming Zhou <david1.zhou@amd.com>; amd-gfx@lists.freedesktop.org; dri-
>> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-
>> project@linuxtesting.org; stable@vger.kernel.org
>> Subject: Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
>>
>> Applied.  Thanks!
> 
> This change beaks the following IGT tests:
> 
> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-create
> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-decode
> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-destroy
> igt@amdgpu/amd_jpeg_dec@amdgpu_cs_jpeg_decode
> igt@amdgpu/amd_cs_nop@cs-nops-with-nop-compute0@cs-nop-with-nop-compute0
> igt@amdgpu/amd_cs_nop@cs-nops-with-sync-compute0@cs-nop-with-sync-compute0
> igt@amdgpu/amd_cs_nop@cs-nops-with-fork-compute0@cs-nop-with-fork-compute0
> igt@amdgpu/amd_cs_nop@cs-nops-with-sync-fork-compute0@cs-nop-with-sync-fork-compute0
> igt@amdgpu/amd_basic@userptr-with-ip-dma@userptr
> igt@amdgpu/amd_basic@cs-compute-with-ip-compute@cs-compute
> igt@amdgpu/amd_basic@cs-sdma-with-ip-dma@cs-sdma
> igt@amdgpu/amd_basic@eviction-test-with-ip-dma@eviction_test
> igt@amdgpu/amd_cp_dma_misc@gtt_to_vram-amdgpu_hw_ip_compute0
> igt@amdgpu/amd_cp_dma_misc@vram_to_gtt-amdgpu_hw_ip_compute0
> igt@amdgpu/amd_cp_dma_misc@vram_to_vram-amdgpu_hw_ip_compute0


Could it be that we used BO list with zero entries for those?

Christian.

> 
> Alex
> 
>>
>> On Tue, Apr 22, 2025 at 5:13 AM Koenig, Christian <Christian.Koenig@amd.com>
>> wrote:
>>>
>>> [AMD Official Use Only - AMD Internal Distribution Only]
>>>
>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>>
>>> ________________________________________
>>> Von: Denis Arefev <arefev@swemel.ru>
>>> Gesendet: Freitag, 18. April 2025 10:31
>>> An: Deucher, Alexander
>>> Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky;
>>> Chunming Zhou; amd-gfx@lists.freedesktop.org;
>>> dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org;
>>> lvc-project@linuxtesting.org; stable@vger.kernel.org
>>> Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in
>>> list
>>>
>>> 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@vger.kernel.org
>>> Signed-off-by: Denis Arefev <arefev@swemel.ru>
>>> ---
>>> V1 -> V2:
>>> Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian
>>> König <christian.koenig@amd.com> suggested
>>>
>>>  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..85f7ee1e085d 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 > USHRT_MAX)
>>> +               return -EINVAL;
>>> +
>>>         info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
>>>         if (!info)
>>>                 return -ENOMEM;
>>> --
>>> 2.43.0
>>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-23 14:29       ` Christian König
@ 2025-04-24 13:40         ` Alex Deucher
  2025-04-28 14:53           ` Christian König
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Deucher @ 2025-04-24 13:40 UTC (permalink / raw)
  To: Christian König
  Cc: Deucher, Alexander, Denis Arefev, David Airlie, Simona Vetter,
	Andrey Grodzovsky, Chunming Zhou, amd-gfx, dri-devel,
	linux-kernel, lvc-project, stable

On Wed, Apr 23, 2025 at 10:29 AM Christian König
<christian.koenig@amd.com> wrote:
>
> On 4/22/25 18:26, Deucher, Alexander wrote:
> > [Public]
> >
> >> -----Original Message-----
> >> From: Alex Deucher <alexdeucher@gmail.com>
> >> Sent: Tuesday, April 22, 2025 9:46 AM
> >> To: Koenig, Christian <Christian.Koenig@amd.com>
> >> Cc: Denis Arefev <arefev@swemel.ru>; Deucher, Alexander
> >> <Alexander.Deucher@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter
> >> <simona@ffwll.ch>; Andrey Grodzovsky <andrey.grodzovsky@amd.com>;
> >> Chunming Zhou <david1.zhou@amd.com>; amd-gfx@lists.freedesktop.org; dri-
> >> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-
> >> project@linuxtesting.org; stable@vger.kernel.org
> >> Subject: Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
> >>
> >> Applied.  Thanks!
> >
> > This change beaks the following IGT tests:
> >
> > igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-create
> > igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-decode
> > igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-destroy
> > igt@amdgpu/amd_jpeg_dec@amdgpu_cs_jpeg_decode
> > igt@amdgpu/amd_cs_nop@cs-nops-with-nop-compute0@cs-nop-with-nop-compute0
> > igt@amdgpu/amd_cs_nop@cs-nops-with-sync-compute0@cs-nop-with-sync-compute0
> > igt@amdgpu/amd_cs_nop@cs-nops-with-fork-compute0@cs-nop-with-fork-compute0
> > igt@amdgpu/amd_cs_nop@cs-nops-with-sync-fork-compute0@cs-nop-with-sync-fork-compute0
> > igt@amdgpu/amd_basic@userptr-with-ip-dma@userptr
> > igt@amdgpu/amd_basic@cs-compute-with-ip-compute@cs-compute
> > igt@amdgpu/amd_basic@cs-sdma-with-ip-dma@cs-sdma
> > igt@amdgpu/amd_basic@eviction-test-with-ip-dma@eviction_test
> > igt@amdgpu/amd_cp_dma_misc@gtt_to_vram-amdgpu_hw_ip_compute0
> > igt@amdgpu/amd_cp_dma_misc@vram_to_gtt-amdgpu_hw_ip_compute0
> > igt@amdgpu/amd_cp_dma_misc@vram_to_vram-amdgpu_hw_ip_compute0
>
>
> Could it be that we used BO list with zero entries for those?

Yes.  Dropping the 0 check fixed them.  E.g.,

+       if (in->bo_number > USHRT_MAX)
+               return -EINVAL;

Alex

>
> Christian.
>
> >
> > Alex
> >
> >>
> >> On Tue, Apr 22, 2025 at 5:13 AM Koenig, Christian <Christian.Koenig@amd.com>
> >> wrote:
> >>>
> >>> [AMD Official Use Only - AMD Internal Distribution Only]
> >>>
> >>> Reviewed-by: Christian König <christian.koenig@amd.com>
> >>>
> >>> ________________________________________
> >>> Von: Denis Arefev <arefev@swemel.ru>
> >>> Gesendet: Freitag, 18. April 2025 10:31
> >>> An: Deucher, Alexander
> >>> Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky;
> >>> Chunming Zhou; amd-gfx@lists.freedesktop.org;
> >>> dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org;
> >>> lvc-project@linuxtesting.org; stable@vger.kernel.org
> >>> Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in
> >>> list
> >>>
> >>> 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@vger.kernel.org
> >>> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> >>> ---
> >>> V1 -> V2:
> >>> Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian
> >>> König <christian.koenig@amd.com> suggested
> >>>
> >>>  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..85f7ee1e085d 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 > USHRT_MAX)
> >>> +               return -EINVAL;
> >>> +
> >>>         info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
> >>>         if (!info)
> >>>                 return -ENOMEM;
> >>> --
> >>> 2.43.0
> >>>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
  2025-04-24 13:40         ` Alex Deucher
@ 2025-04-28 14:53           ` Christian König
  0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2025-04-28 14:53 UTC (permalink / raw)
  To: Alex Deucher
  Cc: Deucher, Alexander, Denis Arefev, David Airlie, Simona Vetter,
	Andrey Grodzovsky, Chunming Zhou, amd-gfx, dri-devel,
	linux-kernel, lvc-project, stable

On 4/24/25 15:40, Alex Deucher wrote:
> On Wed, Apr 23, 2025 at 10:29 AM Christian König
> <christian.koenig@amd.com> wrote:
>>
>> On 4/22/25 18:26, Deucher, Alexander wrote:
>>> [Public]
>>>
>>>> -----Original Message-----
>>>> From: Alex Deucher <alexdeucher@gmail.com>
>>>> Sent: Tuesday, April 22, 2025 9:46 AM
>>>> To: Koenig, Christian <Christian.Koenig@amd.com>
>>>> Cc: Denis Arefev <arefev@swemel.ru>; Deucher, Alexander
>>>> <Alexander.Deucher@amd.com>; David Airlie <airlied@gmail.com>; Simona Vetter
>>>> <simona@ffwll.ch>; Andrey Grodzovsky <andrey.grodzovsky@amd.com>;
>>>> Chunming Zhou <david1.zhou@amd.com>; amd-gfx@lists.freedesktop.org; dri-
>>>> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; lvc-
>>>> project@linuxtesting.org; stable@vger.kernel.org
>>>> Subject: Re: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list
>>>>
>>>> Applied.  Thanks!
>>>
>>> This change beaks the following IGT tests:
>>>
>>> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-create
>>> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-decode
>>> igt@amdgpu/amd_vcn@vcn-decoder-create-decode-destroy@vcn-decoder-destroy
>>> igt@amdgpu/amd_jpeg_dec@amdgpu_cs_jpeg_decode
>>> igt@amdgpu/amd_cs_nop@cs-nops-with-nop-compute0@cs-nop-with-nop-compute0
>>> igt@amdgpu/amd_cs_nop@cs-nops-with-sync-compute0@cs-nop-with-sync-compute0
>>> igt@amdgpu/amd_cs_nop@cs-nops-with-fork-compute0@cs-nop-with-fork-compute0
>>> igt@amdgpu/amd_cs_nop@cs-nops-with-sync-fork-compute0@cs-nop-with-sync-fork-compute0
>>> igt@amdgpu/amd_basic@userptr-with-ip-dma@userptr
>>> igt@amdgpu/amd_basic@cs-compute-with-ip-compute@cs-compute
>>> igt@amdgpu/amd_basic@cs-sdma-with-ip-dma@cs-sdma
>>> igt@amdgpu/amd_basic@eviction-test-with-ip-dma@eviction_test
>>> igt@amdgpu/amd_cp_dma_misc@gtt_to_vram-amdgpu_hw_ip_compute0
>>> igt@amdgpu/amd_cp_dma_misc@vram_to_gtt-amdgpu_hw_ip_compute0
>>> igt@amdgpu/amd_cp_dma_misc@vram_to_vram-amdgpu_hw_ip_compute0
>>
>>
>> Could it be that we used BO list with zero entries for those?
> 
> Yes.  Dropping the 0 check fixed them.  E.g.,
> 
> +       if (in->bo_number > USHRT_MAX)
> +               return -EINVAL;


Feel free to keep my rb on that version as well.

Christian.

> 
> Alex
> 
>>
>> Christian.
>>
>>>
>>> Alex
>>>
>>>>
>>>> On Tue, Apr 22, 2025 at 5:13 AM Koenig, Christian <Christian.Koenig@amd.com>
>>>> wrote:
>>>>>
>>>>> [AMD Official Use Only - AMD Internal Distribution Only]
>>>>>
>>>>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>>>>
>>>>> ________________________________________
>>>>> Von: Denis Arefev <arefev@swemel.ru>
>>>>> Gesendet: Freitag, 18. April 2025 10:31
>>>>> An: Deucher, Alexander
>>>>> Cc: Koenig, Christian; David Airlie; Simona Vetter; Andrey Grodzovsky;
>>>>> Chunming Zhou; amd-gfx@lists.freedesktop.org;
>>>>> dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org;
>>>>> lvc-project@linuxtesting.org; stable@vger.kernel.org
>>>>> Betreff: [PATCH v2] drm/amdgpu: check a user-provided number of BOs in
>>>>> list
>>>>>
>>>>> 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@vger.kernel.org
>>>>> Signed-off-by: Denis Arefev <arefev@swemel.ru>
>>>>> ---
>>>>> V1 -> V2:
>>>>> Set a reasonable limit 'USHRT_MAX' for 'bo_number' it as Christian
>>>>> König <christian.koenig@amd.com> suggested
>>>>>
>>>>>  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..85f7ee1e085d 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 > USHRT_MAX)
>>>>> +               return -EINVAL;
>>>>> +
>>>>>         info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
>>>>>         if (!info)
>>>>>                 return -ENOMEM;
>>>>> --
>>>>> 2.43.0
>>>>>
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-04-28 14:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-18  8:31 [PATCH v2] drm/amdgpu: check a user-provided number of BOs in list Denis Arefev
2025-04-22  9:12 ` AW: " Koenig, Christian
2025-04-22 13:46   ` Alex Deucher
2025-04-22 16:26     ` Deucher, Alexander
2025-04-23 14:29       ` Christian König
2025-04-24 13:40         ` Alex Deucher
2025-04-28 14:53           ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®