Skip to contentSkip to conversation

drm/core: Fix ordering in drm_mode_config_cleanup.

PATCH Applied Maarten Lankhorst 4 participants 6 messages Mar 22, 2016 – Apr 12, 2016

Subsystems (2)
lore
Share & tools
lore

Maarten Lankhorst

author maintainer
#0 lore raw

PATCH 1/1 drm/core: Fix ordering in drm_mode_config_cleanup.

__drm_atomic_helper_plane_destroy_state calls drm_framebuffer_unreference, which means that if drm_framebuffer_free is called before plane->destroy freed memory will be accessed.

A similar case happens for the blob list, which was freed before the crtc state was, resulting in the unreference_blob from crtc_destroy_state pointing to garbage memory causing another opportunity for a GPF.

---
 drivers/gpu/drm/drm_crtc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_crtc.c +9 -9
index 51c5a00ffdff..5a13b1afccbe 100644
@@ -5958,6 +5958,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_property_destroy(dev, property);
 	}
 
+	list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
+				 head) {
+		plane->funcs->destroy(plane);
+	}
+
+	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
+		crtc->funcs->destroy(crtc);
+	}
+
 	list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
 				 head_global) {
 		drm_property_unreference_blob(blob);
@@ -5976,15 +5985,6 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_framebuffer_free(&fb->refcount);
 	}
 
-	list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
-				 head) {
-		plane->funcs->destroy(plane);
-	}
-
-	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
-		crtc->funcs->destroy(crtc);
-	}
-
 	ida_destroy(&dev->mode_config.connector_ida);
 	idr_destroy(&dev->mode_config.tile_idr);
 	idr_destroy(&dev->mode_config.crtc_idr);
Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 18 lines · Maarten Lankhorst

__drm_atomic_helper_plane_destroy_state calls drm_framebuffer_unreference, which means that if drm_framebuffer_free is called before plane->destroy freed memory will be accessed.

A similar case happens for the blob list, which was freed before the crtc state was, resulting in the unreference_blob from crtc_destroy_state pointing to garbage memory causing another opportunity for a GPF.

---
 drivers/gpu/drm/drm_crtc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_crtc.c +0 -0
index 51c5a00ffdff..5a13b1afccbe 100644

drivers/gpu/drm/drm_crtc.c void drm_mode_config_cleanup(struct drm_device *dev) · line 5959

Quoted 2 lines
drivers/gpu/drm/drm_crtc.c +0 -0
@@ -5958,6 +5958,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_property_destroy(dev, property);
 	}

And what about props? Any chance of explosion due to those being gone?

Quoted 36 lines
drivers/gpu/drm/drm_crtc.c +9 -9
+	list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
+				 head) {
+		plane->funcs->destroy(plane);
+	}
+
+	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
+		crtc->funcs->destroy(crtc);
+	}
+
 	list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
 				 head_global) {
 		drm_property_unreference_blob(blob);
@@ -5976,15 +5985,6 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_framebuffer_free(&fb->refcount);
 	}
 
-	list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
-				 head) {
-		plane->funcs->destroy(plane);
-	}
-
-	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
-		crtc->funcs->destroy(crtc);
-	}
-
 	ida_destroy(&dev->mode_config.connector_ida);
 	idr_destroy(&dev->mode_config.tile_idr);
 	idr_destroy(&dev->mode_config.crtc_idr);
Signature · 6 lines
2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#2 lore raw

Op 22-03-16 om 15:58 schreef Ville Syrjälä:

Quoted 14 lines · Maarten Lankhorst
Quoted 13 lines

__drm_atomic_helper_plane_destroy_state calls drm_framebuffer_unreference, which means that if drm_framebuffer_free is called before plane->destroy freed memory will be accessed.

A similar case happens for the blob list, which was freed before the crtc state was, resulting in the unreference_blob from crtc_destroy_state pointing to garbage memory causing another opportunity for a GPF.

---
 drivers/gpu/drm/drm_crtc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Quoted 9 lines

drivers/gpu/drm/drm_crtc.c void drm_mode_config_cleanup(struct drm_device *dev) · line 5959

Quoted 7 lines
drivers/gpu/drm/drm_crtc.c +0 -0
index 51c5a00ffdff..5a13b1afccbe 100644
@@ -5958,6 +5958,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_property_destroy(dev, property);
 	}

And what about props? Any chance of explosion due to those being gone?

Not as far as I'm aware of.

If you use something like a crtc_x property, only the value gets written to crtc_state, the value is an int that would still be valid.

~Maarten
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by
#3 lore raw
Quoted 24 lines · Maarten Lankhorst

Op 22-03-16 om 15:58 schreef Ville Syrjälä:

Quoted 14 lines · Maarten Lankhorst
Quoted 13 lines

__drm_atomic_helper_plane_destroy_state calls drm_framebuffer_unreference, which means that if drm_framebuffer_free is called before plane->destroy freed memory will be accessed.

