Feeds

Anatomy of a 22-year-old X Window bug: Get root with newly uncovered flaw

Grab a patch today if you share your Unix-flavoured desktop with other people

Protecting against web application threats using SSL

The X Window System, which today underpins Linux desktops the world over, has been around for more than two decades – and so have its bugs.

Sysadmins have a few days to patch libXfont to remove a newly discovered, 22-year-old privilege-escalation bug in the code before any tiresome users whip out an exploit. The flaw allows someone logged into a vulnerable machine to crash the X server, or possibly execute injected code as a superuser.

Hard on the heels of a Chaos Communication Congress presentation that found “hundreds” of bugs (discussed at the X.org mailing list here), the newly found bug is a textbook stack buffer overflow that dates back to 1991 – and is present in all versions of X11.

The bug is very straightforward, and will impact shared computers, but it is ideal to dissect to reveal how this sort of security blunder happens.

As the X.org advisory states: “A BDF font file containing a longer than expected string could overflow the buffer on the stack. Testing in X servers built with Stack Protector resulted in an immediate crash when reading a user-provided specially crafted font.”

The guilty party is this block of code in bdfReadCharacters() in libXfont/tree/src/bitmap/bdfread.c:

char charName[100];

if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {
   bdfError("bad character name in BDF file\n");
   goto BAILOUT; /* bottom of function, free and return error */
}

If you can't already see the bug then we'll explain. On-screen fonts can be stored in Glyph Bitmap Distribution Format (BDF) [PDF] files, which start with the following line to declare the format version the font is adhering to:

STARTCHAR 2.1

That's all well and good if the loaded font has a short version number, expressed as a string, which in this case is "2.1". That information is copied into the string variable charName by the sscanf() call in bdfread.c. The problem is, sscanf() is not told to limit the number of bytes read for the version number and will keep copying data from the file until it hits a white-space character.

The charName variable is declared as having a length of 100 bytes, so feeding it a crafted BDF font with a "STARTCHAR" version number longer than that will punch through the boundary of the variable's allotted space in memory and into other data on the stack. This means an attacker could overwrite the memory that controls the processor's instruction pointer on leaving the bdfReadCharacters() function, effectively hijacking the program.

And since the X server is usually run with superuser privileges, the normal user can start running code to take control of the machine if the attack is successful. Much more in-depth explanations on how stack buffer overflows can be exploited, despite some of the protections in place on modern systems, can be found here and here.

The fix for the bug is simple; you simply tell sscanf() to read at most 99 bytes, leaving one for the terminating NULL:

if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) {

As the X.org announcement states:

As libXfont is used to read user-specified font files in all X servers distributed by X.Org, including the Xorg server which is often run with root privileges or as setuid-root in order to access hardware, this bug may lead to an unprivileged user acquiring root privileges in some systems.

In the December Chaos Communication Congress presentation, Ilja van Sprundel said he'd able to find 120 bugs in a couple of months, “and I'm not close to done”. Van Sprundel had already triggered a major X.org security update in May 2013, with tens of fixes needed because client libraries trusted servers to send valid data, and not sanity-tested what was sent.

The latest bug, discovered using the cppcheck static analyzer, is designated CVE-2013-6462; security updates should be available from all good package managers and repositories. ®

Reducing the cost and complexity of web vulnerability management

More from The Register

next story
Early result from Scots indyref vote? NAW, Jimmy - it's a SCAM
Anyone claiming to know before tomorrow is telling porkies
TOR users become FBI's No.1 hacking target after legal power grab
Be afeared, me hearties, these scoundrels be spying our signals
Jihadi terrorists DIDN'T encrypt their comms 'cos of Snowden leaks
Intel bods' analysis concludes 'no significant change' after whistle was blown
Home Depot: 56 million bank cards pwned by malware in our tills
That's about 50 per cent bigger than the Target tills mega-hack
Hackers pop Brazil newspaper to root home routers
Step One: try default passwords. Step Two: Repeat Step One until success
NORKS ban Wi-Fi and satellite internet at embassies
Crackdown on tardy diplomatic sysadmins providing accidental unfiltered internet access
UK.gov lobs another fistful of change at SME infosec nightmares
Senior Lib Dem in 'trying to be relevant' shocker. It's only taxpayers' money, after all
Critical Adobe Reader and Acrobat patches FINALLY make it out
Eight vulns healed, including XSS and DoS paths
Spies would need SUPER POWERS to tap undersea cables
Why mess with armoured 10kV cables when land-based, and legal, snoop tools are easier?
prev story

Whitepapers

Secure remote control for conventional and virtual desktops
Balancing user privacy and privileged access, in accordance with compliance frameworks and legislation. Evaluating any potential remote control choice.
WIN a very cool portable ZX Spectrum
Win a one-off portable Spectrum built by legendary hardware hacker Ben Heck
Intelligent flash storage arrays
Tegile Intelligent Storage Arrays with IntelliFlash helps IT boost storage utilization and effciency while delivering unmatched storage savings and performance.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Beginner's guide to SSL certificates
De-mystify the technology involved and give you the information you need to make the best decision when considering your online security options.