dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/pm/smu11: Prevent division by zero
@ 2025-03-20  9:35 Denis Arefev
  2025-03-20 13:51 ` Alex Deucher
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Arefev @ 2025-03-20  9:35 UTC (permalink / raw)
  To: Kenneth Feng
  Cc: Alex Deucher, Christian König, David Airlie, Simona Vetter,
	Lijo Lazar, Ma Jun, Mario Limonciello, Srinivasan Shanmugam,
	Yang Wang, amd-gfx, dri-devel, linux-kernel, lvc-project

The user can set any speed value.
If speed is greater than UINT_MAX/8, division by zero is possible.

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

Fixes: 1e866f1fe528 ("drm/amd/pm: Prevent divide by zero") 
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
index 189c6a32b6bd..54229b991858 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
@@ -1200,7 +1200,7 @@ int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
 	uint32_t crystal_clock_freq = 2500;
 	uint32_t tach_period;
 
-	if (speed == 0)
+	if (!speed || speed > UINT_MAX/8)
 		return -EINVAL;
 	/*
 	 * To prevent from possible overheat, some ASICs may have requirement
-- 
2.43.0


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

* Re: [PATCH] drm/amd/pm/smu11: Prevent division by zero
  2025-03-20  9:35 [PATCH] drm/amd/pm/smu11: Prevent division by zero Denis Arefev
@ 2025-03-20 13:51 ` Alex Deucher
  2025-04-08  8:16   ` Denis Arefev
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Deucher @ 2025-03-20 13:51 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Kenneth Feng, Alex Deucher, Christian König, David Airlie,
	Simona Vetter, Lijo Lazar, Ma Jun, Mario Limonciello,
	Srinivasan Shanmugam, Yang Wang, amd-gfx, dri-devel, linux-kernel,
	lvc-project

On Thu, Mar 20, 2025 at 9:11 AM Denis Arefev <arefev@swemel.ru> wrote:
>
> The user can set any speed value.
> If speed is greater than UINT_MAX/8, division by zero is possible.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 1e866f1fe528 ("drm/amd/pm: Prevent divide by zero")
> Signed-off-by: Denis Arefev <arefev@swemel.ru>

Thanks.  While you are at it, can you fix up all of the other fan
speed cases?  I quick grep shows:
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c:    tach_period = 60 * xclk
* 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c:    tach_period
= 60 * crystal_clock_freq * 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_thermal.c:
tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c:
tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c:    tach_period = 60
* crystal_clock_freq * 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c:    tach_period = 60 *
crystal_clock_freq * 10000 / (8 * speed);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c:    tach_period = 60 *
crystal_clock_freq * 10000 / (8 * speed);

Thanks,

Alex

> ---
>  drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> index 189c6a32b6bd..54229b991858 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> @@ -1200,7 +1200,7 @@ int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
>         uint32_t crystal_clock_freq = 2500;
>         uint32_t tach_period;
>
> -       if (speed == 0)
> +       if (!speed || speed > UINT_MAX/8)
>                 return -EINVAL;
>         /*
>          * To prevent from possible overheat, some ASICs may have requirement
> --
> 2.43.0
>

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

* Re: [PATCH] drm/amd/pm/smu11: Prevent division by zero
  2025-03-20 13:51 ` Alex Deucher
@ 2025-04-08  8:16   ` Denis Arefev
  2025-04-08 12:51     ` Alex Deucher
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Arefev @ 2025-04-08  8:16 UTC (permalink / raw)
  To: alexdeucher
  Cc: Jun.Ma2, airlied, alexander.deucher, amd-gfx, arefev,
	christian.koenig, dri-devel, kenneth.feng, kevinyang.wang,
	lijo.lazar, linux-kernel, lvc-project, mario.limonciello, simona,
	srinivasan.shanmugam

> ---
>  drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> index 189c6a32b6bd..54229b991858 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> @@ -1200,7 +1200,7 @@ int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
>         uint32_t crystal_clock_freq = 2500;
>         uint32_t tach_period;
>
> -       if (speed == 0)
> +       if (!speed || speed > UINT_MAX/8)
>                 return -EINVAL;
>         /*
>          * To prevent from possible overheat, some ASICs may have requirement
> --
> 2.43.0
>

Hi Alex.

The patch 'drm/amd/pm/smu11: Prevent division by zero' was sent 
separately, not part of the patch series, maybe that's why it wasn't
accepted. Should I resend it?

Regards, Denis.


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

* Re: [PATCH] drm/amd/pm/smu11: Prevent division by zero
  2025-04-08  8:16   ` Denis Arefev
@ 2025-04-08 12:51     ` Alex Deucher
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2025-04-08 12:51 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Jun.Ma2, airlied, alexander.deucher, amd-gfx, christian.koenig,
	dri-devel, kenneth.feng, kevinyang.wang, lijo.lazar, linux-kernel,
	lvc-project, mario.limonciello, simona, srinivasan.shanmugam

Oh, sorry, I've picked it up now.  Thanks!

Alex

On Tue, Apr 8, 2025 at 4:16 AM Denis Arefev <arefev@swemel.ru> wrote:
>
> > ---
> >  drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> > index 189c6a32b6bd..54229b991858 100644
> > --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> > +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
> > @@ -1200,7 +1200,7 @@ int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
> >         uint32_t crystal_clock_freq = 2500;
> >         uint32_t tach_period;
> >
> > -       if (speed == 0)
> > +       if (!speed || speed > UINT_MAX/8)
> >                 return -EINVAL;
> >         /*
> >          * To prevent from possible overheat, some ASICs may have requirement
> > --
> > 2.43.0
> >
>
> Hi Alex.
>
> The patch 'drm/amd/pm/smu11: Prevent division by zero' was sent
> separately, not part of the patch series, maybe that's why it wasn't
> accepted. Should I resend it?
>
> Regards, Denis.
>

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

end of thread, other threads:[~2025-04-08 12:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20  9:35 [PATCH] drm/amd/pm/smu11: Prevent division by zero Denis Arefev
2025-03-20 13:51 ` Alex Deucher
2025-04-08  8:16   ` Denis Arefev
2025-04-08 12:51     ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).