mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fixes uninitialized variable usage in amdgpu_dm_setup_replay
@ 2023-10-26 21:25 Yuran Pereira
       [not found] ` <dc2242cd-6522-4073-b376-edc2a9abc3d9@amd.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Yuran Pereira @ 2023-10-26 21:25 UTC (permalink / raw)
  To: airlied
  Cc: Yuran Pereira, harry.wentland, sunpeng.li, Rodrigo.Siqueira,
	alexander.deucher, christian.koenig, Xinhui.Pan, daniel,
	Bhawanpreet.Lakha, amd-gfx, dri-devel, linux-kernel,
	linux-kernel-mentees

Since `pr_config` is not initialized after its declaration, the
following operations with `replay_enable_option` may be performed
when `replay_enable_option` is holding junk values which could
possibly lead to undefined behaviour

```
    ...
    pr_config.replay_enable_option |= pr_enable_option_static_screen;
    ...

    if (!pr_config.replay_timing_sync_supported)
        pr_config.replay_enable_option &= ~pr_enable_option_general_ui;
    ...
```

This patch initializes `pr_config` after its declaration to ensure that
it doesn't contain junk data, and prevent any undefined behaviour

Addresses-Coverity-ID: 1544428 ("Uninitialized scalar variable")
Fixes: dede1fea4460 ("drm/amd/display: Add Freesync Panel DM code")
Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
index 32d3086c4cb7..40526507f50b 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
@@ -23,6 +23,7 @@
  *
  */
 
+#include <linux/string.h>
 #include "amdgpu_dm_replay.h"
 #include "dc.h"
 #include "dm_helpers.h"
@@ -74,6 +75,8 @@ bool amdgpu_dm_setup_replay(struct dc_link *link, struct amdgpu_dm_connector *ac
 	struct replay_config pr_config;
 	union replay_debug_flags *debug_flags = NULL;
 
+	memset(&pr_config, 0, sizeof(pr_config));
+
 	// For eDP, if Replay is supported, return true to skip checks
 	if (link->replay_settings.config.replay_supported)
 		return true;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in amdgpu_dm_setup_replay
       [not found]     ` <39ab34ec-209d-4176-b271-1a02e2976497@amd.com>
