From a569eb4f36ed96a9e445ececd7e8d98c223461a0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 29 Apr 2026 05:40:33 +0000 Subject: [PATCH] dix: increase XLFDMAXFONTNAMELEN to match libXfont2's MAXFONTNAMELEN XLFDMAXFONTNAMELEN was 256 bytes, but libXfont2 defines MAXFONTNAMELEN as 1024 and allows font names and alias targets up to that length in fonts.alias files. doListFontsAndAliases copies the resolved alias target into a stack-allocated tmp_pattern[XLFDMAXFONTNAMELEN] and then into c->current.pattern[XLFDMAXFONTNAMELEN] (defined in LFWIstateRec). doListFontsWithInfo has the same pattern, copying the resolved name into c->current.pattern[]. With the old 256-byte limit, a fonts.alias entry with a target name between 257 and 1023 bytes would overflow both buffers. An attacker can exploit this by: 1. Creating a font directory with a fonts.alias containing an alias whose target name exceeds 256 bytes 2. Using SetFontPath to add the malicious directory 3. Calling ListFonts with the alias name to trigger alias resolution 4. The oversized resolved name overflows the 256-byte stack buffer Increase XLFDMAXFONTNAMELEN from 256 to 1024 to match libXfont2's MAXFONTNAMELEN, ensuring the server can handle any name the font library produces. This vulnerability was discovered by: Anonymous working with TrendAI Zero Day Initiative ZDI-CAN-30136 Assisted-by: Claude:claude-opus-4-6 (cherry picked from commit bb5158f962dc935e58ef8b4b5fcb31be201a6e07) Part-of: --- dix/dixfonts.c | 8 ++++++++ include/closestr.h | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dix/dixfonts.c b/dix/dixfonts.c index 0366f282f..2c877dfb3 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -670,6 +670,10 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) * is BadFontName, indicating the alias resolution * is complete. */ + if (resolvedlen > XLFDMAXFONTNAMELEN) { + err = BadFontName; + goto ContBadFontName; + } memmove(tmp_pattern, resolved, resolvedlen); if (c->haveSaved) { char *tmpname; @@ -932,6 +936,10 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) memcpy(c->savedName, name, namelen + 1); aliascount = 20; } + if (namelen > XLFDMAXFONTNAMELEN) { + err = BadFontName; + goto ContBadFontName; + } memmove(c->current.pattern, name, namelen); c->current.patlen = namelen; c->current.max_names = 1; diff --git a/include/closestr.h b/include/closestr.h index 60e6f09bc..7567ac6ea 100644 --- a/include/closestr.h +++ b/include/closestr.h @@ -57,7 +57,12 @@ typedef struct _OFclosure { /* ListFontsWithInfo */ -#define XLFDMAXFONTNAMELEN 256 +/* libXfont2 allows font names/aliases up to MAXFONTNAMELEN (1024) bytes in + * fonts.alias files. The server's pattern buffers must be large enough to + * hold resolved alias targets returned by the font library. + * ZDI-CAN-30136 + */ +#define XLFDMAXFONTNAMELEN 1024 typedef struct _LFWIstate { char pattern[XLFDMAXFONTNAMELEN]; int patlen;