Skip to contentSkip to conversation

drm/fb-helper: Fix potential NULL pointer dereference

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Dec 5, 2017 – Dec 6, 2017

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

PATCH 1/1 drm/fb-helper: Fix potential NULL pointer dereference

fb_helper is being dereferenced before it is null checked, hence there is a potential null pointer dereference.

Fix this by moving the pointer dereference after fb_helper has been null checked.

This issue was detected with the help of Coccinelle.

Fixes c777990fb45b ("drm/fb-helper: Handle function NULL argument")
---
 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +3 -1
index 6654f2f..04a3a5c 100644
@@ -178,7 +178,7 @@ EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
  */
 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
 {
-	struct drm_device *dev = fb_helper->dev;
+	struct drm_device *dev;
 	struct drm_connector *connector;
 	struct drm_connector_list_iter conn_iter;
 	int i, ret = 0;
@@ -186,6 +186,8 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
 	if (!drm_fbdev_emulation || !fb_helper)
 		return 0;
 
+	dev = fb_helper->dev;
+
 	mutex_lock(&fb_helper->lock);
 	drm_connector_list_iter_begin(dev, &conn_iter);
 	drm_for_each_connector_iter(connector, &conn_iter) {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Gustavo A. R. Silva

fb_helper is being dereferenced before it is null checked, hence there is a potential null pointer dereference.

Fix this by moving the pointer dereference after fb_helper has been null checked.

This issue was detected with the help of Coccinelle.

Fixes c777990fb45b ("drm/fb-helper: Handle function NULL argument")

Oops. Applied to drm-misc-next, thanks for your patch. -Daniel

Quoted 33 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +3 -1
index 6654f2f..04a3a5c 100644
@@ -178,7 +178,7 @@ EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
  */
 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
 {
-	struct drm_device *dev = fb_helper->dev;
+	struct drm_device *dev;
 	struct drm_connector *connector;
 	struct drm_connector_list_iter conn_iter;
 	int i, ret = 0;
@@ -186,6 +186,8 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
 	if (!drm_fbdev_emulation || !fb_helper)
 		return 0;
 
+	dev = fb_helper->dev;
+
 	mutex_lock(&fb_helper->lock);
 	drm_connector_list_iter_begin(dev, &conn_iter);
 	drm_for_each_connector_iter(connector, &conn_iter) {
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw

Quoting Daniel Vetter <[email protected]>:

Quoted 7 lines · Gustavo A. R. Silva
Quoted 6 lines

fb_helper is being dereferenced before it is null checked, hence there is a potential null pointer dereference.

Fix this by moving the pointer dereference after fb_helper has been null checked.

Quoted 8 lines
Quoted 4 lines

This issue was detected with the help of Coccinelle.

Fixes c777990fb45b ("drm/fb-helper: Handle function NULL argument")

Oops. Applied to drm-misc-next, thanks for your patch. -Daniel

Glad to help. :)

Thanks
--
Gustavo A. R. Silva