@ 2023-10-28  0:48       ` Yuran Pereira
  2023-10-30 15:52         ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Yuran Pereira @ 2023-10-28  0:48 UTC (permalink / raw)
  To: Hamza Mahfooz
  Cc: Lakha, Bhawanpreet, airlied, Li, Sun peng (Leo),
	Pan, Xinhui, Siqueira, Rodrigo, linux-kernel, amd-gfx, dri-devel,
	Deucher, Alexander, Koenig, Christian, linux-kernel-mentees

Hello,
On Fri, Oct 27, 2023 at 11:57:45AM -0400, Hamza Mahfooz wrote:
> On 10/27/23 11:55, Lakha, Bhawanpreet wrote:
> > [AMD Official Use Only - General]
> > 
> > 
> > 
> > There was a consensus to use memset instead of {0}. I remember making
> > changes related to that previously.
> 
> Hm, seems like it's used rather consistently in the DM and in DC
> though.
> 
Have you decided which one should be used?

Should I submit a v2 patch using {0} instead of memset?


Yuran Pereira
> > 
> > Bhawan
> > 
> > ------------------------------------------------------------------------
> > *From:* Mahfooz, Hamza <Hamza.Mahfooz@amd.com>
> > *Sent:* October 27, 2023 11:53 AM
> > *To:* Yuran Pereira <yuran.pereira@hotmail.com>; airlied@gmail.com
> > <airlied@gmail.com>
> > *Cc:* Li, Sun peng (Leo) <Sunpeng.Li@amd.com>; Lakha, Bhawanpreet
> > <Bhawanpreet.Lakha@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; Siqueira,
> > Rodrigo <Rodrigo.Siqueira@amd.com>; linux-kernel@vger.kernel.org
> > <linux-kernel@vger.kernel.org>; amd-gfx@lists.freedesktop.org
> > <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org
> > <dri-devel@lists.freedesktop.org>; Deucher, Alexander
> > <Alexander.Deucher@amd.com>; Koenig, Christian
> > <Christian.Koenig@amd.com>;
> > linux-kernel-mentees@lists.linuxfoundation.org
> > <linux-kernel-mentees@lists.linuxfoundation.org>
> > *Subject:* Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in
> > amdgpu_dm_setup_replay
> > On 10/26/23 17:25, Yuran Pereira wrote:
> > > Since `pr_config` is not initialized after its declaration, the
> > > following operations with `replay_enable_option` may be performed
> > > when `replay_enable_option` is holding junk values which could
> > > possibly lead to undefined behaviour
> > > 
> > > ```
> > >       ...
> > >       pr_config.replay_enable_option |= pr_enable_option_static_screen;
> > >       ...
> > > 
> > >       if (!pr_config.replay_timing_sync_supported)
> > >           pr_config.replay_enable_option &= ~pr_enable_option_general_ui;
> > >       ...
> > > ```
> > > 
> > > This patch initializes `pr_config` after its declaration to ensure that
> > > it doesn't contain junk data, and prevent any undefined behaviour
> > > 
> > > Addresses-Coverity-ID: 1544428 ("Uninitialized scalar variable")
> > > Fixes: dede1fea4460 ("drm/amd/display: Add Freesync Panel DM code")
> > > Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
> > > ---
> > >    drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c | 3 +++
> > >    1 file changed, 3 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
> > > index 32d3086c4cb7..40526507f50b 100644
> > > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
> > > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
> > > @@ -23,6 +23,7 @@
> > >     *
> > >     */
> > > +#include <linux/string.h>
> > >    #include "amdgpu_dm_replay.h"
> > >    #include "dc.h"
> > >    #include "dm_helpers.h"
> > > @@ -74,6 +75,8 @@ bool amdgpu_dm_setup_replay(struct dc_link *link, struct amdgpu_dm_connector *ac
> > >         struct replay_config pr_config;
> > 
> > I would prefer setting pr_config = {0};
> > 
> > >         union replay_debug_flags *debug_flags = NULL;
> > > +     memset(&pr_config, 0, sizeof(pr_config));
> > > +
> > >         // For eDP, if Replay is supported, return true to skip checks
> > >         if (link->replay_settings.config.replay_supported)
> > >                 return true;
> > -- 
> > Hamza
> > 
> -- 
> Hamza
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in amdgpu_dm_setup_replay
  2023-10-28  0:48       ` Yuran Pereira
