From: "Deucher, Alexander" <Alexander.Deucher@amd.com>
To: "'Colin Ian King'" <colin.king@canonical.com>,
"Koenig, Christian" <Christian.Koenig@amd.com>,
"David Airlie" <airlied@linux.ie>, "Zhu, Rex" <Rex.Zhu@amd.com>,
"StDenis, Tom" <Tom.StDenis@amd.com>,
"Huang, Ray" <Ray.Huang@amd.com>,
"Nils Wallménius" <nils.wallmenius@gmail.com>,
"Baoyou Xie" <baoyou.xie@linaro.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] drm/amd/powerplay: check if table_info is NULL before dereferencing it
Date: Tue, 15 Nov 2016 16:18:53 +0000 [thread overview]
Message-ID: <MWHPR12MB1694EB0A2913CAC4ACAD92F2F7BF0@MWHPR12MB1694.namprd12.prod.outlook.com> (raw)
In-Reply-To: <3adcaa1f-6ded-0a56-2f44-c830e5a2d198@canonical.com>
> -----Original Message-----
> From: Colin Ian King [mailto:colin.king@canonical.com]
> Sent: Tuesday, November 15, 2016 11:09 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: Re: [PATCH] drm/amd/powerplay: check if table_info is NULL before
> dereferencing it
>
> 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 <colin.king@canonical.com>
> >>
> >> 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 <colin.king@canonical.com>
> >
> > 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.
Yes, that check is redundant. That is was I was referring to above.
Alex
>
> 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
> >
prev parent reply other threads:[~2016-11-15 16:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 12:54 Colin King
2016-11-15 15:49 ` Deucher, Alexander
2016-11-15 16:09 ` Colin Ian King
2016-11-15 16:18 ` Deucher, Alexander [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MWHPR12MB1694EB0A2913CAC4ACAD92F2F7BF0@MWHPR12MB1694.namprd12.prod.outlook.com \
--to=alexander.deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Ray.Huang@amd.com \
--cc=Rex.Zhu@amd.com \
--cc=Tom.StDenis@amd.com \
--cc=airlied@linux.ie \
--cc=baoyou.xie@linaro.org \
--cc=colin.king@canonical.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nils.wallmenius@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®