Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933541AbcJFSCX (ORCPT ); Thu, 6 Oct 2016 14:02:23 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:42058 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933122AbcJFSCT (ORCPT ); Thu, 6 Oct 2016 14:02:19 -0400 From: Colin King To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Eric Huang , Rex Zhu , Jammy Zhou , Tom St Denis , Dan Carpenter , dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] drm/amd/amdgpu: default to zero number of states if not enabled Date: Thu, 6 Oct 2016 19:02:11 +0100 Message-Id: <20161006180211.31747-1-colin.king@canonical.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1041 Lines: 29 From: Colin Ian King Currently, if adev->pp_enabled is false then the pp_stats_info data is not read and hence a garbage number of states from the stack is used to dump out the number of states. Given data.nums could be any random value, this could easily lead to read outside the data.states array. Fix this by setting data.nums to zero if adev->pp_enabled is false. Signed-off-by: Colin Ian King --- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c index accc908..808d788 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c @@ -195,6 +195,8 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev, if (adev->pp_enabled) amdgpu_dpm_get_pp_num_states(adev, &data); + else + data.nums = 0; buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums); for (i = 0; i < data.nums; i++) -- 2.9.3