[Syslog-ng-maintainers] Bug#1153581: syslog-ng-core: first message of a TLS session can lack ${.tls.x509_cn} (fixed upstream in 4.11.0)
Jarno Mäkelä
jarno.makela at 208.fi
Tue Nov 10 08:19:46 GMT 2026
Package: syslog-ng-core
Version: 4.8.1-5+deb13u1
Severity: important
Tags: patch upstream fixed-upstream trixie
Control: fixed -1 4.12.0-1
Dear Maintainer,
On a TLS source, the first message of a session can be created without
${.tls.x509_cn}, ${.tls.x509_o}, ${.tls.x509_ou} and ${.tls.x509_fp}.
The handshake completes, the client certificate is verified, the message
is received intact, and the macros are empty. Later messages on the same
session are not affected.
This affects every configuration that uses these macros, for example
one that attributes each message to the authenticated peer:
rewrite r_bind_peer_identity { set("${.tls.x509_cn}" value("HOST")); };
The affected message is stored with no origin. The exposure is greatest
exactly when a sender reconnects with a backlog: a syslog-ng client with
a disk-buffer() writes its queued messages immediately after the
handshake. We found it as an intermittent failure in our integration
tests; the reproduction below makes it deterministic.
Cause
-----
tls_session_info_callback() fills in TLSSession.peer_info at
SSL_ST_ACCEPT|SSL_CB_LOOP, that is, while the handshake runs. On the
accepting side the handshake runs inside SSL_read(), called from
log_transport_tls_read_method() (lib/transport/transport-tls.c).
That function copies peer_info into the LogTransportAuxData before it
calls SSL_read(). When the SSL_read() call that completes the handshake
also returns the first application data, the aux data was taken while
peer_info.found was still 0, and the message is created without the
peer values.
This happens whenever the client's first message is already in the
socket by the time the server finishes sending its Finished and OpenSSL
continues the same SSL_read() into the application data: a sender with
a backlog writes immediately after its handshake, and a receiver thread
descheduled at that point loses the race.
Upstream fixed this in 4.11.0, by commits 005e8dea2f and bd99d3975a
(https://github.com/syslog-ng/syslog-ng/pull/5611), which add the peer
info after SSL_read(). unstable and forky carry the fix from 4.12.0-1;
trixie's 4.8.1-5+deb13u1 does not.
Reproduction
------------
The attached reproduce.sh runs a TLS 1.2 receiver with
peer-verify(required-trusted) and sends single-message sessions with
openssl s_client. To make the window deterministic, gdb holds the
receiver for 0.3 s at SSL_CB_HANDSHAKE_DONE, when its Finished has been
sent and the SSL_read() that ran the handshake has not yet read
application data.
On a clean trixie container, syslog-ng-core 4.8.1-5+deb13u1:
A no pause 10/10 cn=[cli.test]
B pause, message already queued 10/10 cn=[]
C pause, message written 1 s after connect 10/10 cn=[cli.test]
Patch
-----
The attached tls-peer-info-after-ssl-read.patch backports the upstream
change to the 4.8.1 read method (upstream applied it after the
LogTransportAdapter rework, so it does not cherry-pick). It moves the
aux data block below the SSL_read() loop, unchanged otherwise.
Tested on Debian 13 amd64, kernel 6.12.116+deb13-amd64, with
the patch added to debian/patches of 4.8.1-5+deb13u1:
- reproduce.sh: 10/10 cn=[cli.test] for A, B and C.
- autopkgtest (basic x3, baseconfig, testinitscript): all pass, as for
the unpatched package.
- Upstream unit tests: debian/rules runs them only when criterion.pc
is present, and libcriterion-dev is not in Build-Depends, so a
normal build skips them. Built with libcriterion-dev installed,
patched and unpatched give identical results, 222 of 228 passing.
The same six fail in both (lib/tests/test_zone,
lib/timeutils/tests/test_conv, test_scan_timestamp, test_unixtime,
modules/timestamp/tests/test_format_date,
modules/python-modules/test_pymodules), none in code the patch
touches. No unit test exercises log_transport_tls_read_method()
itself; reproduce.sh is the test of the change.
Would you consider this for a trixie point release? The change is
confined to one function and matches what unstable already ships.
-- System Information:
Debian Release: 13.7
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 6.12.116+deb13-amd64 (SMP w/64 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: unable to detect
Versions of packages syslog-ng-core depends on:
ii libc6 2.41-12+deb13u4
ii libcap2 1:2.75-10+deb13u1+b3
ii libglib2.0-0t64 2.84.4-3~deb13u5
ii libivykis0t64 0.43.2-1+b1
ii libjson-c5 0.18+ds-1
ii libnet1 1.3+dfsg-2
ii libpcre2-8-0 10.46-1~deb13u3
ii libssl3t64 3.5.7-1~deb13u3
ii libsystemd0 257.13-1~deb13u1
ii libwrap0 7.6.q-36
ii sysvinit-utils [lsb-base] 3.14-4
Versions of packages syslog-ng-core recommends:
pn logrotate <none>
Versions of packages syslog-ng-core suggests:
pn syslog-ng-mod-add-contextual-data <none>
pn syslog-ng-mod-amqp <none>
pn syslog-ng-mod-examples <none>
pn syslog-ng-mod-geoip2 <none>
pn syslog-ng-mod-graphite <none>
pn syslog-ng-mod-http <none>
pn syslog-ng-mod-mongodb <none>
pn syslog-ng-mod-python <none>
pn syslog-ng-mod-rdkafka <none>
pn syslog-ng-mod-redis <none>
pn syslog-ng-mod-riemann <none>
pn syslog-ng-mod-slog <none>
pn syslog-ng-mod-snmp <none>
pn syslog-ng-mod-sql <none>
pn syslog-ng-mod-stardate <none>
pn syslog-ng-mod-stomp <none>
pn syslog-ng-mod-xml-parser <none>
-- no debconf information
-------------- next part --------------
#!/bin/bash
# Reproduces the missing ${.tls.x509_cn} on the first message of a TLS
# session in syslog-ng-core 4.8.1-5+deb13u1. Run as root in a disposable
# Debian 13 container started with
# --cap-add SYS_PTRACE --security-opt seccomp=unconfined
# Needs: syslog-ng-core openssl gdb.
#
# gdb holds the receiver for 0.3 s at SSL_CB_HANDSHAKE_DONE: its Finished
# is already sent, and the SSL_read() call that ran the handshake has not
# yet tried for application data. A client whose message is already
# queued gets it into that same SSL_read() call. Without gdb the same
# thing happens whenever the receiver thread is descheduled at that point.
set -e
W=$(mktemp -d)
cd "$W"
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout ca.key -out ca.pem -subj /CN=ca -days 1 2>/dev/null
for n in srv cli; do
openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout $n.key -out $n.csr -subj /CN=$n.test 2>/dev/null
openssl x509 -req -in $n.csr -CA ca.pem -CAkey ca.key -CAcreateserial \
-out $n.pem -days 1 2>/dev/null
done
cat > recv.conf <<EOF
@version: 4.8
source s {
syslog(ip("127.0.0.1") port(6514) transport("tls")
tls(peer-verify(required-trusted) ca-file("$W/ca.pem")
key-file("$W/srv.key") cert-file("$W/srv.pem")
ssl-options(no-sslv2, no-sslv3, no-tlsv1, no-tlsv11, no-tlsv13)));
};
destination d { file("$W/out.log" template("cn=[\${.tls.x509_cn}] \$MSG\n")); };
log { source(s); destination(d); };
EOF
# send <tag> [delay]: one RFC 6587 frame on a fresh TLS 1.2 connection,
# written to s_client's stdin after <delay> seconds.
send() {
local m="<134>1 2026-11-10T00:00:00Z h t 1 - - $1"
{ [ -n "$2" ] && sleep "$2"; printf '%d %s' "${#m}" "$m"; sleep 1; } |
openssl s_client -connect 127.0.0.1:6514 -cert cli.pem -key cli.key \
-CAfile ca.pem -quiet -no_ign_eof 2>/dev/null || true
}
syslog-ng -F -f recv.conf -R "$W/persist" -p "$W/pid" -c "$W/ctl" --no-caps &
sleep 1
for i in $(seq 1 10); do send A$i; done
cat > gdbcmds <<'EOF'
set pagination off
break tls_session_info_callback if $rsi == 0x20
continue
while 1
shell sleep 0.3
continue
end
EOF
gdb -q -p "$(cat "$W/pid")" -batch -x gdbcmds >gdb.log 2>&1 &
sleep 2
for i in $(seq 1 10); do send B$i; done
for i in $(seq 1 10); do send C$i 1; done
sleep 1
echo "A: no pause B: pause, message queued"
echo "C: pause, message written 1 s after connect"
sed -E 's/<134>.* - - //' out.log | awk '{print substr($2, 1, 1), $1}' | sort | uniq -c
kill %2 %1 2>/dev/null || true
-------------- next part --------------
Description: Add TLS peer info to aux data after SSL_read()
tls_session_info_callback() fills in peer_info while the handshake runs,
and on the accepting side the handshake runs inside SSL_read().
log_transport_tls_read_method() copied peer_info into the aux data before
calling SSL_read(), so when the read that completes the handshake also
returns the first application data, that message is created without
${.tls.x509_cn}, ${.tls.x509_o}, ${.tls.x509_ou} and ${.tls.x509_fp}.
Backport of upstream commits 005e8dea2f and bd99d3975a (PR #5611,
released in 4.11.0) to the pre-LogTransportAdapter read method of 4.8.1.
Origin: backport, https://github.com/syslog-ng/syslog-ng/pull/5611
Applied-Upstream: 4.11.0
Last-Update: 2026-11-10
---
--- a/lib/transport/transport-tls.c 2026-11-10 09:29:43.824153890 +0200
+++ b/lib/transport/transport-tls.c 2026-11-10 09:29:43.900154022 +0200
@@ -103,24 +103,6 @@
* SSL_ERROR_WANT_WRITE is specified by libssl */
self->super.super.cond = G_IO_IN;
- if (aux)
- {
- /* if we have found the peer has a certificate */
- if (self->tls_session->peer_info.found)
- {
- log_transport_aux_data_add_nv_pair(aux, ".tls.x509_cn", self->tls_session->peer_info.cn);
- log_transport_aux_data_add_nv_pair(aux, ".tls.x509_o", self->tls_session->peer_info.o);
- log_transport_aux_data_add_nv_pair(aux, ".tls.x509_ou", self->tls_session->peer_info.ou);
- }
- if (self->tls_session->peer_info.fingerprint[0])
- log_transport_aux_data_add_nv_pair(aux, ".tls.x509_fp", self->tls_session->peer_info.fingerprint);
-
- /* NOTE: we only support TLS on top of TCP for now. We could reuse the
- * proto auto detection code from transport-socket to make this more
- * accurate. */
-
- aux->proto = IPPROTO_TCP;
- }
do
{
rc = SSL_read(self->tls_session->ssl, buf, buflen);
@@ -158,6 +140,30 @@
}
while (rc == -1 && errno == EINTR);
+ /* peer_info is filled in by tls_session_info_callback() while the
+ * handshake runs, which happens inside SSL_read() on the accepting side.
+ * Reading it before SSL_read() leaves the first message of a session
+ * without the .tls.x509_* values when the handshake and that message
+ * are processed by the same SSL_read() call. */
+ if (aux)
+ {
+ /* if we have found the peer has a certificate */
+ if (self->tls_session->peer_info.found)
+ {
+ log_transport_aux_data_add_nv_pair(aux, ".tls.x509_cn", self->tls_session->peer_info.cn);
+ log_transport_aux_data_add_nv_pair(aux, ".tls.x509_o", self->tls_session->peer_info.o);
+ log_transport_aux_data_add_nv_pair(aux, ".tls.x509_ou", self->tls_session->peer_info.ou);
+ }
+ if (self->tls_session->peer_info.fingerprint[0])
+ log_transport_aux_data_add_nv_pair(aux, ".tls.x509_fp", self->tls_session->peer_info.fingerprint);
+
+ /* NOTE: we only support TLS on top of TCP for now. We could reuse the
+ * proto auto detection code from transport-socket to make this more
+ * accurate. */
+
+ aux->proto = IPPROTO_TCP;
+ }
+
if (rc > 0)
self->super.super.cond = 0;
More information about the Syslog-ng-maintainers
mailing list