[code] [blog] [Repos] [GPS Tracker] [Music] [VNC] [Restart VNC] [E-Mail me]
git clone https://coredump.ws/repos/x11vnc-fixes.git
# push (client certificate):
git remote set-url --push origin https://coredump.ws:8443/repos/x11vnc-fixes.git

Branches and tags

masterbranch22 days agozip

Files at HEAD (b85721b890) · download zip

overlay/
tests/
LICENSE34.3 KB
README.md27.5 KB

Recent commits · all

b85721b8README: show vnc_conn_rate with a timeoutno-body-in-particular22 days ago
4439308dRelicense under GPL-3.0-or-laterno-body-in-particular27 days ago
3c942bb9License under GPL-2.0no-body-in-particular28 days ago
b177c456x11vnc 0.9.17-r11, libvncserver 0.9.15-r10: CU stop-and-wait, resize hangno-body-in-particular2026-10-08
a2115124x11vnc 0.9.17-r10: resize deadlock, framebuffer races, stuck keys, 70 s TLS dropno-body-in-particular2026-10-08
a5530208x11vnc 0.9.17-r9, libvncserver 0.9.15-r9: performance releaseno-body-in-particular2026-10-08
6bbf8283x11vnc 0.9.17-r8, libvncserver 0.9.15-r8: pre/post-auth hunt fixesno-body-in-particular2026-10-08
3355e965libvncserver 0.9.15-r7: refuse WebSocket origins not in LIBVNCSERVER_WS_ORIGINSno-body-in-particular2026-10-08
d9dacd99x11vnc 0.9.17-r6, libvncserver 0.9.15-r6: lifetime races, main-loop stalls, SIGTERMno-body-in-particular2026-10-07
33b20decx11vnc 0.9.17-r5, libvncserver 0.9.15-r5: resize and scaled-screen fixesno-body-in-particular2026-10-07

README.md

x11vnc-fixes

Fixes and a Gentoo ebuild for x11vnc 0.9.17, as run behind NoVNCAudio on coredump.ws: -ssl with -sslverify client certificates as the only authentication, on a port open to the internet. Everything here also applies to an x11vnc that serves anything else over -ssl.

It also carries fixes for libvncserver 0.9.15, the library x11vnc serves clients with. x11vnc has had no release since 0.9.17 (2025-04-11), libvncserver none since 0.9.15, and none of this is upstream yet.

What it changes

Patches (overlay/x11-misc/x11vnc/files/, against 0.9.17):