A similar case happens for the blob list, which was freed before the crtc state was, resulting in the unreference_blob from crtc_destroy_state pointing to garbage memory causing another opportunity for a GPF.

---
 drivers/gpu/drm/drm_crtc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Quoted 9 lines

drivers/gpu/drm/drm_crtc.c void drm_mode_config_cleanup(struct drm_device *dev) · line 5959

Quoted 7 lines
drivers/gpu/drm/drm_crtc.c +0 -0
index 51c5a00ffdff..5a13b1afccbe 100644
@@ -5958,6 +5958,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_property_destroy(dev, property);
 	}

And what about props? Any chance of explosion due to those being gone?

Quoted 3 lines

Not as far as I'm aware of.

If you use something like a crtc_x property, only the value gets written to crtc_state, the value is an int that would still be valid.

I was too lazy to confirm this for all drivers. But at least i915 looked clean on that front. So

Quoted 2 lines

~Maarten

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 25 lines · Ville Syrjälä
Quoted 24 lines · Maarten Lankhorst

Op 22-03-16 om 15:58 schreef Ville Syrjälä:

Quoted 23 lines · Maarten Lankhorst
Quoted 18 lines

__drm_atomic_helper_plane_destroy_state calls drm_framebuffer_unreference, which means that if drm_framebuffer_free is called before plane->destroy freed memory will be accessed.

A similar case happens for the blob list, which was freed before the crtc state was, resulting in the unreference_blob from crtc_destroy_state pointing to garbage memory causing another opportunity for a GPF.

---
 drivers/gpu/drm/drm_crtc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_crtc.c +0 -0
index 51c5a00ffdff..5a13b1afccbe 100644

drivers/gpu/drm/drm_crtc.c void drm_mode_config_cleanup(struct drm_device *dev) · line 5959

Quoted 2 lines
drivers/gpu/drm/drm_crtc.c +0 -0
@@ -5958,6 +5958,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 		drm_property_destroy(dev, property);
 	}

And what about props? Any chance of explosion due to those being gone?

Quoted 8 lines
Quoted 3 lines

Not as far as I'm aware of.

If you use something like a crtc_x property, only the value gets written to crtc_state, the value is an int that would still be valid.

I was too lazy to confirm this for all drivers. But at least i915 looked clean on that front. So

Applied to drm-misc, thanks.
-Daniel

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

✓ Fi.CI.BAT: success for drm/core: Fix ordering in drm_mode_config_cleanup.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/core: Fix ordering in drm_mode_config_cleanup.
URL : https://patchwork.freedesktop.org/series/4758/
State : success

== Summary ==

Series 4758v1 drm/core: Fix ordering in drm_mode_config_cleanup.
http://patchwork.freedesktop.org/api/1.0/series/4758/revisions/1/mbox/

Test kms_pipe_crc_basic:

        Subgroup suspend-read-crc-pipe-c:
                dmesg-warn -> PASS       (bsw-nuc-2)
Test pm_rpm:
        Subgroup basic-pci-d3-state:
                dmesg-warn -> PASS       (byt-nuc)
        Subgroup basic-rte:
                pass       -> DMESG-WARN (byt-nuc) UNSTABLE
bdw-nuci7        total:192  pass:180  dwarn:0   dfail:0   fail:0   skip:12 
bdw-ultra        total:192  pass:171  dwarn:0   dfail:0   fail:0   skip:21 
bsw-nuc-2        total:192  pass:154  dwarn:1   dfail:0   fail:0   skip:37 
byt-nuc          total:192  pass:156  dwarn:1   dfail:0   fail:0   skip:35 
hsw-brixbox      total:192  pass:170  dwarn:0   dfail:0   fail:0   skip:22 
hsw-gt2          total:192  pass:175  dwarn:0   dfail:0   fail:0   skip:17 
ivb-t430s        total:192  pass:167  dwarn:0   dfail:0   fail:0   skip:25 
skl-i5k-2        total:192  pass:169  dwarn:0   dfail:0   fail:0   skip:23 
skl-i7k-2        total:192  pass:169  dwarn:0   dfail:0   fail:0   skip:23 
skl-nuci5        total:192  pass:181  dwarn:0   dfail:0   fail:0   skip:11 
snb-dellxps      total:192  pass:158  dwarn:0   dfail:0   fail:0   skip:34 
snb-x220t        total:192  pass:158  dwarn:0   dfail:0   fail:1   skip:33 

Results at /archive/results/CI_IGT_test/Patchwork_1679/

83ed25fa1b956275542da63eb98dc8fd2291329d drm-intel-nightly: 2016y-03m-22d-15h-20m-55s UTC integration manifest 2fb96a0c0489a7c3c751ae69e7d13bf503d2ce25 drm/core: Fix ordering in drm_mode_config_cleanup.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx