nouveau.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes
@ 2024-06-26  1:30 Ma Ke
  2024-06-26  9:44 ` Jani Nikula
  2024-06-26 11:35 ` Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Ma Ke @ 2024-06-26  1:30 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, Ma Ke

In nouveau_connector_get_modes(), the return value of drm_mode_duplicate()
is assigned to mode, which will lead to a possible NULL pointer
dereference on failure of drm_mode_duplicate(). Add a check to avoid npd.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/gpu/drm/nouveau/nouveau_connector.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 856b3ef5edb8..010eed56b14d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -1001,6 +1001,8 @@ nouveau_connector_get_modes(struct drm_connector *connector)
 		struct drm_display_mode *mode;
 
 		mode = drm_mode_duplicate(dev, nv_connector->native_mode);
+		if (!mode)
+			return -ENOMEM;
 		drm_mode_probed_add(connector, mode);
 		ret = 1;
 	}
-- 
2.25.1


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

* Re: [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes
  2024-06-26  1:30 [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes Ma Ke
@ 2024-06-26  9:44 ` Jani Nikula
  2024-06-26 14:53   ` Danilo Krummrich
  2024-06-26 11:35 ` Markus Elfring
  1 sibling, 1 reply; 4+ messages in thread
From: Jani Nikula @ 2024-06-26  9:44 UTC (permalink / raw)
  To: Ma Ke, kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, Ma Ke

On Wed, 26 Jun 2024, Ma Ke <make24@iscas.ac.cn> wrote:
> In nouveau_connector_get_modes(), the return value of drm_mode_duplicate()
> is assigned to mode, which will lead to a possible NULL pointer
> dereference on failure of drm_mode_duplicate(). Add a check to avoid npd.
>
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/gpu/drm/nouveau/nouveau_connector.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
> index 856b3ef5edb8..010eed56b14d 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_connector.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
> @@ -1001,6 +1001,8 @@ nouveau_connector_get_modes(struct drm_connector *connector)
>  		struct drm_display_mode *mode;
>  
>  		mode = drm_mode_duplicate(dev, nv_connector->native_mode);
> +		if (!mode)
> +			return -ENOMEM;

Do not return negative values from .get_modes().

BR,
Jani.

>  		drm_mode_probed_add(connector, mode);
>  		ret = 1;
>  	}

-- 
Jani Nikula, Intel

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

* Re: [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes
  2024-06-26  1:30 [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes Ma Ke
  2024-06-26  9:44 ` Jani Nikula
@ 2024-06-26 11:35 ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-06-26 11:35 UTC (permalink / raw)
  To: Ma Ke, nouveau, dri-devel, Daniel Vetter, Danilo Krummrich,
	David Airlie, Karol Herbst, Lyude Paul
  Cc: LKML

> In nouveau_connector_get_modes(), the return value of drm_mode_duplicate()
> is assigned to mode, which will lead to a possible NULL pointer
> dereference on failure of drm_mode_duplicate(). Add a check to avoid npd.

1. Can a wording approach (like the following) be a better change description?

   A null pointer is stored in the local variable “mode” after a call
   of the function “drm_mode_duplicate” failed. This pointer was passed to
   a subsequent call of the function “drm_mode_probed_add” where an undesirable
   dereference will be performed then.
   Thus add a corresponding return value check.


2. Would you like to add any tags (like “Fixes” and “Cc”) accordingly?


3. How do you think about to append parentheses to the function name
   in the summary phrase?


4. How do you think about to put similar results from static source code
   analyses into corresponding patch series?


Regards,
Markus

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

* Re: [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes
  2024-06-26  9:44 ` Jani Nikula
@ 2024-06-26 14:53   ` Danilo Krummrich
  0 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2024-06-26 14:53 UTC (permalink / raw)
  To: Ma Ke
  Cc: dri-devel, nouveau, lyude, linux-kernel, daniel, airlied, kherbst,
	Jani Nikula

On 6/26/24 11:44, Jani Nikula wrote:
> On Wed, 26 Jun 2024, Ma Ke <make24@iscas.ac.cn> wrote:
>> In nouveau_connector_get_modes(), the return value of drm_mode_duplicate()
>> is assigned to mode, which will lead to a possible NULL pointer
>> dereference on failure of drm_mode_duplicate(). Add a check to avoid npd.
>>

Please add a "Fixes" tag (also for your previous commits) and CC stable.

>> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
>> ---
>>   drivers/gpu/drm/nouveau/nouveau_connector.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
>> index 856b3ef5edb8..010eed56b14d 100644
>> --- a/drivers/gpu/drm/nouveau/nouveau_connector.c
>> +++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
>> @@ -1001,6 +1001,8 @@ nouveau_connector_get_modes(struct drm_connector *connector)
>>   		struct drm_display_mode *mode;
>>   
>>   		mode = drm_mode_duplicate(dev, nv_connector->native_mode);
>> +		if (!mode)
>> +			return -ENOMEM;
> 
> Do not return negative values from .get_modes().

+1

https://elixir.bootlin.com/linux/latest/source/include/drm/drm_modeset_helper_vtables.h#L899

> 
> BR,
> Jani.
> 
>>   		drm_mode_probed_add(connector, mode);
>>   		ret = 1;
>>   	}
> 


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

end of thread, other threads:[~2025-12-13 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-26  1:30 [PATCH] drm/nouveau: fix null pointer dereference in nouveau_connector_get_modes Ma Ke
2024-06-26  9:44 ` Jani Nikula
2024-06-26 14:53   ` Danilo Krummrich
2024-06-26 11:35 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).