All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/tegra: fix a possible null pointer dereference
@ 2024-05-31 13:56 Huai-Yuan Liu
  2024-05-31 14:27 ` Thierry Reding
  0 siblings, 1 reply; 3+ messages in thread
From: Huai-Yuan Liu @ 2024-05-31 13:56 UTC (permalink / raw)
  To: thierry.reding, mperttunen, airlied, daniel, jonathanh
  Cc: dri-devel, linux-tegra, linux-kernel, baijiaju1990, Huai-Yuan Liu

In malidp_tegra_crtc_reset, new memory is allocated with kzalloc, but 
no check is performed. Before calling __drm_atomic_helper_crtc_reset, 
mw_state should be checked to prevent possible null pointer dereferene.

Fixes: b7e0b04ae450 ("drm/tegra: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
---
 drivers/gpu/drm/tegra/dc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index be61c9d1a4f0..7648e129c212 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1388,7 +1388,8 @@ static void tegra_crtc_reset(struct drm_crtc *crtc)
 	if (crtc->state)
 		tegra_crtc_atomic_destroy_state(crtc, crtc->state);
 
-	__drm_atomic_helper_crtc_reset(crtc, &state->base);
+	if (state)
+		__drm_atomic_helper_crtc_reset(crtc, &state->base);
 }
 
 static struct drm_crtc_state *
-- 
2.34.1


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

* Re: [PATCH] drm/tegra: fix a possible null pointer dereference
  2024-05-31 13:56 [PATCH] drm/tegra: fix a possible null pointer dereference Huai-Yuan Liu
@ 2024-05-31 14:27 ` Thierry Reding
  0 siblings, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2024-05-31 14:27 UTC (permalink / raw)
  To: Huai-Yuan Liu, mperttunen, airlied, daniel, jonathanh
  Cc: dri-devel, linux-tegra, linux-kernel, baijiaju1990

[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]

On Fri May 31, 2024 at 3:56 PM CEST, Huai-Yuan Liu wrote:
> In malidp_tegra_crtc_reset, new memory is allocated with kzalloc, but 
> no check is performed. Before calling __drm_atomic_helper_crtc_reset, 
> mw_state should be checked to prevent possible null pointer dereferene.

Please check that all these variable name references actually are valid.

Also, "dereference".

> Fixes: b7e0b04ae450 ("drm/tegra: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
> Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
> ---
>  drivers/gpu/drm/tegra/dc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
> index be61c9d1a4f0..7648e129c212 100644
> --- a/drivers/gpu/drm/tegra/dc.c
> +++ b/drivers/gpu/drm/tegra/dc.c
> @@ -1388,7 +1388,8 @@ static void tegra_crtc_reset(struct drm_crtc *crtc)
>  	if (crtc->state)
>  		tegra_crtc_atomic_destroy_state(crtc, crtc->state);
>  
> -	__drm_atomic_helper_crtc_reset(crtc, &state->base);
> +	if (state)
> +		__drm_atomic_helper_crtc_reset(crtc, &state->base);

Looking at how other drivers do this, they call

	__drm_atomic_helper_crtc_reset(crtc, NULL);

if they fail to allocate a new state. Any reason why we wouldn't want to
do the same thing here?

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH] drm/tegra: fix a possible null pointer dereference
@ 2024-11-06  9:59 Qiu-ji Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Qiu-ji Chen @ 2024-11-06  9:59 UTC (permalink / raw)
  To: thierry.reding, mperttunen, airlied, simona, jonathanh
  Cc: dri-devel, linux-tegra, linux-kernel, baijiaju1990, Qiu-ji Chen,
	stable

In tegra_crtc_reset(), new memory is allocated with kzalloc(), but
no check is performed. Before calling __drm_atomic_helper_crtc_reset,
state should be checked to prevent possible null pointer dereference.

Fixes: b7e0b04ae450 ("drm/tegra: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
Cc: stable@vger.kernel.org
Signed-off-by: Qiu-ji Chen <chenqiuji666@gmail.com>
---
 drivers/gpu/drm/tegra/dc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index be61c9d1a4f0..1ed30853bd9e 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1388,7 +1388,10 @@ static void tegra_crtc_reset(struct drm_crtc *crtc)
 	if (crtc->state)
 		tegra_crtc_atomic_destroy_state(crtc, crtc->state);
 
-	__drm_atomic_helper_crtc_reset(crtc, &state->base);
+	if (state)
+		 __drm_atomic_helper_crtc_reset(crtc, &state->base);
+	else
+		 __drm_atomic_helper_crtc_reset(crtc, NULL);
 }
 
 static struct drm_crtc_state *
-- 
2.34.1


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

end of thread, other threads:[~2024-11-06  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31 13:56 [PATCH] drm/tegra: fix a possible null pointer dereference Huai-Yuan Liu
2024-05-31 14:27 ` Thierry Reding
  -- strict thread matches above, loose matches on Subject: below --
2024-11-06  9:59 Qiu-ji Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.