Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp926060imj; Sat, 9 Feb 2019 10:58:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IbdVex++lJ+hc5RNnbP+tJkSmnZ1DAz+TZxgJtbHjj0PZSiPVty57fSRiknzRQrPzFPmnqV X-Received: by 2002:a63:1824:: with SMTP id y36mr26794853pgl.68.1549738688665; Sat, 09 Feb 2019 10:58:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549738688; cv=none; d=google.com; s=arc-20160816; b=0gRVDlDRwMpaVPa59F9+N1Vcpb8hFoiz0ypPCyNAulvE2kxLhc24LnpM7eI7t2A9iR zJy9E6jDQhj3Cw8E/IzSkuyIudmfLqgTukYvYLDMLc59ESHil5LUp2YnmFZJubvZJdxQ PKzOy1Ncy5XrRHGKqOC8+gbpuj1awrkBTrMDREZXVPFbZc/YOOidm96mynoigRDR8E0J OCUJHNtK7EX2b0iBmKt1pzm5yuJ2ZxGY8Obn4KrV9D9Iq+8IqmwYuWdZQ/jk14aYwige pqj9Yz7UGGeSYknU4LeuCp5l8GmPcLDtvvfn6zinrHBKqHfpYKYLSCTW9WICGuyxFwEX 9w2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RvoNz5U+T6i75+X5a0oW/m84ooF1blom+Y0ajcCLwE4=; b=UTMoKNb5CTrY5ZWR70cEjtSJrgxg4bF3YXQO7QIo9kAScCdFfAwha6juMt1hu1tvlL c9AgNfbGUDWruXAM4k7FtTr4b23JwI/heM1IzGEDZRq3ecmD5SdLAv8KGQ05pTCikzVn VRALvDO2CMM+4AGYrDWTxgM8pplr3oE0WXb7yHxqAkmV9jND07IkEAdahnDVeVv70OHP 8qJiggT2AJhwvFCRxUaxDAbwt4a6OTkIX2SiHPwPKDgkjsdmEqBiCoXk6ocaZbhNIBuI E0t3Ei0uFO76J24vJYUIcoqg4CU2elNkN1xe0gvFaYZgXZWktQyS/uBOc77AlvA7458P h59g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wt+Xnb44; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si587790plc.40.2019.02.09.10.57.53; Sat, 09 Feb 2019 10:58:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wt+Xnb44; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728331AbfBIS5E (ORCPT + 99 others); Sat, 9 Feb 2019 13:57:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:60504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727413AbfBISru (ORCPT ); Sat, 9 Feb 2019 13:47:50 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E8CD2192C; Sat, 9 Feb 2019 18:47:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549738070; bh=eKE2CzvghHkIspAUrkaXB6hPphI4rQhEYKHodqBP14Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wt+Xnb44Z2zFdR/as0+ASqh2dLTNNcguH3ltP5bOUhqY9hUu+eVDfsh2cgHtQQJuP tmtAvU9gJktDWichKXTr+qer3r2oPwLoIaRIyeGZsG/2RCa8IzJPPeIndeTAroI8bj OY3mshq7YJTgj0KmFZrNNffJrTZ8+I32bEoT6Ru0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Evan Quan , Alex Deucher , Sasha Levin Subject: [PATCH AUTOSEL 4.20 14/42] drm/amd/powerplay: avoid possible buffer overflow Date: Sat, 9 Feb 2019 13:47:06 -0500 Message-Id: <20190209184734.125935-14-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190209184734.125935-1-sashal@kernel.org> References: <20190209184734.125935-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Evan Quan [ Upstream commit fff0d3f7686942bd544b53a48d1b76bd62c46946 ] Make sure the clock level enforced is within the allowed ranges. Signed-off-by: Evan Quan Reviewed-by: Alex Deucher Reviewed-by: Likun Gao Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c index 3b7fce5d7258..b9e19b0eb905 100644 --- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c @@ -2244,6 +2244,13 @@ static int vega20_force_clock_level(struct pp_hwmgr *hwmgr, soft_min_level = mask ? (ffs(mask) - 1) : 0; soft_max_level = mask ? (fls(mask) - 1) : 0; + if (soft_max_level >= data->dpm_table.gfx_table.count) { + pr_err("Clock level specified %d is over max allowed %d\n", + soft_max_level, + data->dpm_table.gfx_table.count - 1); + return -EINVAL; + } + data->dpm_table.gfx_table.dpm_state.soft_min_level = data->dpm_table.gfx_table.dpm_levels[soft_min_level].value; data->dpm_table.gfx_table.dpm_state.soft_max_level = @@ -2264,6 +2271,13 @@ static int vega20_force_clock_level(struct pp_hwmgr *hwmgr, soft_min_level = mask ? (ffs(mask) - 1) : 0; soft_max_level = mask ? (fls(mask) - 1) : 0; + if (soft_max_level >= data->dpm_table.mem_table.count) { + pr_err("Clock level specified %d is over max allowed %d\n", + soft_max_level, + data->dpm_table.mem_table.count - 1); + return -EINVAL; + } + data->dpm_table.mem_table.dpm_state.soft_min_level = data->dpm_table.mem_table.dpm_levels[soft_min_level].value; data->dpm_table.mem_table.dpm_state.soft_max_level = -- 2.19.1