Blame SOURCES/0001-render-Avoid-possible-double-free-in-ProcRenderAddGl.patch

191e41
From 337d8d48b618d4fc0168a7b978be4c3447650b04 Mon Sep 17 00:00:00 2001
191e41
From: Olivier Fourdan <ofourdan@redhat.com>
191e41
Date: Fri, 5 Apr 2024 15:24:49 +0200
191e41
Subject: [PATCH] render: Avoid possible double-free in ProcRenderAddGlyphs()
191e41
191e41
ProcRenderAddGlyphs() adds the glyph to the glyphset using AddGlyph() and
191e41
then frees it using FreeGlyph() to decrease the reference count, after
191e41
AddGlyph() has increased it.
191e41
191e41
AddGlyph() however may chose to reuse an existing glyph if it's already
191e41
in the glyphSet, and free the glyph that was given, in which case the
191e41
caller function, ProcRenderAddGlyphs() will call FreeGlyph() on an
191e41
already freed glyph, as reported by ASan:
191e41
191e41
  READ of size 4 thread T0
191e41
    #0 in FreeGlyph xserver/render/glyph.c:252
191e41
    #1 in ProcRenderAddGlyphs xserver/render/render.c:1174
191e41
    #2 in Dispatch xserver/dix/dispatch.c:546
191e41
    #3 in dix_main xserver/dix/main.c:271
191e41
    #4 in main xserver/dix/stubmain.c:34
191e41
    #5 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
191e41
    #6 in __libc_start_main_impl ../csu/libc-start.c:360
191e41
    #7  (/usr/bin/Xwayland+0x44fe4)
191e41
  Address is located 0 bytes inside of 64-byte region
191e41
  freed by thread T0 here:
191e41
    #0 in __interceptor_free libsanitizer/asan/asan_malloc_linux.cpp:52
191e41
    #1 in _dixFreeObjectWithPrivates xserver/dix/privates.c:538
191e41
    #2 in AddGlyph xserver/render/glyph.c:295
191e41
    #3 in ProcRenderAddGlyphs xserver/render/render.c:1173
191e41
    #4 in Dispatch xserver/dix/dispatch.c:546
191e41
    #5 in dix_main xserver/dix/main.c:271
191e41
    #6 in main xserver/dix/stubmain.c:34
191e41
    #7 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
191e41
  previously allocated by thread T0 here:
191e41
    #0 in __interceptor_malloc libsanitizer/asan/asan_malloc_linux.cpp:69
191e41
    #1 in AllocateGlyph xserver/render/glyph.c:355
191e41
    #2 in ProcRenderAddGlyphs xserver/render/render.c:1085
191e41
    #3 in Dispatch xserver/dix/dispatch.c:546
191e41
    #4 in dix_main xserver/dix/main.c:271
191e41
    #5 in main xserver/dix/stubmain.c:34
191e41
    #6 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
191e41
  SUMMARY: AddressSanitizer: heap-use-after-free xserver/render/glyph.c:252 in FreeGlyph
191e41
191e41
To avoid that, make sure not to free the given glyph in AddGlyph().
191e41
191e41
v2: Simplify the test using the boolean returned from AddGlyph() (Michel)
191e41
v3: Simplify even more by not freeing the glyph in AddGlyph() (Peter)
191e41
191e41
Fixes: bdca6c3d1 - render: fix refcounting of glyphs during ProcRenderAddGlyphs
191e41
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1659
191e41
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
191e41
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1476>
191e41
---
191e41
 render/glyph.c | 2 --
191e41
 1 file changed, 2 deletions(-)
191e41
191e41
diff --git a/render/glyph.c b/render/glyph.c
191e41
index 13991f8a1..5fa7f3b5b 100644
191e41
--- a/render/glyph.c
191e41
+++ b/render/glyph.c
191e41
@@ -291,8 +291,6 @@ AddGlyph(GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
191e41
     gr = FindGlyphRef(&globalGlyphs[glyphSet->fdepth], signature,
191e41
                       TRUE, glyph->sha1);
191e41
     if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph) {
191e41
-        FreeGlyphPicture(glyph);
191e41
-        dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
191e41
         glyph = gr->glyph;
191e41
     }
191e41
     else if (gr->glyph != glyph) {
191e41
-- 
191e41
2.44.0
191e41