提交 7fdc5e78 编写于 作者: P Paweł Gronowski 提交者: Yang Yingliang

drm/amdgpu: Fix NULL dereference in dpm sysfs handlers

commit 38e0c89a19fd13f28d2b4721035160a3e66e270b upstream.

NULL dereference occurs when string that is not ended with space or
newline is written to some dpm sysfs interface (for example pp_dpm_sclk).
This happens because strsep replaces the tmp with NULL if the delimiter
is not present in string, which is then dereferenced by tmp[0].

Reproduction example:
sudo sh -c 'echo -n 1 > /sys/class/drm/card0/device/pp_dpm_sclk'
Signed-off-by: NPaweł Gronowski <me@woland.xyz>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 f737f074
...@@ -529,8 +529,7 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, ...@@ -529,8 +529,7 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
while (isspace(*++tmp_str)); while (isspace(*++tmp_str));
while (tmp_str[0]) { while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
sub_str = strsep(&tmp_str, delimiter);
ret = kstrtol(sub_str, 0, &parameter[parameter_size]); ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
if (ret) if (ret)
return -EINVAL; return -EINVAL;
...@@ -630,8 +629,7 @@ static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask) ...@@ -630,8 +629,7 @@ static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
memcpy(buf_cpy, buf, bytes); memcpy(buf_cpy, buf, bytes);
buf_cpy[bytes] = '\0'; buf_cpy[bytes] = '\0';
tmp = buf_cpy; tmp = buf_cpy;
while (tmp[0]) { while ((sub_str = strsep(&tmp, delimiter)) != NULL) {
sub_str = strsep(&tmp, delimiter);
if (strlen(sub_str)) { if (strlen(sub_str)) {
ret = kstrtol(sub_str, 0, &level); ret = kstrtol(sub_str, 0, &level);
if (ret) if (ret)
...@@ -882,8 +880,7 @@ static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev, ...@@ -882,8 +880,7 @@ static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
i++; i++;
memcpy(buf_cpy, buf, count-i); memcpy(buf_cpy, buf, count-i);
tmp_str = buf_cpy; tmp_str = buf_cpy;
while (tmp_str[0]) { while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
sub_str = strsep(&tmp_str, delimiter);
ret = kstrtol(sub_str, 0, &parameter[parameter_size]); ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
if (ret) { if (ret) {
count = -EINVAL; count = -EINVAL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册