Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp396019pxb; Wed, 3 Mar 2021 06:08:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWc14ZkbHfRwHVUHYD3yhHyPWCO1zJUwtIV+gc8TS3sjjBz+nkN9bv7wa3msP/1ziSu9gR X-Received: by 2002:a50:9ecf:: with SMTP id a73mr25141914edf.181.1614780528564; Wed, 03 Mar 2021 06:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614780528; cv=none; d=google.com; s=arc-20160816; b=byqSmPTsAr5wCoyo/B+TpiBYIAWkrJul7FISjcKrut8Vrjvo5ndPNRMVkTDEe0Z1wy xU/931kBHMLju0r3Qns+AEtlKFqcgyL2iHbZWecJVU0c6i6xPGUuQUN6SaeJsc/oKavL OkQbVCyz0GmTe16mVbFGHTosxjQIobaKbw7YwkSWNqcSOrL1dCVwJUYGALiK6lQETF5/ Jywi16kMOBz9hoEKkV4zQ5+RK2PTHrpdUVjFN+HZH4Y4TWFu2GfWb4LpFZPcYlgmmRCb Z7/c71uZ8Pi83PakzDlAbdSR7xRQxwuTE3uqC6jhNS9lyoGVdgHBY75a3Pv5Hx0CLhOh fAwA== 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=VzTymb6RQgR7kxw26pJ9u+s7WWfuJ461OtoRCcvA5kM=; b=REzMoz3OfkVfNnWhc7+BeT6zy5+G8MTqN+CKX/ygwwXuNLhwNkW1Bmq69SKcib9P6X S9tGfNCOqNEd3r6w9wxt9tOE/F2/r6baP1D15/FfUXSuRwquA8V5J9CVNui5t2td1GvF TRzDSeYj5j+RWygjd39rRWVUCeDmrSctjDQiI5oQQOeq7lKysU4VPpcfhSjul0eRok5d gfJwGeofKnniNgPnB6mjdePdPT2uQgwXbCWtswbWVaiKokREjlM8rTCBhri1wAMtsJ9r sJe2mtWmO4I8/8KB22jnmQRJ6MomT2JVOXpgquGpSr+m5ndDdCXhpAipYyAJ++pU+pd9 t3Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ip+7d5Sy; 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 s20si5678562edq.484.2021.03.03.06.07.33; Wed, 03 Mar 2021 06:08:48 -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=ip+7d5Sy; 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 S243730AbhCAUjX (ORCPT + 99 others); Mon, 1 Mar 2021 15:39:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:35372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237544AbhCARIW (ORCPT ); Mon, 1 Mar 2021 12:08:22 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30BCF64F87; Mon, 1 Mar 2021 16:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616883; bh=ihkjfv3QUOQ+XYuaYwF02p96VkvpK5bZr/DlSJ0w4Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ip+7d5SylBvQRFYoMBL/MZqa7V32mMl2xB9Luurq91ttChqVRQ3QtoKWO2l1iUwZV S1WQWlGZU+xKC3+AANXoYBd5Lg+ZvEo7tKrzJ4MVCPmJC/aUsQt7nJ8uCLQMkfnMTN Psan4n9ZQt+QwsYq7eQ+OX2puezrDxV5l88tCQFc= 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 4.19 098/247] drm/amdgpu: Prevent shift wrapping in amdgpu_read_mask() Date: Mon, 1 Mar 2021 17:11:58 +0100 Message-Id: <20210301161036.477443445@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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/amdgpu/amdgpu_pm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c index e63a253eb4255..cbb969a870f6a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c @@ -617,7 +617,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]; @@ -633,8 +633,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