GHSL-2020-064: integer overflow in LibVNCClient HandleCursorShape resulting in remote heap overflow - CVE-2019-20788
An integer overflow in the HandleCursorShape function of libvncclient allows a malicious VNC server to under-allocate a heap buffer and then write beyond it, potentially leading to remote code execution. The issue was fixed in version 0.9.13.
Originally disclosed on GitHub Security Lab
There exists an integer overflow in HandleCursorShape RFB event handler in libvncclient, which is the client implementation for LibVNC included with libvncserver.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The allocation size is computed as width * height * bytesPerPixel using 32-bit integer arithmetic, which can overflow and result in a smaller allocation than needed.
Impact
A malicious VNC server could trigger a remote heap overflow in a connecting client, which may lead to remote code execution, though the authors consider this unlikely due to limited control over the overflow.
What the attacker needed
Victim connects to a malicious VNC server
The fix
The issue was fixed in libvncclient 0.9.13.
How it was found
- A malicious VNC server sends a framebuffer update message with a rectangle encoding set to rfbEncodingXCursor or rfbEncodingRichCursor.
- The server controls the width and height values (up to 16 bits each) and the bits-per-pixel setting, which determines bytesPerPixel.
- The client calls HandleCursorShape with these values, and the multiplication width * height * bytesPerPixel overflows, causing malloc to allocate a smaller buffer than intended.
- The client then reads pixel data from the server and writes it into the undersized buffer, causing a heap overflow.
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 report has not been written yet. The Original tab links to the source.
When a VNC client connects to a server, the server can send cursor images. The client calculates how much memory to reserve for the image using numbers from the server. If those numbers are large, the calculation can wrap around to a small value, so the client reserves too little memory. Then it writes the image data into that small buffer, overflowing it and potentially letting the attacker run code on the client machine.
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.