*nix libX11: Uncovering and exploiting a 35-year-old vulnerability – Part 2 of 2
A heap-based buffer overflow in libX11's XCreateImage function, triggered by parsing a malformed XPM image, allows an attacker to overwrite heap memory and potentially achieve remote code execution. The vulnerability was fixed in libX11 version 1.8.7.
Published on jfrog.com
The JFrog Security research team has recently discovered two security vulnerabilities in X.Org libX11, the widely popular graphics library – CVE-2023-43786 and CVE-2023-43787 (with a high NVD severity CVSS 7.8). These vulnerabilities cause a denial-of-service and remote code execution.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the integer overflow in the calculation of bytes_per_line in XCreateImage due to lack of validation on the image width, leading to a smaller allocation than required.
Impact
An attacker could achieve remote code execution by tricking a victim into opening a malicious XPM file with a vulnerable application, though the blog demonstrates code execution only on a 32-bit Debian system and notes that 64-bit exploitation would require more research.
What the attacker needed
Victim opens a malicious XPM file; application uses vulnerable libXPM
The fix
The vulnerability was fixed in libX11 version 1.8.7 by adding validation to prevent the integer overflow.
How it was found
- Craft an XPM image with a very large width value in its header.
- Open the malicious XPM file with a vulnerable application such as sxpm.
- The application parses the XPM file, triggering the overflow in XCreateImage.
- The overflow corrupts heap memory, potentially allowing control of execution flow.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When a program reads an image file, it calculates how much memory to set aside for the image data. If the image's width is extremely large, that calculation can wrap around and produce a much smaller number than needed. The program then writes the image data into that too-small space, overflowing into adjacent memory. An attacker can craft a malicious image file to control what gets overwritten, potentially leading to code execution.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.