@ 2023-10-30 15:52         ` Christian König
  0 siblings, 0 replies; 3+ messages in thread
From: Christian König @ 2023-10-30 15:52 UTC (permalink / raw)
  To: Yuran Pereira, Hamza Mahfooz
  Cc: Li, Sun peng (Leo),
	Lakha, Bhawanpreet, Pan, Xinhui, Siqueira, Rodrigo, linux-kernel,
	amd-gfx, dri-devel, Deucher, Alexander, airlied, Koenig,
	Christian, linux-kernel-mentees

Am 28.10.23 um 02:48 schrieb Yuran Pereira:
> Hello,
> On Fri, Oct 27, 2023 at 11:57:45AM -0400, Hamza Mahfooz wrote:
>> On 10/27/23 11:55, Lakha, Bhawanpreet wrote:
>>> [AMD Official Use Only - General]
>>>
>>>
>>>
>>> There was a consensus to use memset instead of {0}. I remember making
>>> changes related to that previously.
>> Hm, seems like it's used rather consistently in the DM and in DC
>> though.
>>
> Have you decided which one should be used?
>
> Should I submit a v2 patch using {0} instead of memset?

The problem is that {0} doesn't initialize padding fields in structures.

So what can happen are problems like leaking bytes to userspace or 
getting unstable hash keys etc...

So I think memset() is usually preferred and that not only counts for Linux.

Regards,
Christian.

>
>
> Yuran Pereira
>>> Bhawan
>>>
>>> ------------------------------------------------------------------------
>>> *From:* Mahfooz, Hamza <Hamza.Mahfooz@amd.com>
>>> *Sent:* October 27, 2023 11:53 AM
>>> *To:* Yuran Pereira <yuran.pereira@hotmail.com>; airlied@gmail.com
>>> <airlied@gmail.com>
>>> *Cc:* Li, Sun peng (Leo) <Sunpeng.Li@amd.com>; Lakha, Bhawanpreet
>>> <Bhawanpreet.Lakha@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; Siqueira,
>>> Rodrigo <Rodrigo.Siqueira@amd.com>; linux-kernel@vger.kernel.org
>>> <linux-kernel@vger.kernel.org>; amd-gfx@lists.freedesktop.org
>>> <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org
>>> <dri-devel@lists.freedesktop.org>; Deucher, Alexander
>>> <Alexander.Deucher@amd.com>; Koenig, Christian
>>> <Christian.Koenig@amd.com>;
>>> linux-kernel-mentees@lists.linuxfoundation.org
>>> <linux-kernel-mentees@lists.linuxfoundation.org>
>>> *Subject:* Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in
>>> amdgpu_dm_setup_replay
>>> On 10/26/23 17:25, Yuran Pereira wrote:
>>>> Since `pr_config` is not initialized after its declaration, the
>>>> following operations with `replay_enable_option` may be performed
>>>> when `replay_enable_option` is holding junk values which could
>>>> possibly lead to undefined behaviour
>>>>
>>>> ```
>>>>        ...
>>>>        pr_config.replay_enable_option |= pr_enable_option_static_screen;
>>>>        ...
>>>>
>>>>        if (!pr_config.replay_timing_sync_supported)
>>>>            pr_config.replay_enable_option &= ~pr_enable_option_general_ui;
>>>>        ...
>>>> ```
>>>>
>>>> This patch initializes `pr_config` after its declaration to ensure that
>>>> it doesn't contain junk data, and prevent any undefined behaviour
>>>>
>>>> Addresses-Coverity-ID: 1544428 ("Uninitialized scalar variable")
>>>> Fixes: dede1fea4460 ("drm/amd/display: Add Freesync Panel DM code")
>>>> Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
>>>> ---
>>>>     drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c | 3 +++
>>>>     1 file changed, 3 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
>>>> index 32d3086c4cb7..40526507f50b 100644
>>>> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
>>>> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c
>>>> @@ -23,6 +23,7 @@
>>>>      *
>>>>      */
>>>> +#include <linux/string.h>
>>>>     #include "amdgpu_dm_replay.h"
>>>>     #include "dc.h"
>>>>     #include "dm_helpers.h"
>>>> @@ -74,6 +75,8 @@ bool amdgpu_dm_setup_replay(struct dc_link *link, struct amdgpu_dm_connector *ac
>>>>          struct replay_config pr_config;
>>> I would prefer setting pr_config = {0};
>>>
>>>>          union replay_debug_flags *debug_flags = NULL;
>>>> +     memset(&pr_config, 0, sizeof(pr_config));
>>>> +
>>>>          // For eDP, if Replay is supported, return true to skip checks
>>>>          if (link->replay_settings.config.replay_supported)
>>>>                  return true;
>>> -- 
>>> Hamza
>>>
>> -- 
>> Hamza
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-30 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 21:25 [PATCH] drm/amdgpu: Fixes uninitialized variable usage in amdgpu_dm_setup_replay Yuran Pereira
     [not found] ` <dc2242cd-6522-4073-b376-edc2a9abc3d9@amd.com>
     [not found]   ` <PH8PR12MB727953EE85D593EF25650454F9DCA@PH8PR12MB7279.namprd12.prod.outlook.com>
     [not found]     ` <39ab34ec-209d-4176-b271-1a02e2976497@amd.com>
2023-10-28  0:48       ` Yuran Pereira
2023-10-30 15:52         ` Christian König

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®