X-Debbugs-Cc: [email protected]
Package: cups-daemon
Version: 2.4.2-3+deb12u10
Severity: important
Tags: security patch upstream
Dear maintainers,
cupsd in bookworm dies with SIGSEGV as soon as a client talks TLS
(ipps://)
and closes the connection afterwards. Since cupsd is restarted by
systemd,
the crash is easy to miss: the client just gets a reset, jobs
disappear.
Printing over plain ipp:// is unaffected, which is why this went
unnoticed.
Reproduced on Debian 12.15 (bookworm), amd64, cups-daemon
2.4.2-3+deb12u10
(binary built with OpenSSL, libcups2 linked against libssl.so.3).
Steps to reproduce
------------------
1. Make TLS usable. Note that on the Debian package TLS is broken
out of the
box because of a second, independent bug (see below / separate
report):
the default ServerKeychain does not point to the existing
/etc/cups/ssl,
so cupsd logs "Unable to encrypt connection: No such file or
directory".
# sed -i 's|^#ServerKeychain ssl|ServerKeychain
/etc/cups/ssl|' /etc/cups/cups-files.conf
# systemctl restart cups
(CreateSelfSignedCerts defaults to yes, cupsd creates
/etc/cups/ssl/<hostname>.crt/.key on its own.)
2. Send any IPP request over TLS and let the client close the
connection:
$ ipptool -t ipps://127.0.0.1:631/printers/<queue> \
/usr/share/cups/ipptool/get-printer-attributes.test
Get printer attributes using get-printer-attributes
[PASS]
$ systemctl show -p MainPID --value cups # PID has changed
$ journalctl -u cups --since '-2 min' | grep SEGV
... cups.service: Main process exited, code=killed,
status=11/SEGV
$ dmesg | tail -1
cupsd[438469]: segfault at 7f3931a47d50 ip 00007f3931a47d50 sp
00007ffffb063938
error 15 in libc.so.6[1d3d50,7f3931a47000+2000] likely on CPU 5
The same happens with an unauthenticated ipps Create-Job +
Send-Document
(which is answered with 401) -- no credentials are needed to
trigger it.
Observed / expected
-------------------
cupsd segfaults; expected: connection is torn down cleanly, cupsd
keeps running.
Backtrace
---------
Obtained by running the same source build under gdb:
Thread 1 "cupsd" received signal SIGSEGV, Segmentation fault.
0x00007f19423cad50 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#0 0x00007f19423cad50 in ?? () from
/lib/x86_64-linux-gnu/libc.so.6
#1 0x00007f1941dcedee in SSL_pending () from
/lib/x86_64-linux-gnu/libssl.so.3
#2 0x00007f1942427610 in _httpTLSPending (http=<optimized
out>) at ./cups/tls-openssl.c:871
#3 0x00007f194240ab05 in httpGetReady (http=<optimized out>)
at ./cups/http.c:1104
#4 0x000055cc44f612d0 in main (argc=<optimized out>,
argv=<optimized out>) at ./scheduler/main.c:1044
Analysis
--------
cups/tls-openssl.c, _httpTLSStop():
context = SSL_get_SSL_CTX(http->tls);
SSL_shutdown(http->tls);
SSL_CTX_free(context);
SSL_free(http->tls); <-- http->tls is left dangling
}
The GnuTLS backend does it correctly (cups/tls-gnutls.c:
gnutls_deinit();
http->tls = NULL;). For encrypted clients, scheduler/client.c:463
(httpShutdown() in the "partial close" path of
cupsdCloseClient()) tears the
TLS state down, but the client stays in the Clients array for the
next main
loop iteration; scheduler/main.c:1044 then calls httpGetReady() ->
_httpTLSPending() -> SSL_pending() on the already freed SSL object.
Proposed fix (one line)
-----------------------
--- a/cups/tls-openssl.c
+++ b/cups/tls-openssl.c
@@ -1152,6 +1152,7 @@ _httpTLSStop(http_t *http)
SSL_shutdown(http->tls);
SSL_CTX_free(context);
SSL_free(http->tls);
+ http->tls = NULL;
}
This matches current upstream master; all released 2.4.x tarballs
(v2.4.2 ... v2.4.6) lack the assignment, so an upstream backport
is needed as
well -- I am going to file it with OpenPrinting as well.
Local rebuild with this single change survives the reproducer, 3x
aborted
TLS handshakes and 3x truncated POSTs (PID unchanged, no SEGV).
Second, related finding (worth a separate report)
-------------------------------------------------
TLS is broken out of the box: on OpenSSL builds scheduler/conf.c sets
ServerKeychain to "/Library/Keychains/System.keychain" (a macOS
path), and
cups-files.conf only contains a commented "#ServerKeychain ssl";
since
cupsd chdir()s to "/", a relative "ssl" would resolve to /ssl anyway.
Result: every ipps:// client gets "cups-pki-error", the log fills
with
"Unable to encrypt connection: No such file or directory".
Setting "ServerKeychain /etc/cups/ssl" fixes it. Upstream master
maps a
relative server keychain against ServerRoot (conf.c:1205ff) --
that part is
missing in 2.4.2.
Note: the NULL dereference reported as #1155899 is unrelated (it
is a
regression from the CVE-2026-27447 backport in 2.4.2-3+deb12u10
and hit the
same host), but it masked this crash: while no TLS connection can be
established, the use-after-free is unreachable.
Regards,
Maximilian, [email protected]