Skip to contentSkip to conversation

drm/client: Do not destroy NULL modes

PATCH In review Jonathan Cavitt 2 participants 2 messages Feb 24 – Feb 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/client: Do not destroy NULL modes

'modes' in drm_client_modeset_probe may fail to kcalloc. If this occurs, we jump to 'out', calling modes_destroy on it, which dereferences it. This may result in a NULL pointer dereference in the error case. Prevent that.

Fixes 3039cc0c0653 ("drm/client: Make copies of modes")
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/drm_client_modeset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_client_modeset.c +2 -1
index 262b1b8773c5..bb49b8361271 100644
@@ -930,7 +930,8 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,
 	mutex_unlock(&client->modeset_mutex);
 out:
 	kfree(crtcs);
-	modes_destroy(dev, modes, connector_count);
+	if (modes)
+		modes_destroy(dev, modes, connector_count);
 	kfree(modes);
 	kfree(offsets);
 	kfree(enabled);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Jonathan Cavitt

'modes' in drm_client_modeset_probe may fail to kcalloc. If this occurs, we jump to 'out', calling modes_destroy on it, which dereferences it. This may result in a NULL pointer dereference in the error case. Prevent that.

Fixes 3039cc0c0653 ("drm/client: Make copies of modes")
Cc Ville Syrjälä <[email protected]>

Thanks. Pushed to drm-misc-fixes.

Quoted 20 lines
---
 drivers/gpu/drm/drm_client_modeset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_client_modeset.c +2 -1
index 262b1b8773c5..bb49b8361271 100644
@@ -930,7 +930,8 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,
 	mutex_unlock(&client->modeset_mutex);
 out:
 	kfree(crtcs);
-	modes_destroy(dev, modes, connector_count);
+	if (modes)
+		modes_destroy(dev, modes, connector_count);
 	kfree(modes);
 	kfree(offsets);
 	kfree(enabled);
Signature · 1 line
2.43.0
Signature · 2 lines
Ville Syrjälä
Intel