[PATCH] drm/amd/pm: Handle non-terminated overdrive commands.

Alex Deucher alexdeucher at gmail.com
Tue Oct 17 21:26:30 UTC 2023


Applied.  Thanks!

On Tue, Oct 17, 2023 at 10:01 AM Bas Nieuwenhuizen
<bas at basnieuwenhuizen.nl> wrote:
>
> The incoming strings might not be terminated by a newline
> or a 0.
>
> (found while testing a program that just wrote the string
>  itself, causing a crash)
>
> Cc: stable at vger.kernel.org
> Fixes: e3933f26b657 ("drm/amd/pp: Add edit/commit/show OD clock/voltage support in sysfs")
> Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> ---
>  drivers/gpu/drm/amd/pm/amdgpu_pm.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> index da0da03569e8..f9c9eba1a815 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -760,7 +760,7 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
>         if (adev->in_suspend && !adev->in_runpm)
>                 return -EPERM;
>
> -       if (count > 127)
> +       if (count > 127 || count == 0)
>                 return -EINVAL;
>
>         if (*buf == 's')
> @@ -780,7 +780,8 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
>         else
>                 return -EINVAL;
>
> -       memcpy(buf_cpy, buf, count+1);
> +       memcpy(buf_cpy, buf, count);
> +       buf_cpy[count] = 0;
>
>         tmp_str = buf_cpy;
>
> @@ -797,6 +798,9 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
>                         return -EINVAL;
>                 parameter_size++;
>
> +               if (!tmp_str)
> +                       break;
> +
>                 while (isspace(*tmp_str))
>                         tmp_str++;
>         }
> --
> 2.42.0
>


More information about the amd-gfx mailing list