Skip to contentSkip to conversation

drm: Make sure that encoder_type for drm_encoder_init() is in the list

PATCH In review Jordan Crouse 2 participants 2 messages Jun 29, 2018 – Jul 2, 2018

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

PATCH 1/1 drm: Make sure that encoder_type for drm_encoder_init() is in the list

If a encoder name isn't specified for drm_encoder_init() it will try to construct one based on the incoming encoder_type identifier. If the caller passes an invalid encoder_type value the lookup could walk right past the end of the table.

[v2: Use a WARN() at the top of the function as suggested by Daniel
Vetter]

---
 drivers/gpu/drm/drm_encoder.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_encoder.c +4 -0
index 273e1c59c54a..6228c2cee5f0 100644
@@ -114,6 +114,10 @@ int drm_encoder_init(struct drm_device *dev,
 	if (WARN_ON(dev->mode_config.num_encoder >= 32))
 		return -EINVAL;
 
+	/* Make sure that the requested encoder type is in the list */
+	if (WARN_ON(encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)))
+		return -EINVAL;
+
 	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
 	if (ret)
 		return ret;
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jordan Crouse

If a encoder name isn't specified for drm_encoder_init() it will try to construct one based on the incoming encoder_type identifier. If the caller passes an invalid encoder_type value the lookup could walk right past the end of the table.

[v2: Use a WARN() at the top of the function as suggested by Daniel
Vetter]

Aside: Want drm-misc commit rights so you can push patches like these yourself?

Might also be useful in case the group maintainership thing with msm happens, just as prep.
-Daniel

Quoted 22 lines
---
 drivers/gpu/drm/drm_encoder.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_encoder.c +4 -0
index 273e1c59c54a..6228c2cee5f0 100644
@@ -114,6 +114,10 @@ int drm_encoder_init(struct drm_device *dev,
 	if (WARN_ON(dev->mode_config.num_encoder >= 32))
 		return -EINVAL;
 
+	/* Make sure that the requested encoder type is in the list */
+	if (WARN_ON(encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)))
+		return -EINVAL;
+
 	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
 	if (ret)
 		return ret;
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel