Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3836390pxb; Mon, 1 Mar 2021 22:59:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2cSiUX51bkXNbEiC/4tx0z1X05p4e4UYP+ay/q4sYHBEqwEzbd3eOXU8nsENVZIuuLmEu X-Received: by 2002:a50:f9c8:: with SMTP id a8mr793307edq.270.1614668382418; Mon, 01 Mar 2021 22:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614668382; cv=none; d=google.com; s=arc-20160816; b=X7PrmkdzPSualgfNVlTrP0rn7+t6o9ORQN/HAHR/M22GMjmADReT4J3hXifDQSg5hm qP042Eyo3PapErA+M5DU5Tz1JQ1109uXqa2mibDr4WzZEy3Xi2vWs2x+tvlhNDowb3Xy 4+Ha2W2hBfERKFA3MvXC/xg5s+i5Ezdog3HSzBynUgZzQ/qpGR2vU8LnAJdRNjxjBXUm 4HKX+GyVSg6d8ofjT1c5/Q8B4xhh2YqiPXT3FnGbEH5qp8VQiWFHVjTZ77StjIs+ehS+ Pp4K2P4/4wj8LdyDXYURa/5jQ+qPfuT3fXVNGw+VOku8wZke7TrdF7wEcfOx85v4JTeM kkRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UXJ9HuIyFaC9+ieNBLpUzjmlaqJWNzDKYMp2xSn9ey8=; b=lJSEjUiRnBtpxUQD1C1pkRK+6DrUeJphcwfQz1ecTsZyx4m9o7UEvs5YmFccRDn7uX ZJ6BlaE57qwivfVXYnZu/OaMdqoM763COP6gwFWNxdQJ1gnpMCZbdapXZzrLrJ6iSgNH hbSXkEcReLzhUuRdKH6wdBKJHjVKT5g79UGN0/BurEv8VTY0LlXy9uJ1Dh4BipR9906c QSO8RfotCTQKhfm6YqC2fXzS8EjsWSpolJHCAvWjlQeuXw4Vppc/911ijHr5dJWdHzoy FhLGw188GBr9HMwq3ME6YGXcl7d/NmdTDi1NvUdRsicPOKiP/bvsHeauY7YK8hjHjgpJ 4fmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wcgES/LA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fi16si1143265ejb.239.2021.03.01.22.59.19; Mon, 01 Mar 2021 22:59:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wcgES/LA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377518AbhCBArf (ORCPT + 99 others); Mon, 1 Mar 2021 19:47:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:54504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237099AbhCASpB (ORCPT ); Mon, 1 Mar 2021 13:45:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D738164E12; Mon, 1 Mar 2021 17:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618773; bh=6l8EQL6pTGEDKoOy63AMW/PtpowgN3J+JPAKAnjR4c4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wcgES/LA7VqafSne4VR1jnJ3Qj6/6RLyOhu/01U+T7pNvUgXnm1MC5+6y4z5Wgej8 zx5b6o23XtGxy+sl2Iv+0veoQesENu4IMkfuhOrC0PgzWUWlkZtse97D81bo7x9hA0 4g3EpB/oLiltSvNtucNBGU1teQdvixFK5OAA/JmU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 212/663] drm/amdgpu: Prevent shift wrapping in amdgpu_read_mask() Date: Mon, 1 Mar 2021 17:07:40 +0100 Message-Id: <20210301161152.278660107@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit c915ef890d5dc79f483e1ca3b3a5b5f1a170690c ] 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 Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c index 529816637c731..9f383b9041d28 100644 --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c @@ -1070,7 +1070,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]; @@ -1086,8 +1086,8 @@ static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask) while (tmp[0]) { sub_str = strsep(&tmp, delimiter); if (strlen(sub_str)) { - ret = kstrtol(sub_str, 0, &level); - if (ret) + ret = kstrtoul(sub_str, 0, &level); + if (ret || level > 31) return -EINVAL; *mask |= 1 << level; } else -- 2.27.0