From: Dan Carpenter <dan.carpenter@oracle.com>
To: Alex Deucher <alexander.deucher@amd.com>
Cc: "Xiaojian Du" <Xiaojian.Du@amd.com>,
"David Airlie" <airlied@linux.ie>,
kernel-janitors@vger.kernel.org,
"Kevin Wang" <kevin1.wang@amd.com>,
"Huang Rui" <ray.huang@amd.com>,
amd-gfx@lists.freedesktop.org, "Nirmoy Das" <nirmoy.das@amd.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Eric Huang" <JinHuiEric.Huang@amd.com>,
"Evan Quan" <evan.quan@amd.com>,
"Christian König" <christian.koenig@amd.com>
Subject: [PATCH] drm/amdgpu: Prevent shift wrapping in amdgpu_read_mask()
Date: Tue, 02 Feb 2021 05:56:36 +0000 [thread overview]
Message-ID: <YBjplLOof9J1E2o5@mwanda> (raw)
If the user passes a "level" value which is higher than 31 then that
leads to shift wrapping. The undefined behavior will lead to a
syzkaller stack dump.
Fixes: 5632708f4452 ("drm/amd/powerplay: add dpm force multiple levels on cz/tonga/fiji/polaris (v2)")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/gpu/drm/amd/pm/amdgpu_pm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index e9b569b76716..1a4010fcf561 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -1094,7 +1094,7 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
{
int ret;
- long level;
+ unsigned long level;
char *sub_str = NULL;
char *tmp;
char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
@@ -1109,9 +1109,9 @@ static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
tmp = buf_cpy;
while (tmp[0]) {
sub_str = strsep(&tmp, delimiter);
- if (strlen(sub_str)) {
- ret = kstrtol(sub_str, 0, &level);
- if (ret)
+ if (sub_str[0]) {
+ ret = kstrtoul(sub_str, 0, &level);
+ if (ret || level > 31)
return -EINVAL;
*mask |= 1 << level;
} else
--
2.29.2
next reply other threads:[~2021-02-02 5:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 5:56 Dan Carpenter [this message]
2021-02-02 16:38 ` [PATCH] drm/amdgpu: Prevent shift wrapping in amdgpu_read_mask() Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YBjplLOof9J1E2o5@mwanda \
--to=dan.carpenter@oracle.com \
--cc=JinHuiEric.Huang@amd.com \
--cc=Xiaojian.Du@amd.com \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=evan.quan@amd.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kevin1.wang@amd.com \
--cc=nirmoy.das@amd.com \
--cc=ray.huang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox