Skip to contentSkip to conversation

Disable DRI2 if we're running on shadowfb

PATCH In review Julien Cristau 10 participants 15 messages Sep 22, 2010 – Sep 28, 2010 5 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Disable DRI2 if we're running on shadowfb

Without this change, DRI2 gets enabled but doesn't work and glxinfo crashes my X server.

---
 src/intel_driver.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
src/intel_driver.c +7 -6
index c0ad69e..ad90174 100644
@@ -830,12 +830,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
 
 	scrn->videoRam = device->regions[fb_bar].size / 1024;
 
-#ifdef DRI2
-	if (intel->directRenderingType == DRI_NONE
-	    && I830DRI2ScreenInit(screen))
-		intel->directRenderingType = DRI_DRI2;
-#endif
-
 	intel->force_fallback = FALSE;
 	intel->use_shadow = FALSE;
 
@@ -859,8 +853,15 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
 		xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
 			   "Shadow buffer enabled,"
 			   " GPU acceleration disabled.\n");
+		intel->directRenderingType = DRI_DISABLED;
 	}
 
+#ifdef DRI2
+	if (intel->directRenderingType == DRI_NONE
+	    && I830DRI2ScreenInit(screen))
+		intel->directRenderingType = DRI_DRI2;
+#endif
+
 	/* SwapBuffers delays to avoid tearing */
 	intel->swapbuffers_wait = TRUE;
 
Signature · 1 line
1.7.1
#1 lore raw

Re: [PATCH] Disable DRI2 if we are running on shadowfb

Quoted 2 lines · Julien Cristau

Without this change, DRI2 gets enabled but doesn't work and glxinfo crashes my X server.

Like this?

==2989== Invalid write of size 4

==2989==    at 0x48CE6E5: DrawableGone (glxext.c:169)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
==2989==  Address 0x55a9c1c is 76 bytes inside a block of size 88 free'd
==2989==    at 0x4023B6A: free (vg_replace_malloc.c:366)
==2989==    by 0x48D9DD8: __glXDRIcontextDestroy (glxdri2.c:250)
==2989==    by 0x48CE1A0: __glXFreeContext (glxext.c:222)
==2989==    by 0x48CE786: DrawableGone (glxext.c:165)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)

Kristian, I know how much you enjoy fixing these... You probably already have a patch. ;-)
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw

PATCH 1/1 glx: Fix use after free in DrawableGone

---

Quoted 16 lines

==2989== Invalid write of size 4

==2989==    at 0x48CE6E5: DrawableGone (glxext.c:169)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
==2989==  Address 0x55a9c1c is 76 bytes inside a block of size 88 free'd
==2989==    at 0x4023B6A: free (vg_replace_malloc.c:366)
==2989==    by 0x48D9DD8: __glXDRIcontextDestroy (glxdri2.c:250)
==2989==    by 0x48CE1A0: __glXFreeContext (glxext.c:222)
==2989==    by 0x48CE786: DrawableGone (glxext.c:165)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
Quoted 2 lines

Kristian, I know how much you enjoy fixing these... You probably already have a patch. ;-)

I think we're looking at this use after free problem. We may free the context in the big if-statement above and the go and touch its drawPriv and readPriv fields afterwards.

Kristian

 glx/glxext.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
glx/glxext.c +2 -4
index e203156..0b04c37 100644
@@ -160,15 +160,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 		    }
 		}
 	    }
-
-	    if (!c->idExists) {
-		__glXFreeContext(c);
-	    }
 	}
 	if (c->drawPriv == glxPriv)
 	    c->drawPriv = NULL;
 	if (c->readPriv == glxPriv)
 	    c->readPriv = NULL;
+	if (!c->idExists && !c->isCurrent)
+	    __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
Signature · 6 lines
1.7.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH v2 1/1 glx: Fix use after free in DrawableGone

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

Kristian

 glx/glxext.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -6
index e203156..f5ebe4f 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+	next = c->next;
 	if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
 	    int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 		    }
 		}
 	    }
-
-	    if (!c->idExists) {
-		__glXFreeContext(c);
-	    }
 	}
 	if (c->drawPriv == glxPriv)
 	    c->drawPriv = NULL;
 	if (c->readPriv == glxPriv)
 	    c->readPriv = NULL;
+	if (!c->idExists && !c->isCurrent)
+	    __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
Signature · 6 lines
1.7.3

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

A message that is not in the archive (sent off-list or not yet received): 1285247051-2717-1-git-send-email-krh-1OA22m9ORUweIZ0/[email protected]

Tested-by
#5 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

Quoted 1 line · Kristian Høgsberg

Now that is starting to look familiar ;-)

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#6 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

In reply to a message not in the archive

That seems off to me. This is doing more than changing the c->next dereference. You're now freeing it where you weren't before.

Previously, you freed it inside:
if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv))

    if(!c->idExists)

Now, you free it inside:
if (!c->idExists && !c->isCurrent)

So you're missing the check for (c->drawPriv == glxPriv || c->readPriv == glxPriv) ... is that intentional and we had a leak before, or are we now over-releasing?

Quoted 59 lines · Kristian Høgsberg

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

Kristian

glx/glxext.c | 11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -6
index e203156..f5ebe4f 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
    /* If this drawable was created using glx 1.3 drawable
     * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
    }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+	next = c->next;
 	if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
 	    int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 		    }
 		}
 	    }
-
-	    if (!c->idExists) {
-		__glXFreeContext(c);
-	    }
 	}
 	if (c->drawPriv == glxPriv)
 	    c->drawPriv = NULL;
 	if (c->readPriv == glxPriv)
 	    c->readPriv = NULL;
+	if (!c->idExists && !c->isCurrent)
+	    __glXFreeContext(c);
    }
 
    glxPriv->destroy(glxPriv);
Signature · 6 lines
1.7.3

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

A message that is not in the archive (sent off-list or not yet received): A7B70C84-4699-4A06-8769-6195E3B8A631-2kanFRK1NckAvxtiuMwx3w@public.gmane.org

#8 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

2010/9/23 Jeremy Huddleston <[email protected]>:

Quoted 10 lines

That seems off to me.  This is doing more than changing the c->next dereference.  You're now freeing it where you weren't before.

Previously, you freed it inside:
if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) if(!c->idExists)

Now, you free it inside:
if (!c->idExists && !c->isCurrent)

So you're missing the check for (c->drawPriv == glxPriv || c->readPriv == glxPriv) ... is that intentional and we had a leak before, or are we now over-releasing?

All the contexts on the context list have either idExists or isCurrent or both true, otherwise we would have already destroyed them. If a context that was current is destroyed, we set idExists to NULL (it no longer has an XID) but keep it around while it's still current. If the context is not current, we just destroy it right away and take it out of the list.

The loop above, iterates through the list of all contexts to see if there is a context that has been destroyed but is still current with the drawable that we're getting the DrawableGone() callback for. We treat that as an unbind, which triggers the context destruction. As Jon mentions, that may not be the right thing to do, but in the scope of this patch, we're just delaying the destroy until we're done touching the context.

Kristian

Quoted 53 lines · Kristian Høgsberg
Quoted 52 lines

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

Kristian

glx/glxext.c |   11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -6
index e203156..f5ebe4f 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
           FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+     next = c->next;
       if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
           int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
                   }
               }
           }
-
-         if (!c->idExists) {
-             __glXFreeContext(c);
-         }
       }
       if (c->drawPriv == glxPriv)
           c->drawPriv = NULL;
       if (c->readPriv == glxPriv)
           c->readPriv = NULL;
+     if (!c->idExists && !c->isCurrent)
+         __glXFreeContext(c);
     }
 
Quoted 10 lines
Quoted 8 lines
glx/glxext.c +0 -1
     glxPriv->destroy(glxPriv);
--

1.7.3

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#9 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

2010/9/23 Kristian Høgsberg <[email protected]>:

Quoted 19 lines

2010/9/23 Jeremy Huddleston <[email protected]>:

Quoted 10 lines

That seems off to me.  This is doing more than changing the c->next dereference.  You're now freeing it where you weren't before.

Previously, you freed it inside:
if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) if(!c->idExists)

Now, you free it inside:
if (!c->idExists && !c->isCurrent)

So you're missing the check for (c->drawPriv == glxPriv || c->readPriv == glxPriv) ... is that intentional and we had a leak before, or are we now over-releasing?

All the contexts on the context list have either idExists or isCurrent or both true, otherwise we would have already destroyed them.  If a context that was current is destroyed, we set idExists to NULL (it no longer has an XID) but keep it around while it's still current.  If the context is not current, we just destroy it right away and take it out of the list.

Quoted 7 lines

The loop above, iterates through the list of all contexts to see if there is a context that has been destroyed but is still current with the drawable that we're getting the DrawableGone() callback for.  We treat that as an unbind, which triggers the context destruction.  As Jon mentions, that may not be the right thing to do, but in the scope of this patch, we're just delaying the destroy until we're done touching the context.

Jeremy, does the above explanation satisfy your concerns? Keith, do you want to pick this up for master?

Quoted 57 lines
Quoted 57 lines · Kristian Høgsberg
Quoted 56 lines

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

Kristian

glx/glxext.c |   11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -7
index e203156..f5ebe4f 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
           FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+     next = c->next;
       if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
           int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
                   }
               }
           }
-
-         if (!c->idExists) {
-             __glXFreeContext(c);
-         }
       }
       if (c->drawPriv == glxPriv)
           c->drawPriv = NULL;
       if (c->readPriv == glxPriv)
           c->readPriv = NULL;
+     if (!c->idExists && !c->isCurrent)
+         __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
--

1.7.3

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

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

A message that is not in the archive (sent off-list or not yet received): AANLkTimm9mbEHgzmKr7xNm3HSfUyfnoZ2OFe_RTDoPF6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

On Sep 27, 2010, at 05:42, Kristian Høgsberg wrote:
...

Quoted 2 lines

Jeremy, does the above explanation satisfy your concerns? Keith, do you want to pick this up for master?

Yes, thanks.

Quoted 58 lines
Quoted 58 lines
Quoted 58 lines · Kristian Høgsberg
Quoted 56 lines

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

Kristian

glx/glxext.c | 11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -7
index e203156..f5ebe4f 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *next;
 
    /* If this drawable was created using glx 1.3 drawable
     * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
          FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
    }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = next) {
+     next = c->next;
      if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
          int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
                  }
              }
          }
-
-         if (!c->idExists) {
-             __glXFreeContext(c);
-         }
      }
      if (c->drawPriv == glxPriv)
          c->drawPriv = NULL;
      if (c->readPriv == glxPriv)
          c->readPriv = NULL;
+     if (!c->idExists && !c->isCurrent)
+         __glXFreeContext(c);
    }
 
    glxPriv->destroy(glxPriv);
--

1.7.3

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#12 lore raw

Re: [PATCH v2] glx: Fix use after free in DrawableGone

In reply to a message not in the archive
Quoted 5 lines · Kristian Høgsberg

---

Chris Wilson points out that we were still accessing c->next after free. Here's an updated version that fixes that.

I've merged this patch (and attempted to collect all of the *-by:
lines). I liked 'next' better than 'tmp' as a name, so Kristian ends up with the credit.

Signature · 1 line
[email protected]

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

A message that is not in the archive (sent off-list or not yet received): 1285156047-21138-1-git-send-email-jcristau-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org

#14 lore raw

PATCH 1/1 glx: Avoid use-after-free after drawableGone

Becareful during list processing to keep valgrind quiet:

==2989== Invalid read of size 4

==2989==    at 0x48CE6B5: DrawableGone (glxext.c:168)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
==2989==  Address 0x55a9c1c is 76 bytes inside a block of size 88 free'd
==2989==    at 0x4023B6A: free (vg_replace_malloc.c:366)
==2989==    by 0x48D9DD8: __glXDRIcontextDestroy (glxdri2.c:250)
==2989==    by 0x48CE1A0: __glXFreeContext (glxext.c:222)
==2989==    by 0x48CE786: DrawableGone (glxext.c:165)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
---
 glx/glxext.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -6
index e203156..69ed24e 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
 */
 static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
-    __GLXcontext *c;
+    __GLXcontext *c, *tmp;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = tmp) {
+	tmp = c->next;
 	if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
 	    int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 		    }
 		}
 	    }
-
-	    if (!c->idExists) {
-		__glXFreeContext(c);
-	    }
 	}
 	if (c->drawPriv == glxPriv)
 	    c->drawPriv = NULL;
 	if (c->readPriv == glxPriv)
 	    c->readPriv = NULL;
+	if (!c->idExists)
+	    __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
Signature · 6 lines
1.7.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

A message that is not in the archive (sent off-list or not yet received): 1285158749-9056-1-git-send-email-chris-Y6uKTt2uX1cEflXRtASbqLVCufUGDwFn@public.gmane.org

Reviewed-by Jamey Sharp
#16 lore raw

Re: [PATCH] glx: Avoid use-after-free after drawableGone

I don't know the code, but this looks pretty obvious.

Quoted 69 lines · Chris Wilson

Becareful during list processing to keep valgrind quiet:

==2989== Invalid read of size 4
==2989==    at 0x48CE6B5: DrawableGone (glxext.c:168) ==2989==    by 0x809F401: FreeResource (resource.c:601) ==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733) ==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
==2989==  Address 0x55a9c1c is 76 bytes inside a block of size 88 free'd ==2989==    at 0x4023B6A: free (vg_replace_malloc.c:366) ==2989==    by 0x48D9DD8: __glXDRIcontextDestroy (glxdri2.c:250) ==2989==    by 0x48CE1A0: __glXFreeContext (glxext.c:222) ==2989==    by 0x48CE786: DrawableGone (glxext.c:165) ==2989==    by 0x809F401: FreeResource (resource.c:601) ==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733) ==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)

---
 glx/glxext.c |   11 +++++------

 1 files changed, 5 insertions(+), 6 deletions(-)
glx/glxext.c +5 -7
index e203156..69ed24e 100644
@@ -124,7 +124,7 @@ static int glxBlockClients;
  */
  static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
  {
-    __GLXcontext *c;
+    __GLXcontext *c, *tmp;
 
     /* If this drawable was created using glx 1.3 drawable
      * constructors, we added it as a glx drawable resource under both
@@ -137,7 +137,8 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
            FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
     }
 
-    for (c = glxAllContexts; c; c = c->next) {
+    for (c = glxAllContexts; c; c = tmp) {
+       tmp = c->next;
        if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
            int i;
 
@@ -160,15 +161,13 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
                    }
                }
            }
-
-           if (!c->idExists) {
-               __glXFreeContext(c);
-           }
        }
        if (c->drawPriv == glxPriv)
            c->drawPriv = NULL;
        if (c->readPriv == glxPriv)
            c->readPriv = NULL;
+       if (!c->idExists)
+           __glXFreeContext(c);
     }
 
     glxPriv->destroy(glxPriv);
--

1.7.1

Quoted 4 lines

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reviewed-by
#17 lore raw

Re: [PATCH] glx: Avoid use-after-free after drawableGone

In reply to a message not in the archive
Quoted 18 lines · Chris Wilson

Becareful during list processing to keep valgrind quiet:

==2989== Invalid read of size 4

==2989==    at 0x48CE6B5: DrawableGone (glxext.c:168)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
==2989==  Address 0x55a9c1c is 76 bytes inside a block of size 88 free'd
==2989==    at 0x4023B6A: free (vg_replace_malloc.c:366)
==2989==    by 0x48D9DD8: __glXDRIcontextDestroy (glxdri2.c:250)
==2989==    by 0x48CE1A0: __glXFreeContext (glxext.c:222)
==2989==    by 0x48CE786: DrawableGone (glxext.c:165)
==2989==    by 0x809F401: FreeResource (resource.c:601)
==2989==    by 0x80845CE: ProcDestroyWindow (dispatch.c:733)
==2989==    by 0x8087D76: Dispatch (dispatch.c:432)
==2989==    by 0x8066439: main (main.c:291)
Quoted 3 lines
Cc Kristian Høgsberg <krh-1OA22m9ORUweIZ0/[email protected]>

- ajax

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#18 lore raw
In reply to Julien Cristau
Quoted 2 lines · Julien Cristau

Without this change, DRI2 gets enabled but doesn't work and glxinfo crashes my X server.

I think we need a bigger hammer than this.

The problem is that when we disable acceleration (EIO returned from execbuffer), the same thing happens. I think a fix for this should also deal with that case. Probably something conditional on the force_fallback member at dri2 time... (we can disallow dri2 connections, right?)

No patch from me yet, but I am thinking about it.

-0-

Signature · 2 lines
Hartley's Second Law:
	Never sleep with anyone crazier than yourself.
#19 lore raw

Re: [PATCH] Disable DRI2 if we are running on shadowfb

Quoted 11 lines · Owain Ainsworth
Quoted 2 lines · Julien Cristau

Without this change, DRI2 gets enabled but doesn't work and glxinfo crashes my X server.

I think we need a bigger hammer than this.

The problem is that when we disable acceleration (EIO returned from execbuffer), the same thing happens. I think a fix for this should also deal with that case. Probably something conditional on the force_fallback member at dri2 time... (we can disallow dri2 connections, right?)

This is what we get at the moment by returning buffers with name == 0 to the client. Just we still appear to be exercising what were rarely tested error paths...
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre