Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753494AbcKOQJY (ORCPT ); Tue, 15 Nov 2016 11:09:24 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:37275 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752483AbcKOQJW (ORCPT ); Tue, 15 Nov 2016 11:09:22 -0500 Subject: Re: [PATCH] drm/amd/powerplay: check if table_info is NULL before dereferencing it To: "Deucher, Alexander" , "Koenig, Christian" , David Airlie , "Zhu, Rex" , "StDenis, Tom" , "Huang, Ray" , =?UTF-8?Q?Nils_Wallm=c3=a9nius?= , Baoyou Xie , "dri-devel@lists.freedesktop.org" References: <20161115125435.6236-1-colin.king@canonical.com> Cc: "linux-kernel@vger.kernel.org" From: Colin Ian King Message-ID: <3adcaa1f-6ded-0a56-2f44-c830e5a2d198@canonical.com> Date: Tue, 15 Nov 2016 16:09:13 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: 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: 3468 Lines: 91 On 15/11/16 15:49, Deucher, Alexander wrote: >> -----Original Message----- >> From: Colin King [mailto:colin.king@canonical.com] >> Sent: Tuesday, November 15, 2016 7:55 AM >> To: Deucher, Alexander; Koenig, Christian; David Airlie; Zhu, Rex; StDenis, >> Tom; Huang, Ray; Nils Wallménius; Baoyou Xie; dri- >> devel@lists.freedesktop.org >> Cc: linux-kernel@vger.kernel.org >> Subject: [PATCH] drm/amd/powerplay: check if table_info is NULL before >> dereferencing it >> >> From: Colin Ian King >> >> table_info is being dereferenced before a null check, which implies >> a potential null pointer deference error. Fix this by moving the null >> check of table_info to the start of smu7_get_evv_voltages to avoid >> potential null pointer deferencing. >> >> Found with static analysis by CoverityScan, CID 1377752 >> >> Signed-off-by: Colin Ian King > > NACK, this effectively reverts the patch. This causes the function to exit early on asics where the table it NULL which is not what we want. Whether the table exists or not is dependent on the table version and the feature caps for the chip which are checked before the table is dereferenced. The NULL check in the top if clause is not strictly necessary and could be removed. > > Alex OK, understood. The part I'm missing is that we dereference table_info at the following statement: if ((hwmgr->pp_table_version == PP_TABLE_V1) && !phm_get_sclk_for_voltage_evv(hwmgr, table_info->vddgfx_lookup_table, vv_id, &sclk)) and later check if it is NULL. So, I can't see where table_info is being set other than the start of the function, so, either it can be null and hence we have a null ptr deference, or it's never null, in which case the check for NULL is redundant. Colin > >> --- >> drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 6 ++---- >> 1 file changed, 2 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c >> b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c >> index 28e748d..6798067 100644 >> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c >> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c >> @@ -1473,6 +1473,8 @@ static int smu7_get_evv_voltages(struct pp_hwmgr >> *hwmgr) >> (struct phm_ppt_v1_information *)hwmgr->pptable; >> struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = >> NULL; >> >> + if (table_info == NULL) >> + return -EINVAL; >> >> for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) { >> vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; >> @@ -1483,8 +1485,6 @@ static int smu7_get_evv_voltages(struct pp_hwmgr >> *hwmgr) >> table_info- >>> vddgfx_lookup_table, vv_id, &sclk)) { >> if (phm_cap_enabled(hwmgr- >>> platform_descriptor.platformCaps, >> >> PHM_PlatformCaps_ClockStretcher)) { >> - if (table_info == NULL) >> - return -EINVAL; >> sclk_table = table_info- >>> vdd_dep_on_sclk; >> >> for (j = 1; j < sclk_table->count; j++) { >> @@ -1517,8 +1517,6 @@ static int smu7_get_evv_voltages(struct pp_hwmgr >> *hwmgr) >> table_info->vddc_lookup_table, >> vv_id, &sclk)) { >> if (phm_cap_enabled(hwmgr- >>> platform_descriptor.platformCaps, >> >> PHM_PlatformCaps_ClockStretcher)) { >> - if (table_info == NULL) >> - return -EINVAL; >> sclk_table = table_info- >>> vdd_dep_on_sclk; >> >> for (j = 1; j < sclk_table->count; j++) { >> -- >> 2.10.2 >