diff options
| author | Vijay Anusuri <vanusuri@mvista.com> | 2025-03-04 17:49:09 +0530 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2025-03-08 06:35:36 -0800 |
| commit | 46014acb66ba42f9c20f31df70f291273b9faf89 (patch) | |
| tree | 350077ad839ec3d9d9e8e70435fe06761af2dc2e | |
| parent | 57a80e447e73eb1e5c735e24e92205ba40f8a6e5 (diff) | |
| download | poky-46014acb66ba42f9c20f31df70f291273b9faf89.tar.gz | |
xwayland: Fix CVE-2024-31083
The patches are copied from xserver-xorg recipe.
CVE reported for both and patches apply on both.
Upstream-Commit:
https://gitlab.freedesktop.org/xorg/xserver/-/commit/bdca6c3d1f5057ee & https://gitlab.freedesktop.org/xorg/xserver/-/commit/337d8d48b618d4fc
(From OE-Core rev: 1c4b1e7877210243707a91d6a9d37ed4546bc8a7)
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
3 files changed, 197 insertions, 0 deletions
diff --git a/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0001.patch b/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0001.patch new file mode 100644 index 0000000000..754e03961a --- /dev/null +++ b/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0001.patch | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | From bdca6c3d1f5057eeb31609b1280fc93237b00c77 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Peter Hutterer <peter.hutterer@who-t.net> | ||
| 3 | Date: Tue, 30 Jan 2024 13:13:35 +1000 | ||
| 4 | Subject: [PATCH] render: fix refcounting of glyphs during ProcRenderAddGlyphs | ||
| 5 | |||
| 6 | Previously, AllocateGlyph would return a new glyph with refcount=0 and a | ||
| 7 | re-used glyph would end up not changing the refcount at all. The | ||
| 8 | resulting glyph_new array would thus have multiple entries pointing to | ||
| 9 | the same non-refcounted glyphs. | ||
| 10 | |||
| 11 | AddGlyph may free a glyph, resulting in a UAF when the same glyph | ||
| 12 | pointer is then later used. | ||
| 13 | |||
| 14 | Fix this by returning a refcount of 1 for a new glyph and always | ||
| 15 | incrementing the refcount for a re-used glyph, followed by dropping that | ||
| 16 | refcount back down again when we're done with it. | ||
| 17 | |||
| 18 | CVE-2024-31083, ZDI-CAN-22880 | ||
| 19 | |||
| 20 | This vulnerability was discovered by: | ||
| 21 | Jan-Niklas Sohn working with Trend Micro Zero Day Initiative | ||
| 22 | |||
| 23 | Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1463> | ||
| 24 | |||
| 25 | CVE: CVE-2024-31083 | ||
| 26 | |||
| 27 | Upstream-Status: Backport [https://gitlab.freedesktop.org/xorg/xserver/-/commit/bdca6c3d1f5057ee] | ||
| 28 | |||
| 29 | Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com> | ||
| 30 | Signed-off-by: Vijay Anusuri <vanusuri@mvista.com> | ||
| 31 | --- | ||
| 32 | render/glyph.c | 5 +++-- | ||
| 33 | render/glyphstr.h | 2 ++ | ||
| 34 | render/render.c | 15 +++++++++++---- | ||
| 35 | 3 files changed, 16 insertions(+), 6 deletions(-) | ||
| 36 | |||
| 37 | diff --git a/render/glyph.c b/render/glyph.c | ||
| 38 | index f3ed9cf..d5fc5f3 100644 | ||
| 39 | --- a/render/glyph.c | ||
| 40 | +++ b/render/glyph.c | ||
| 41 | @@ -245,10 +245,11 @@ FreeGlyphPicture(GlyphPtr glyph) | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | -static void | ||
| 46 | +void | ||
| 47 | FreeGlyph(GlyphPtr glyph, int format) | ||
| 48 | { | ||
| 49 | CheckDuplicates(&globalGlyphs[format], "FreeGlyph"); | ||
| 50 | + BUG_RETURN(glyph->refcnt == 0); | ||
| 51 | if (--glyph->refcnt == 0) { | ||
| 52 | GlyphRefPtr gr; | ||
| 53 | int i; | ||
| 54 | @@ -354,7 +355,7 @@ AllocateGlyph(xGlyphInfo * gi, int fdepth) | ||
| 55 | glyph = (GlyphPtr) malloc(size); | ||
| 56 | if (!glyph) | ||
| 57 | return 0; | ||
| 58 | - glyph->refcnt = 0; | ||
| 59 | + glyph->refcnt = 1; | ||
| 60 | glyph->size = size + sizeof(xGlyphInfo); | ||
| 61 | glyph->info = *gi; | ||
| 62 | dixInitPrivates(glyph, (char *) glyph + head_size, PRIVATE_GLYPH); | ||
| 63 | diff --git a/render/glyphstr.h b/render/glyphstr.h | ||
| 64 | index 2f51bd2..68f8c9e 100644 | ||
| 65 | --- a/render/glyphstr.h | ||
| 66 | +++ b/render/glyphstr.h | ||
| 67 | @@ -117,6 +117,8 @@ extern GlyphSetPtr AllocateGlyphSet(int fdepth, PictFormatPtr format); | ||
| 68 | extern int | ||
| 69 | FreeGlyphSet(void *value, XID gid); | ||
| 70 | |||
| 71 | +void FreeGlyph(GlyphPtr glyph, int format); | ||
| 72 | + | ||
| 73 | #define GLYPH_HAS_GLYPH_PICTURE_ACCESSOR 1 /* used for api compat */ | ||
| 74 | extern _X_EXPORT PicturePtr | ||
| 75 | GetGlyphPicture(GlyphPtr glyph, ScreenPtr pScreen); | ||
| 76 | diff --git a/render/render.c b/render/render.c | ||
| 77 | index 456f156..5bc2a20 100644 | ||
| 78 | --- a/render/render.c | ||
| 79 | +++ b/render/render.c | ||
| 80 | @@ -1076,6 +1076,7 @@ ProcRenderAddGlyphs(ClientPtr client) | ||
| 81 | |||
| 82 | if (glyph_new->glyph && glyph_new->glyph != DeletedGlyph) { | ||
| 83 | glyph_new->found = TRUE; | ||
| 84 | + ++glyph_new->glyph->refcnt; | ||
| 85 | } | ||
| 86 | else { | ||
| 87 | GlyphPtr glyph; | ||
| 88 | @@ -1168,8 +1169,10 @@ ProcRenderAddGlyphs(ClientPtr client) | ||
| 89 | err = BadAlloc; | ||
| 90 | goto bail; | ||
| 91 | } | ||
| 92 | - for (i = 0; i < nglyphs; i++) | ||
| 93 | + for (i = 0; i < nglyphs; i++) { | ||
| 94 | AddGlyph(glyphSet, glyphs[i].glyph, glyphs[i].id); | ||
| 95 | + FreeGlyph(glyphs[i].glyph, glyphSet->fdepth); | ||
| 96 | + } | ||
| 97 | |||
| 98 | if (glyphsBase != glyphsLocal) | ||
| 99 | free(glyphsBase); | ||
| 100 | @@ -1179,9 +1182,13 @@ ProcRenderAddGlyphs(ClientPtr client) | ||
| 101 | FreePicture((void *) pSrc, 0); | ||
| 102 | if (pSrcPix) | ||
| 103 | FreeScratchPixmapHeader(pSrcPix); | ||
| 104 | - for (i = 0; i < nglyphs; i++) | ||
| 105 | - if (glyphs[i].glyph && !glyphs[i].found) | ||
| 106 | - free(glyphs[i].glyph); | ||
| 107 | + for (i = 0; i < nglyphs; i++) { | ||
| 108 | + if (glyphs[i].glyph) { | ||
| 109 | + --glyphs[i].glyph->refcnt; | ||
| 110 | + if (!glyphs[i].found) | ||
| 111 | + free(glyphs[i].glyph); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | if (glyphsBase != glyphsLocal) | ||
| 115 | free(glyphsBase); | ||
| 116 | return err; | ||
| 117 | -- | ||
| 118 | 2.40.0 | ||
diff --git a/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0002.patch b/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0002.patch new file mode 100644 index 0000000000..c597e9b575 --- /dev/null +++ b/meta/recipes-graphics/xwayland/xwayland/CVE-2024-31083-0002.patch | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | From 337d8d48b618d4fc0168a7b978be4c3447650b04 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Olivier Fourdan <ofourdan@redhat.com> | ||
| 3 | Date: Fri, 5 Apr 2024 15:24:49 +0200 | ||
| 4 | Subject: [PATCH] render: Avoid possible double-free in ProcRenderAddGlyphs() | ||
| 5 | ProcRenderAddGlyphs() adds the glyph to the glyphset using AddGlyph() and | ||
| 6 | then frees it using FreeGlyph() to decrease the reference count, after | ||
| 7 | AddGlyph() has increased it. | ||
| 8 | |||
| 9 | AddGlyph() however may chose to reuse an existing glyph if it's already | ||
| 10 | in the glyphSet, and free the glyph that was given, in which case the | ||
| 11 | caller function, ProcRenderAddGlyphs() will call FreeGlyph() on an | ||
| 12 | already freed glyph, as reported by ASan: | ||
| 13 | |||
| 14 | READ of size 4 thread T0 | ||
| 15 | #0 in FreeGlyph xserver/render/glyph.c:252 | ||
| 16 | #1 in ProcRenderAddGlyphs xserver/render/render.c:1174 | ||
| 17 | #2 in Dispatch xserver/dix/dispatch.c:546 | ||
| 18 | #3 in dix_main xserver/dix/main.c:271 | ||
| 19 | #4 in main xserver/dix/stubmain.c:34 | ||
| 20 | #5 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 | ||
| 21 | #6 in __libc_start_main_impl ../csu/libc-start.c:360 | ||
| 22 | #7 (/usr/bin/Xwayland+0x44fe4) | ||
| 23 | Address is located 0 bytes inside of 64-byte region | ||
| 24 | freed by thread T0 here: | ||
| 25 | #0 in __interceptor_free libsanitizer/asan/asan_malloc_linux.cpp:52 | ||
| 26 | #1 in _dixFreeObjectWithPrivates xserver/dix/privates.c:538 | ||
| 27 | #2 in AddGlyph xserver/render/glyph.c:295 | ||
| 28 | #3 in ProcRenderAddGlyphs xserver/render/render.c:1173 | ||
| 29 | #4 in Dispatch xserver/dix/dispatch.c:546 | ||
| 30 | #5 in dix_main xserver/dix/main.c:271 | ||
| 31 | #6 in main xserver/dix/stubmain.c:34 | ||
| 32 | #7 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 | ||
| 33 | previously allocated by thread T0 here: | ||
| 34 | #0 in __interceptor_malloc libsanitizer/asan/asan_malloc_linux.cpp:69 | ||
| 35 | #1 in AllocateGlyph xserver/render/glyph.c:355 | ||
| 36 | #2 in ProcRenderAddGlyphs xserver/render/render.c:1085 | ||
| 37 | #3 in Dispatch xserver/dix/dispatch.c:546 | ||
| 38 | #4 in dix_main xserver/dix/main.c:271 | ||
| 39 | #5 in main xserver/dix/stubmain.c:34 | ||
| 40 | #6 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 | ||
| 41 | SUMMARY: AddressSanitizer: heap-use-after-free xserver/render/glyph.c:252 in FreeGlyph | ||
| 42 | |||
| 43 | To avoid that, make sure not to free the given glyph in AddGlyph(). | ||
| 44 | |||
| 45 | v2: Simplify the test using the boolean returned from AddGlyph() (Michel) | ||
| 46 | v3: Simplify even more by not freeing the glyph in AddGlyph() (Peter) | ||
| 47 | |||
| 48 | Fixes: bdca6c3d1 - render: fix refcounting of glyphs during ProcRenderAddGlyphs | ||
| 49 | Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1659 | ||
| 50 | Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> | ||
| 51 | Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1476> | ||
| 52 | |||
| 53 | CVE: CVE-2024-31083 | ||
| 54 | |||
| 55 | Upstream-Status: Backport [https://gitlab.freedesktop.org/xorg/xserver/-/commit/337d8d48b618d4fc] | ||
| 56 | |||
| 57 | Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com> | ||
| 58 | Signed-off-by: Vijay Anusuri <vanusuri@mvista.com> | ||
| 59 | --- | ||
| 60 | render/glyph.c | 2 -- | ||
| 61 | 1 file changed, 2 deletions(-) | ||
| 62 | |||
| 63 | diff --git a/render/glyph.c b/render/glyph.c | ||
| 64 | index d5fc5f3..f5069d4 100644 | ||
| 65 | --- a/render/glyph.c | ||
| 66 | +++ b/render/glyph.c | ||
| 67 | @@ -291,8 +291,6 @@ AddGlyph(GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) | ||
| 68 | gr = FindGlyphRef(&globalGlyphs[glyphSet->fdepth], signature, | ||
| 69 | TRUE, glyph->sha1); | ||
| 70 | if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph) { | ||
| 71 | - FreeGlyphPicture(glyph); | ||
| 72 | - dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH); | ||
| 73 | glyph = gr->glyph; | ||
| 74 | } | ||
| 75 | else if (gr->glyph != glyph) { | ||
| 76 | -- | ||
| 77 | 2.40.0 | ||
diff --git a/meta/recipes-graphics/xwayland/xwayland_22.1.8.bb b/meta/recipes-graphics/xwayland/xwayland_22.1.8.bb index 5fa2402234..258a875697 100644 --- a/meta/recipes-graphics/xwayland/xwayland_22.1.8.bb +++ b/meta/recipes-graphics/xwayland/xwayland_22.1.8.bb | |||
| @@ -26,6 +26,8 @@ SRC_URI = "https://www.x.org/archive/individual/xserver/xwayland-${PV}.tar.xz \ | |||
| 26 | file://CVE-2024-21886-2.patch \ | 26 | file://CVE-2024-21886-2.patch \ |
| 27 | file://CVE-2024-31080.patch \ | 27 | file://CVE-2024-31080.patch \ |
| 28 | file://CVE-2024-31081.patch \ | 28 | file://CVE-2024-31081.patch \ |
| 29 | file://CVE-2024-31083-0001.patch \ | ||
| 30 | file://CVE-2024-31083-0002.patch \ | ||
| 29 | " | 31 | " |
| 30 | SRC_URI[sha256sum] = "d11eeee73290b88ea8da42a7d9350dedfaba856ce4ae44e58c045ad9ecaa2f73" | 32 | SRC_URI[sha256sum] = "d11eeee73290b88ea8da42a7d9350dedfaba856ce4ae44e58c045ad9ecaa2f73" |
| 31 | 33 | ||
