diff mbox series

drm/amd/pm/smu11: Prevent division by zero

Message ID 20250320093517.5247-1-arefev@swemel.ru (mailing list archive)
State New
Headers show
Series drm/amd/pm/smu11: Prevent division by zero | expand

Commit Message

Denis Arefev March 20, 2025, 9:35 a.m. UTC
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(-)

Comments

Alex Deucher March 20, 2025, 1:51 p.m. UTC | #1
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
>
diff mbox series

Patch

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