Skip to contentSkip to conversation

drm: Fix possible EDID memory allocation oops

PATCH In review Tim Gardner 2 participants 2 messages Dec 5, 2012 – Dec 6, 2012

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

PATCH 1/1 drm: Fix possible EDID memory allocation oops

The result of drm_property_create_blob() is not checked for success which could lead to a NULL pointer dereference.

I was led to this by a smatch warning:

drivers/gpu/drm/drm_crtc.c:3186 drm_mode_connector_update_edid_property() error: potential null dereference 'connector->edid_blob_ptr'. (drm_property_create_blob returns null)

drm_property_create_blob() calls kzalloc() which can return NULL.

---

This bug actually exists in the original commit f453ba0460742ad027ae0c4c7d61e62817b3e7ef (2.6.29), but I only checked as far back as 3.0 for stable.

 drivers/gpu/drm/drm_crtc.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_crtc.c +4 -0
index ef1b221..31872ba 100644
@@ -3180,6 +3180,10 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 	size = EDID_LENGTH * (1 + edid->extensions);
 	connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
 							    size, edid);
+	if (!connector->edid_blob_ptr) {
+		pr_err("drm: Could not allocate %d edid blob bytes.\n", size);
+		return -ENOMEM;
+	}
 
 	ret = drm_connector_property_set_value(connector,
 					       dev->mode_config.edid_property,
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Tim Gardner

The result of drm_property_create_blob() is not checked for success which could lead to a NULL pointer dereference.

I was led to this by a smatch warning:

Quoted 8 lines

drivers/gpu/drm/drm_crtc.c:3186 drm_mode_connector_update_edid_property() error: potential null dereference 'connector->edid_blob_ptr'. (drm_property_create_blob returns null)

drm_property_create_blob() calls kzalloc() which can return NULL.

Quoted 30 lines

---

This bug actually exists in the original commit f453ba0460742ad027ae0c4c7d61e62817b3e7ef (2.6.29), but I only checked as far back as 3.0 for stable.

 drivers/gpu/drm/drm_crtc.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_crtc.c +4 -1
index ef1b221..31872ba 100644
@@ -3180,6 +3180,10 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
        size = EDID_LENGTH * (1 + edid->extensions);
        connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
                                                            size, edid);
+       if (!connector->edid_blob_ptr) {
+               pr_err("drm: Could not allocate %d edid blob bytes.\n", size);
+               return -ENOMEM;
+       }
 
        ret = drm_connector_property_set_value(connector,
                                               dev->mode_config.edid_property,
--

1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel