Skip to contentSkip to conversation

drm/tegra: fix a possible null pointer dereference

PATCH Superseded Huai-Yuan Liu 2 participants 2 messages May 31, 2024

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/tegra: fix a possible null pointer dereference

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.")
---
 drivers/gpu/drm/tegra/dc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/tegra/dc.c +2 -1
index be61c9d1a4f0..7648e129c212 100644
@@ -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 *
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · 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.

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

Also, "dereference".

Quoted 11 lines
Fixes b7e0b04ae450 ("drm/tegra: Convert to using __drm_atomic_helper_crtc_reset() for reset.")
---
 drivers/gpu/drm/tegra/dc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/tegra/dc.c +0 -0
index be61c9d1a4f0..7648e129c212 100644

drivers/gpu/drm/tegra/dc.c static void tegra_crtc_reset(struct drm_crtc *crtc) · line 1392

Quoted 6 lines
drivers/gpu/drm/tegra/dc.c +2 -1
@@ -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