Skip to contentSkip to conversation

drm/client: fix null pointer dereference in drm_client_modeset_probe

PATCH RESEND In review Ma Ke 2 participants 3 messages Aug 2, 2024

Subsystems (3)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH RESEND v4 1/1 drm/client: fix null pointer dereference in drm_client_modeset_probe

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

Fixes cf13909aee05 ("drm/fb-helper: Move out modeset config code")

---
Changes in v4:
- modified patch, set ret and break to handle error rightly. Changes in v3:
- modified patch as suggestions, returned error directly when failing to get modeset->mode.
Changes in v2:
- added the recipient's email address, due to the prolonged absence of a response from the recipients.
- added Cc stable.

---
 drivers/gpu/drm/drm_client_modeset.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +5 -0
index 31af5cf37a09..cee5eafbfb81 100644
@@ -880,6 +880,11 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,
 
 			kfree(modeset->mode);
 			modeset->mode = drm_mode_duplicate(dev, mode);
+			if (!modeset->mode) {
+				ret = -ENOMEM;
+				break;
+			}
+
 			drm_connector_get(connector);
 			modeset->connectors[modeset->num_connectors++] = connector;
 			modeset->x = offset->x;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v4 1/1
#1 lore raw

Am 02.08.24 um 06:47 schrieb Ma Ke:

Quoted 7 lines

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

Fixes cf13909aee05 ("drm/fb-helper: Move out modeset config code")
Quoted 30 lines

---
Changes in v4:
- modified patch, set ret and break to handle error rightly. Changes in v3:
- modified patch as suggestions, returned error directly when failing to get modeset->mode.
Changes in v2:
- added the recipient's email address, due to the prolonged absence of a response from the recipients.
- added Cc stable.

---
  drivers/gpu/drm/drm_client_modeset.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +5 -0
index 31af5cf37a09..cee5eafbfb81 100644
@@ -880,6 +880,11 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,
 
  			kfree(modeset->mode);
  			modeset->mode = drm_mode_duplicate(dev, mode);
+			if (!modeset->mode) {
+				ret = -ENOMEM;
+				break;
+			}
+
  			drm_connector_get(connector);
  			modeset->connectors[modeset->num_connectors++] = connector;
  			modeset->x = offset->x;
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#2 lore raw
In reply to Ma Ke

Hi

Am 02.08.24 um 06:47 schrieb Ma Ke:

Quoted 7 lines

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

Fixes cf13909aee05 ("drm/fb-helper: Move out modeset config code")

Thanks, merged into drm-misc-fixes.

Best regards
Thomas

Quoted 30 lines

---
Changes in v4:
- modified patch, set ret and break to handle error rightly. Changes in v3:
- modified patch as suggestions, returned error directly when failing to get modeset->mode.
Changes in v2:
- added the recipient's email address, due to the prolonged absence of a response from the recipients.
- added Cc stable.

---
  drivers/gpu/drm/drm_client_modeset.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/drm_client_modeset.c +5 -0
index 31af5cf37a09..cee5eafbfb81 100644
@@ -880,6 +880,11 @@ int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width,
 
  			kfree(modeset->mode);
  			modeset->mode = drm_mode_duplicate(dev, mode);
+			if (!modeset->mode) {
+				ret = -ENOMEM;
+				break;
+			}
+
  			drm_connector_get(connector);
  			modeset->connectors[modeset->num_connectors++] = connector;
  			modeset->x = offset->x;
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)