PatchFix
0001 configureCarried from ::gentoo (x11vnc#268): drop AC_FUNC_STAT, which breaks with -Werror=implicit-function-declaration.
0002 copy_tilescopy_tiles() narrowed a changed tile's update rectangle to the columns that differ, but scanned after the memcpy() that had made old and new identical, so the narrowing never happened. The scan now runs first, with an SSE2/word-wise byte scan instead of a memcmp() per pixel. On a scrolling 2px-wide line, incremental traffic drops from 552,961 to 34,561 pixels.
0003 sslhelperUnauthenticated DoS. Every rejected connection left a zombie: the parent sent SIGTERM to the failed SSL helper and then did a WNOHANG wait before it had exited, and nothing reaped it later. Zombies count against RLIMIT_NPROC, so junk connections eventually stop the user from forking at all, x11vnc included. The wait is now blocking.
0004 sslhelperUnauthenticated DoS. A client that connected and then said nothing hung the whole server: the helper's VeNCrypt/ANONTLS negotiation read with no timeout, and the main loop waited for the helper's cookie with no timeout either. One idle connection was seen holding a public server for 17 minutes. The SSL_INIT_TIMEOUT alarm now covers the whole helper initialization, and the parent's wait is bounded.
0005 sslhelperLocal authentication bypass. For VeNCrypt/ANONTLS clients the helper wrote its cookie truncated, and the parent accepted any prefix of it, down to a bare RB=. A local process could race the helper to the parent's loopback port and get a session with no certificate (with -nopw, full desktop control). The whole cookie is now sent and must match exactly.
0006 sslhelperBytes from an unauthenticated client that did not send an RFB version were logged raw, so terminal escape sequences could be put into the log. Non-printable bytes are now replaced.
0007 sslhelperNo protocol floor or cipher list was set, so OpenSSL 3 defaults allowed TLS 1.2 static-RSA and CBC-SHA1 suites. The server now requires TLS ≥ 1.2 and, for TLS 1.2, ECDHE with AES-GCM or ChaCha20-Poly1305 (so -dhparams no longer has an effect). X11VNC_SSL_CIPHERS overrides the list.

A second review, with dynamic tests against a lab build, found gaps in 0003-0007. Fixed in -r3:

PatchFix
0008 sslhelper0004 armed the timeout early, but the handshake loop re-armed it and cancelled it on success, so the helper could take twice SSL_INIT_TIMEOUT and the HTTP sniffing after the handshake ran unbounded (one loop spun at full CPU on a half-closed client). One deadline now covers everything until the helper starts relaying. The 20s greeting wait after an HTTPS fetch is capped to fit inside it, and SSL_INIT_TIMEOUT is capped at a day.
0009 sslhelperThe parent still searched for the VENCRYPT= tag anywhere in a helper message. HTTPS messages carry the client's request line, so a crafted URL was taken as a VeNCrypt selection (harmless, but wrong). The message must now be exactly <prefix>,VENCRYPT=<n>,<cookie>.
0010 sslhelper0006 missed the invalid version log line, which RFB 3.7 plus five escape bytes still reached.
0011 sslhelperWith 0003 reaping a helper after rfbNewClient() fails, its pid stayed in the helper table and could be signalled at exit after reuse. The entry is now removed.

libvncserver (overlay/net-libs/libvncserver/files/, against 0.9.15 plus the ::gentoo cmake4 patch). x11vnc's -threads runs libvncserver's threaded client mode: one thread applies the client's messages while another encodes screen updates, and the first changed state the second was using without taking its lock. Each race was reproduced under ASan/UBSan against both a minimal threaded server and x11vnc 0.9.17 itself. Every trigger needs a client that has already authenticated (with -ssl -sslverify, a valid certificate).

PatchFix
0001-0004Backports of upstream server-side fixes after 0.9.15: e7ee07dd and eae4f703 (no invalid fds to FD_SET, which aborts under _FORTIFY_SOURCE), 1b4f87f4 (fd leak on an interrupted file transfer), 5ea5fc30 (no update sending once the client is shutting down).
0005eae4f703 returns from rfbWriteExact() with outputMutex held, which can deadlock a later rfbClientConnectionGone(). Also in upstream master.
0006Input and output threads could both tear down a client on disconnect: double free of cl->wspath (and of the SSL context for wss). Teardown moves to rfbClientConnectionGone() in threaded mode.
0007Repeated GET lines in a websocket handshake leaked cl->wspath, and the handshake had no overall deadline (one trickling client could hold the accepting thread for minutes).
0008SetPixelFormat wrote the client's format before validating it and swapped the translation tables under the encoder: use-after-free, a heap overflow past cl->updateBuf (x11vnc died with its client list overwritten by pixel data), and a division by zero for bpp=0 that killed x11vnc. The format is now validated into a local and swapped under sendMutex. Also rejects ZRLE shifts over 31.
0009SetEncodings reset the Tight compression level mid-rectangle, so tight.c indexed past tightConf[4] and divided by a value read beyond it (SIGFPE). The list is now read first and applied under sendMutex.
0010Bounds checks on the Tight configuration tables, in case a level reaches them some other way.
0011SetScale swapped the client's scaled framebuffer under the encoder, which then read past the end of the new one and sent adjacent heap memory to the client. Now swapped under sendMutex.
0012rfbWriteExact() encoded a WebSocket frame into the per-client buffer before taking outputMutex, so two threads writing to one client (an update, and x11vnc's main loop sending clipboard text) could send each other's frame; noVNC drops the connection on a bad frame. The lock now covers the encoding too.

None of the races exist without -threads, but dropping it has a real cost: x11vnc's main loop blocks on every incoming SSL handshake, and without threads that freezes input and encoding as well as screen polling. On a public port, where scanners connect all the time, the desktop became noticeably slower. Keep -threads and use this library.

-r4

x11vnc 0012-0035 (all against 0.9.17, applied after 0001-0011):

PatchesChange
0012-0017, 0034The main loop no longer waits on SSL handshakes. Before, each connection's helper was waited for in the main loop, so a port scanner holding a handshake froze screen updates (and without -threads, input) for everyone - measured 7-18% of the time on a public port. Helpers now sit in a bounded table polled each pass; at most 4 pending handshakes per source address (a source at its cap replaces its own oldest), the oldest of the busiest source is evicted when the table is full. The helper cookie is 256 random bits, the connect-back port is chosen by the kernel, and the certificate/DH reports go through unlinked temp files, so nothing is left in /tmp. With 6 stalled connections a connected viewer's longest update gap went from 8.1 s to 0.39 s, and a new client's connect time from 11 s to under a second. X11VNC_SSL_SYNC_HELPER=1 restores the old behaviour.
0018-0019The pre-auth SSL helper closes every inherited descriptor and, with -sslverify, runs under a seccomp allowlist, PR_SET_NO_NEW_PRIVS, not-dumpable and zero process/core limits before it reads anything from the client (X11VNC_SSL_HELPER_SANDBOX=0 or =log).
0020X11VNC_NO_NEW_PRIVS=1 sets PR_SET_NO_NEW_PRIVS for x11vnc itself (opt-in).
0021The accepted client certificate (subject, issuer, serial, SHA-256) is logged; -users sslpeer= and RFB_SSL_CLIENT_CERT work again.
0022-0025Clipboard text over 128 KiB read at the wrong offset; a self-deadlock on every framebuffer change (-xrandr resize) with -threads and a client; cursors[-1] after a new framebuffer; a departed client's deferred pointer events.
0026TCP_NODELAY on both sockets of the SSL relay. Nagle held the second of the two TLS records of every Tight update until the first was ACKed: keystroke-to-glyph on loopback 49.7 -> 8.8 ms (p50), and a round trip less on about half of small updates over a WAN.
0027-0031Review fixes: async-signal-safe SIGALRM handlers; the HTTP sniff wait fits inside the helper deadline; no inherited log/timezone locks in the forked helper; client_gone() no longer blocks on a helper; helper-table/reap fixes.
0032-0033The "holds its port but never accepts" wedge. With -threads the scan locked every client's sendMutex and unlocked by walking the client list again; a client removed in between - a refused HTTP/WebSocket GET does that - stayed locked, and its thread blocked forever in rfbClientConnectionGone(). The send ban now unlocks exactly the clients it locked (holding a reference), and framebuffer changes use the same ban.
0035With IPv6 and no -ssl, libvncserver opened its own listener on [::]:5900, ignoring -rfbport, -localhost and -noipv6.

libvncserver 0001-0026 (against 0.9.15 + the ::gentoo cmake4 patch): 0001-0004 are upstream cherry-picks; 0005-0013 the threaded-mode races and locking above (plus ExtendedClipboard replies under sendMutex, TLS teardown order for GnuTLS); 0014-0025 bugs found by fuzzing, none fixed upstream as of master 98aaee05 - a TightPng heap overflow (16 bpp client, up to ~64 KiB written past the buffer), Tight with a 24 bpp client sending up to ~64 KiB of adjacent heap to the client, a SIGFPE on an empty FramebufferUpdateRequest, a WebSocket control-frame livelock and split frame headers, scaled screens across resizes, a NULL cursor in CopyRect, and smaller ones; 0026 sends a small Tight update as one write.

Both ebuilds add FORTIFY level 3, zero-initialised automatic variables and explicit RELRO/now/noexecstack, and drop a global --allow-multiple-definition; x11vnc requires libvncserver-0.9.15-r4.

tests/run.sh builds both packages from the tarballs and the overlay patches (or tests a given binary) and runs a lab regression suite: TLS policy, zombies and fd leaks, handshake stalls, log sanitising, VeNCrypt, threaded stress, input, clipboard and resize. See tests/README.md.

-r11 (x11vnc) and libvncserver -r10

PatchFix
libvncserver 0062ContinuousUpdates fell into stop-and-wait on short, fast links. The flow-control window was one bandwidth x base-RTT plus an average update size capped at that same product, so at 20 ms a single video frame overflowed it: every update waited for the answer to the previous one (transfer, client decode, round trip, next encode in series), and the rate measured under that cap could never grow the window. The extra term is now the largest of the last 16 updates, uncapped, and before any rate sample the window is 64 kB plus that, so at least two updates are always in flight. Real noVNC, 20 ms / 3 MB/s, 640x360 video: 2.9 -> 4.5 pictures/s and draw-to-pixel p90 2172 -> 627 ms; ZRLE at 20 ms / 10 MB/s: 6.1 -> 11.8 updates/s.
libvncserver 0063rfbNewFramebuffer() in threaded mode locked every client's sendMutex in one walk and unlocked in a second; a client that closed in between stayed locked and its input thread hung for good in rfbClientConnectionGone() (found by fuzzing; x11vnc -threads does its own resize locking and was not affected). It now unlocks exactly the clients it locked, holding a reference on each.
x11vnc 0075Other threads' "check this area" requests no longer write the scan's tile bitmap directly.
x11vnc 0076The scroll-copy decision is made under the send ban, in the same pass that applies it, not one pass earlier.

-r10 (x11vnc only; libvncserver stays -r9)

PatchFix
0068X error handlers no longer call into Xlib. With -clear_all, an X error during a resize storm went Xerror() -> clear_keys() -> XQueryKeymap() inside Xlib and deadlocked the main thread while it held X_LOCK and every client's sendMutex. The handler now logs, sets shut_down and lets the main loop exit cleanly (status 1, so -loop restarts). Before: 5 of 9 resize stress runs deadlocked; after: 30 of 30 clean.
0069Trap handlers kept a pointer to Xlib's on-stack XErrorEvent; they keep a copy.
0070XShmAttach() is now waited for (XSync under a serial-matched trap). A refused attach is retried once, then x11vnc falls back to XGetImage instead of failing later on a segment the server never attached.
0071-0072Framebuffer writes outside the scan now take the send ban: the black-screen clear, the wireframe box, direct_fb_copy() and the CopyRect moves (which could otherwise move torn pixels on the client for good).
0073Held keys are released when the last client disconnects. With -repeat, a key held when a viewer's connection dropped kept auto-repeating into the focused window until x11vnc restarted.
0074The SSL relay no longer reaps helpers at its 70 s cutover: under the -r8 seccomp filter that kill(pid,0) killed the relay, so a TLS session ended 70 s after connecting whenever another helper (a scanner's handshake, a reconnect) was running.

-r9 (performance)

Six measured performance rounds, merged on -r8 (every -r8 security fix and PoC still holds; the strict suite, an ASan/UBSan suite, byte-exact encoder output and exact-pixel convergence after scroll/drag/video are part of the gate). Over an emulated 115 ms / 2.5 MB/s link:

-r8-r9
Typing key->glyph p50126 ms121 ms
Terminal scroll settles p50285 ms133 ms
Window drag settles239 ms153 ms
640x360 video, Tight16 fps28 fps
640x360 video, H.264 adaptive (opt-in)3.7 fps (ZRLE)29 fps at 1/6 the bandwidth
Typing during video p50 (ZRLE)344 ms174 ms
Idle CPU, x11vnc / X server2.5% / 1.0%0.4% / 0.1%

The matching noVNC changes (ContinuousUpdates/Fence, the H.264 decoder and "Video (H.264)" menu entry, a wasm ZRLE decoder, ImageDecoder for JPEG, one bundled script) are in NoVNCAudio.

-r7 and -r8

-r7 (libvncserver 0045): the WebSocket Origin allowlist, LIBVNCSERVER_WS_ORIGINS. A browser sends its TLS client certificate with a WebSocket that any page opens, and with -nopw the certificate is the whole authentication: without this, every website the certificate holder visited could open the session and type into it (cross-site WebSocket hijacking). Set it to the noVNC page's own origin only, and serve that page from an origin nothing else shares.

-r8 merges a further security round: a fix agent (soft cursor drawn per client, clipboard/bells queued to the output thread, X error-handler leaks) and two exploit hunts (pre-auth: a use-after-free of the last client address and an -allow bypass in the non-blocking accept, a single-address accept flood, TLS session tickets with a shared key and no peer-cert check in the helper, the SIGTERM fallback; post-auth: view-only pointer lock, ZRLE raw tiles to 15-bit clients, client cut text without a terminating NUL, hotkeys ignoring -input), plus a cursor race found by ThreadSanitizer.

libvncserver 0.9.15 (0046-0052, on -r7 0001-0045)

x11vnc 0.9.17 (0053-0062, on -r6 0001-0052)

x11vnc 0061 relies on libvncserver 0049 for viewOnly clients; 0062 is correct with or without libvncserver 0051.

-r5 and -r6

-r5 (post-deploy locking tests: SetScale during resizes crashed -r4): new clients wait while a framebuffer change holds the send ban, scaled screens are rebuilt after it, no NULL-framebuffer sampling, update regions clipped to the current framebuffer, settle_clients() measures scaled clients by their own size, no shm cleanup of freed tile rows.

-r6 merges three follow-up rounds - remaining libvncserver bugs, a ThreadSanitizer race hunt of x11vnc -threads, and a main-loop latency/robustness pass (a watchdog found 132 main-loop pauses over 100 ms in two minutes of realistic load; none remain). Notable: a viewer that stops reading no longer freezes the server (it could, for up to a week); a reconnect with -nevershared no longer frees the old client under an iterator; SIGTERM no longer deadlocks in Xlib; one leaked 8 MiB thread per connection; connecting while another viewer is busy takes ~0.2 s instead of 4-8 s.

libvncserver 0.9.15 (0029-0044, on -r5 0001-0028)

x11vnc 0.9.17 (0039-0052, on -r5 0001-0038)

x11vnc 0051 uses rfbNewClientNoWebSockets() from libvncserver 0044 when present; with an older library it falls back to rfbNewClient().

Ebuilds: x11vnc-0.9.17-r10 and libvncserver-0.9.15-r9, the ::gentoo ebuilds with the patches above. It does not install the ::gentoo init/conf scripts, because NoVNCAudio drives x11vnc from its own /etc/init.d/vnc.

Installing

As an overlay of its own:

cat > /etc/portage/repos.conf/x11vnc-fixes.conf <<'EOF'
[x11vnc-fixes]
location = /var/db/repos/x11vnc-fixes/overlay
EOF
git clone https://coredump.ws/repos/x11vnc-fixes.git /var/db/repos/x11vnc-fixes
emerge -av1 =net-libs/libvncserver-0.9.15-r10::x11vnc-fixes =x11-misc/x11vnc-0.9.17-r11::x11vnc-fixes

Or copy overlay/x11-misc/x11vnc and overlay/net-libs/libvncserver into an existing local overlay. Without Gentoo, apply the patches in order to the 0.9.17 tarball with patch -p1.

A running x11vnc keeps the old binary until it is restarted. Its -loop parent re-execs the binary from disk, so the whole tree has to go down (NoVNCAudio: rc-service vnc restart_vnc).

These need no rebuild and complement the patches:

Other findings

Collected while writing these patches, not fixed here:

License

GPL-3.0-or-later, see LICENSE. The exception is the ebuilds and init scripts that are modified copies of Gentoo's: they are Gentoo's work under GPL-2, as their headers say, and stay that way. The patches are also offered under the licence of the project they patch, so they can go upstream.