Skip to contentSkip to conversation

drm/fb-helper: Fix drm_fb_helper_hotplug_event() NULL ptr argument

PATCH In review Noralf Trønnes 3 participants 5 messages May 15, 2019 – May 16, 2019

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

PATCH 1/1 drm/fb-helper: Fix drm_fb_helper_hotplug_event() NULL ptr argument

drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace") introduced a fb_helper dereference before the NULL check. Fixup by moving the dereference after the NULL check.

Fixes 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")
---
 drivers/gpu/drm/drm_fb_helper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +2 -3
index c259a28522f8..a52b48fafbd7 100644
@@ -3031,7 +3031,6 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
  */
 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 {
-	struct drm_device *dev = fb_helper->dev;
 	int err = 0;
 
 	if (!drm_fbdev_emulation || !fb_helper)
@@ -3044,13 +3043,13 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 		return err;
 	}
 
-	if (!fb_helper->fb || !drm_master_internal_acquire(dev)) {
+	if (!fb_helper->fb || !drm_master_internal_acquire(fb_helper->dev)) {
 		fb_helper->delayed_hotplug = true;
 		mutex_unlock(&fb_helper->lock);
 		return err;
 	}
 
-	drm_master_internal_release(dev);
+	drm_master_internal_release(fb_helper->dev);
 
 	DRM_DEBUG_KMS("\n");
 
Signature · 6 lines
2.20.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 · Noralf Trønnes

drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace") introduced a fb_helper dereference before the NULL check. Fixup by moving the dereference after the NULL check.

Fixes 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")

Ah the classic "I spotted a deref before your NULL check, I'm going to optimize this all away because you got it wrong" nonsense from gcc. I thought the kernel uses a special compile flag to avoid this optimization
...

Quoted 39 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +2 -3
index c259a28522f8..a52b48fafbd7 100644
@@ -3031,7 +3031,6 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
  */
 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 {
-	struct drm_device *dev = fb_helper->dev;
 	int err = 0;
 
 	if (!drm_fbdev_emulation || !fb_helper)
@@ -3044,13 +3043,13 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 		return err;
 	}
 
-	if (!fb_helper->fb || !drm_master_internal_acquire(dev)) {
+	if (!fb_helper->fb || !drm_master_internal_acquire(fb_helper->dev)) {
 		fb_helper->delayed_hotplug = true;
 		mutex_unlock(&fb_helper->lock);
 		return err;
 	}
 
-	drm_master_internal_release(dev);
+	drm_master_internal_release(fb_helper->dev);
 
 	DRM_DEBUG_KMS("\n");
 
Signature · 6 lines
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
#2 lore raw
Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Noralf Trønnes

drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace") introduced a fb_helper dereference before the NULL check. Fixup by moving the dereference after the NULL check.

Fixes 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")
Quoted 4 lines

Ah the classic "I spotted a deref before your NULL check, I'm going to optimize this all away because you got it wrong" nonsense from gcc. I thought the kernel uses a special compile flag to avoid this optimization
...

This is just a normal NULL dereference bug.

You're thinking of the old tun.c vulnerability. That was back in the day before we started using -fno-delete-null-pointer-checks. What happened there was the code should have NULL dereferenced and Oopsed but GCC optimized it away and it ended up being a privilege escalation bug instead.

regards,
dan carpenter

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

#3 lore raw
Quoted 17 lines · Dan Carpenter
Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Noralf Trønnes

drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace") introduced a fb_helper dereference before the NULL check. Fixup by moving the dereference after the NULL check.

Fixes 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")
Quoted 4 lines

Ah the classic "I spotted a deref before your NULL check, I'm going to optimize this all away because you got it wrong" nonsense from gcc. I thought the kernel uses a special compile flag to avoid this optimization
...

Quoted 7 lines

This is just a normal NULL dereference bug.

You're thinking of the old tun.c vulnerability. That was back in the day before we started using -fno-delete-null-pointer-checks. What happened there was the code should have NULL dereferenced and Oopsed but GCC optimized it away and it ended up being a privilege escalation bug instead.

Hm right, I got confused.
-Daniel

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
#4 lore raw
In reply to Daniel Vetter

Den 15.05.2019 15.40, skrev Daniel Vetter:

Quoted 6 lines · Noralf Trønnes
Quoted 5 lines

drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace") introduced a fb_helper dereference before the NULL check. Fixup by moving the dereference after the NULL check.

Quoted 7 lines
Quoted 4 lines
Fixes 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")

Thanks Dan and Daniel, applied to drm-misc-next.

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