Skip to content

Commit

Permalink
drm/amd/pm: Handle non-terminated overdrive commands.
Browse files Browse the repository at this point in the history
commit 08e9ebc upstream.

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@vger.kernel.org
Fixes: e3933f2 ("drm/amd/pp: Add edit/commit/show OD clock/voltage support in sysfs")
Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
BNieuwenhuizen authored and gregkh committed Nov 28, 2023
1 parent e3b83d8 commit f0a1173
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/gpu/drm/amd/pm/amdgpu_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,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')
Expand All @@ -754,7 +754,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;

Expand All @@ -771,6 +772,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++;
}
Expand Down

0 comments on commit f0a1173

Please sign in to comment.