Skip to contentSkip to conversation

drm/arm/malidp: fix a possible null pointer dereference

PATCH Superseded Huai-Yuan Liu 2 participants 2 messages Apr 3, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/arm/malidp: fix a possible null pointer dereference

In malidp_mw_connector_reset, new memory is allocated with kzalloc, but no check is performed. In order to prevent null pointer dereferencing, ensure that mw_state is checked before calling __drm_atomic_helper_connector_reset.

Fixes 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
---
 drivers/gpu/drm/arm/malidp_mw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_mw.c +3 -1
index 626709bec6f5..25623ef9be80 100644
@@ -72,7 +72,9 @@ static void malidp_mw_connector_reset(struct drm_connector *connector)
 		__drm_atomic_helper_connector_destroy_state(connector->state);
 
 	kfree(connector->state);
-	__drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+	if (mw_state)
+		__drm_atomic_helper_connector_reset(connector, &mw_state->base);
 }
 
 static enum drm_connector_status
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi,

Quoted 5 lines · Huai-Yuan Liu

In malidp_mw_connector_reset, new memory is allocated with kzalloc, but no check is performed. In order to prevent null pointer dereferencing, ensure that mw_state is checked before calling __drm_atomic_helper_connector_reset.

Thanks for the patch, it does look like an oversight. Can I suggest you respin your patch and add a

	connector->state = NULL;

right after kfree(connector->state) ?

That way we can be sure we're not leaving state pointing to freed memory.

Best regards,
Liviu

Quoted 25 lines
Fixes 8cbc5caf36ef ("drm: mali-dp: Add writeback connector")
---
 drivers/gpu/drm/arm/malidp_mw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/malidp_mw.c +3 -1
index 626709bec6f5..25623ef9be80 100644
@@ -72,7 +72,9 @@ static void malidp_mw_connector_reset(struct drm_connector *connector)
 		__drm_atomic_helper_connector_destroy_state(connector->state);
 
 	kfree(connector->state);
-	__drm_atomic_helper_connector_reset(connector, &mw_state->base);
+
+	if (mw_state)
+		__drm_atomic_helper_connector_reset(connector, &mw_state->base);
 }
 
 static enum drm_connector_status
Signature · 1 line
2.34.1
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