pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
7+ messages / 5 participants
[nested] [flat]
* BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-29 15:32 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 7+ messages in thread
From: PG Bug reporting form @ 2026-10-29 15:32 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: benjamin.arthur.mejia@gmail.com
The following bug has been logged on the website:
Bug reference: 19815
Logged by: Ben Mejia
Email address: benjamin.arthur.mejia@gmail.com
PostgreSQL version: 19rc1
Operating system: RHEL 8.10 (UBI 8 container), x86_64, OpenSSL 1.1.
Description:
The new SNI test src/test/ssl/t/004_sni.pl fails on RHEL 8 with OpenSSL
1.1.1k, which configure.ac documents as the minimum supported version.
Two of its 129 assertions fail on every run. The same source passes on
RHEL 9, and the test has no OpenSSL version guard.
Environment
- RHEL 8.10 (UBI 8 builder image), x86_64, openssl-1.1.1k-18.el8_6
- configure --enable-tap-tests --with-openssl (plus other options)
- source: REL_19_STABLE at fc189eb7508 (after the REL_19_RC1 tag),
which includes commit 4f433025f66 ("ssl: Serverside SNI support for
libpq"); checked against current REL_19_STABLE (0c6e0437110): the
test and be-secure-openssl.c are unchanged by the 40 newer commits
except for 9674c91aeb2 (EXEC_BACKEND/Windows, unrelated to this path)
Reproduce
make -C src/test/ssl check PG_TEST_EXTRA=ssl PROVE_TESTS=t/004_sni.pl
Result (5 of 5 runs identical, about 6 seconds each)
# Failed test 'pg_hosts.conf: connect to default with sslmode=require:
matches'
# at t/004_sni.pl line 333.
# 'psql: error: connection to server at "127.0.0.1",
port 22348 failed: SSL SYSCALL error: EOF detected'
# doesn't match '(?^:handshake failure)'
# Failed test 'pg_hosts.conf: connect to default after failed reload
with ssl_sni off: matches'
# at t/004_sni.pl line 394.
(same message)
# Looks like you failed 2 tests of 129.
Both are connect_fails() calls with sslsni=0 against a server whose
pg_hosts.conf has no default entry, expecting qr/handshake failure/.
The other 127 assertions pass, including the ones that expect
"unrecognized name".
What I checked
- The server rejects the connection as the code intends. Its log has
"could not accept SSL connection: callback failed", and there is no
crash or signal. In sni_clienthello_cb() the no-hostname case sets
*al = SSL_AD_MISSING_EXTENSION and returns SSL_CLIENT_HELLO_ERROR.
- It is not TLS 1.3 specific. With ssl_max_protocol_version =
'TLSv1.2' on the server (the server log then shows
protocol=TLSv1.2 for all 27 connections), the same two assertions
fail the same way.
- It is not a timing race: 5 of 5 runs fail.
- The same source on RHEL 9 with its system OpenSSL 3 passes the whole
test, so the client there does report the expected message. I did
not record that OpenSSL's exact version.
What I do not know
- Whether the 1.1.1 server does not send the alert on this early
ClientHello-callback failure, or sends it and the 1.1.1 client does
not read it before the connection closes. I have not looked at the
traffic.
- Whether any buildfarm animal runs this test with OpenSSL 1.1.1.
Question
Is the expected message in these two assertions meant to depend on the
OpenSSL version? If 1.1.1 should be supported here, should the test
accept the EOF form (as some other tests in this directory accept
alternatives), or should the server behave differently in this case?
I am happy to run further experiments on this setup.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-30 19:10 Andrey Rachitskiy <pl0h0yp1@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 7+ messages in thread
From: Andrey Rachitskiy @ 2026-10-30 19:10 UTC (permalink / raw)
To: benjamin.arthur.mejia@gmail.com; pgsql-bugs@lists.postgresql.org; +Cc: Daniel Gustafsson <daniel@yesql.se>
пт, 30 окт. 2026 г. в 12:14, PG Bug reporting form <noreply@postgresql.org>:
> Result (5 of 5 runs identical, about 6 seconds each)
> # Failed test 'pg_hosts.conf: connect to default with sslmode=require:
> matches'
> # at t/004_sni.pl line 333.
> # 'psql: error: connection to server at "127.0.0.1",
> port 22348 failed: SSL SYSCALL error: EOF detected'
> # doesn't match '(?^:handshake failure)'
> # Failed test 'pg_hosts.conf: connect to default after failed reload
> with ssl_sni off: matches'
> # at t/004_sni.pl line 394.
> (same message)
> # Looks like you failed 2 tests of 129.
>
>
>
Hi, Ben!
Thanks for the report.
OpenSSL 1.1.1 has no mapping for missing_extension and returns -1 [1].
ssl3_send_alert() writes nothing [2], the socket closes and libpq reports
"SSL SYSCALL error: EOF detected". The attached patch requests
SSL_AD_HANDSHAKE_FAILURE instead. OpenSSL 1.1.1 sends that alert [3].
OpenSSL 3 already produces alert SSL_AD_HANDSHAKE_FAILURE for both values,
so the client text stays the same [4].
[1]
https://github.com/openssl/openssl/blob/OpenSSL_1_1_1k/ssl/t1_enc.c#L606-L677
[2]
https://github.com/openssl/openssl/blob/OpenSSL_1_1_1k/ssl/s3_msg.c#L49-L50
[3]
https://github.com/openssl/openssl/blob/OpenSSL_1_1_1k/ssl/t1_enc.c#L621-L622
[4]
https://github.com/openssl/openssl/blob/openssl-3.0.7/ssl/t1_enc.c#L798-L799
https://github.com/openssl/openssl/blob/openssl-3.0.7/ssl/t1_enc.c#L852-L853
Thoughts?
--
Regards,
Rachitskiy Andrey
Attachments:
0001-Fix-missing-alert-when-ClientHello-has-no-server_name.patch (text/x-patch, 2.8K) download
From 677485c9fffaa8a425101295cc5843cac4787811 Mon Sep 17 00:00:00 2001
From: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Date: Fri, 30 Oct 2026 23:25:27 +0500
Subject: [PATCH] Fix missing alert when ClientHello has no server_name
sni_clienthello_cb() requests SSL_AD_MISSING_EXTENSION when the
ClientHello has no server_name and pg_hosts.conf has no fallback.
OpenSSL runs the callback before choosing a protocol version and
translates the alert with tls1_alert_code(). OpenSSL 1.1.1 has no
mapping for that alert and closes the socket, so libpq reports
"SSL SYSCALL error: EOF detected". OpenSSL 3 rewrites the same
alert to handshake_failure, which src/test/ssl/t/004_sni.pl already
expects.
Request SSL_AD_HANDSHAKE_FAILURE instead. OpenSSL 1.1.1 sends that
alert, and the client message on OpenSSL 3 stays the same.
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reported-by: Ben Mejia <benjamin.arthur.mejia@gmail.com>
Discussion: https://postgr.es/m/19815-8c6d40e717afe5fd@postgresql.org
Backpatch-through: 19
---
src/backend/libpq/be-secure-openssl.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index fbd4f1173bc..79f3deab30e 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -2076,17 +2076,15 @@ sni_clienthello_cb(SSL *ssl, int *al, void *arg)
else
{
/*
- * Reaching here means that we didn't get a hostname in the TLS
- * extension and the server has been configured to not allow any
- * connections without a specified hostname.
- *
- * The error message for a missing server_name should, according
- * to RFC 8446, be missing_extension. This isn't entirely ideal
- * since the user won't be able to tell which extension the server
- * considered missing. Sending unrecognized_name would be a more
- * helpful error, but for now we stick to the RFC.
+ * No server_name extension, and no fallback. RFC 8446 specifies
+ * missing_extension for this case. This callback runs before
+ * OpenSSL selects a protocol version, so the alert is translated
+ * with the TLS 1.2 table. OpenSSL 1.1.1 has no mapping for
+ * missing_extension and closes the connection without an alert.
+ * OpenSSL 3 rewrites it to handshake_failure. Send
+ * handshake_failure so both versions send an alert.
*/
- *al = SSL_AD_MISSING_EXTENSION;
+ *al = SSL_AD_HANDSHAKE_FAILURE;
ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
@@ -2104,7 +2102,7 @@ sni_clienthello_cb(SSL *ssl, int *al, void *arg)
if (tlsext_hostname)
*al = SSL_AD_UNRECOGNIZED_NAME;
else
- *al = SSL_AD_MISSING_EXTENSION;
+ *al = SSL_AD_HANDSHAKE_FAILURE;
return SSL_CLIENT_HELLO_ERROR;
}
--
2.53.0
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-30 19:47 Jacob Champion <jacob.champion@enterprisedb.com>
parent: Andrey Rachitskiy <pl0h0yp1@gmail.com>
0 siblings, 2 replies; 7+ messages in thread
From: Jacob Champion @ 2026-10-30 19:47 UTC (permalink / raw)
To: Andrey Rachitskiy <pl0h0yp1@gmail.com>; +Cc: benjamin.arthur.mejia@gmail.com, pgsql-bugs@lists.postgresql.org, Daniel Gustafsson <daniel@yesql.se>
On Fri, Oct 30, 2026 at 12:10 PM Andrey Rachitskiy <pl0h0yp1@gmail.com> wrote:
> OpenSSL 1.1.1 has no mapping for missing_extension and returns -1 [1]. ssl3_send_alert() writes nothing [2], the socket closes and libpq reports "SSL SYSCALL error: EOF detected".
1.1.1o apparently fixes the mapping behavior, which is why I didn't
see it locally... It's easy enough to add an alternative expected
message to the tests, but why aren't our RHEL 8 buildfarm machines
complaining?
--Jacob
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-30 19:59 Andrey Rachitskiy <pl0h0yp1@gmail.com>
parent: Jacob Champion <jacob.champion@enterprisedb.com>
1 sibling, 1 reply; 7+ messages in thread
From: Andrey Rachitskiy @ 2026-10-30 19:59 UTC (permalink / raw)
To: Jacob Champion <jacob.champion@enterprisedb.com>; +Cc: benjamin.arthur.mejia@gmail.com, pgsql-bugs@lists.postgresql.org, Daniel Gustafsson <daniel@yesql.se>
сб, 31 окт. 2026 г. в 00:47, Jacob Champion <jacob.champion@enterprisedb.com
>:
> but why aren't our RHEL 8 buildfarm machines complaining?
>
>
Hi, Jacob!
1.1.1o does contain this code (
https://github.com/openssl/openssl/blob/ca2e0784d2c38edcefd5d68028f4d954bd8faddb/ssl/t1_enc.c#L675),
if that version is on the buildfarm, everything will be fine.
--
Regards,
Rachitskiy Andrey
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-30 21:36 Andrey Rachitskiy <pl0h0yp1@gmail.com>
parent: Andrey Rachitskiy <pl0h0yp1@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Andrey Rachitskiy @ 2026-10-30 21:36 UTC (permalink / raw)
To: Jacob Champion <jacob.champion@enterprisedb.com>; +Cc: benjamin.arthur.mejia@gmail.com, pgsql-bugs@lists.postgresql.org, Daniel Gustafsson <daniel@yesql.se>
сб, 31 окт. 2026 г. в 00:59, Andrey Rachitskiy <pl0h0yp1@gmail.com>:
> if that version is on the buildfarm, everything will be fine.
>
>
camel (RHEL 8.9, OpenSSL 1.1.1k) records an empty PG_TEST_EXTRA [1].
004_sni.pl returns skip_all unless PG_TEST_EXTRA contains the word ssl
[2]. That's
why we didn't see the error.
[1]
https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=camel&dt=2026-10-30%2009%3A30%3A41...
[2]
https://github.com/postgres/postgres/blob/0c6e0437110dd6ceb14fdca5b323bc1b058a13cf/src/test/ssl/t/00...
--
Regards,
Rachitskiy Andrey
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-10-31 00:28 Michael Paquier <michael@paquier.xyz>
parent: Jacob Champion <jacob.champion@enterprisedb.com>
1 sibling, 1 reply; 7+ messages in thread
From: Michael Paquier @ 2026-10-31 00:28 UTC (permalink / raw)
To: Jacob Champion <jacob.champion@enterprisedb.com>; +Cc: Andrey Rachitskiy <pl0h0yp1@gmail.com>; benjamin.arthur.mejia@gmail.com, pgsql-bugs@lists.postgresql.org, Daniel Gustafsson <daniel@yesql.se>
On Fri, Oct 30, 2026 at 12:47:17PM -0700, Jacob Champion wrote:
> 1.1.1o apparently fixes the mapping behavior, which is why I didn't
> see it locally... It's easy enough to add an alternative expected
> message to the tests, but why aren't our RHEL 8 buildfarm machines
> complaining?
Perhaps they're already patched or reflect some specific RHEL
behavior. If the diff of output can be fixed by upgrading OpenSSL,
I'd suggest to upgrade OpenSSL on the buildfarm host, not touch
Postgres to adapt to it, especially as everybody should be out of
1.1.1 these days.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86)
@ 2026-11-03 12:53 Daniel Gustafsson <daniel@yesql.se>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Gustafsson @ 2026-11-03 12:53 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Jacob Champion <jacob.champion@enterprisedb.com>; Andrey Rachitskiy <pl0h0yp1@gmail.com>; benjamin.arthur.mejia@gmail.com; pgsql-bugs@lists.postgresql.org
> On 31 Oct 2026, at 01:28, Michael Paquier <michael@paquier.xyz> wrote:
>
> On Fri, Oct 30, 2026 at 12:47:17PM -0700, Jacob Champion wrote:
>> 1.1.1o apparently fixes the mapping behavior, which is why I didn't
>> see it locally... It's easy enough to add an alternative expected
>> message to the tests, but why aren't our RHEL 8 buildfarm machines
>> complaining?
>
> Perhaps they're already patched or reflect some specific RHEL
> behavior. If the diff of output can be fixed by upgrading OpenSSL,
> I'd suggest to upgrade OpenSSL on the buildfarm host, not touch
> Postgres to adapt to it, especially as everybody should be out of
> 1.1.1 these days.
I've built and tested old versions of OpenSSL to confirm the behaviour, and
1.1.1n and newer does indeed pass the tests. OpenSSL 1.1.1n is 4 years old,
and 1.1.1 is 3 years out of support, so I too don't see a compelling reason to
carry an alternative output file which risk masking other bugs, or patch libpq,
when the real solution is to upgrade OpenSSL.
If we suddenly get RHEL8 machines running the SSL tests, with ancient OpenSSL
versions, in the buildfarm we might have to revisit.
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-11-03 12:53 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 15:32 BUG #19815: 004_sni.pl fails deterministically with OpenSSL 1.1.1 (tests 75 and 86) PG Bug reporting form <noreply@postgresql.org>
2026-10-30 19:10 ` Andrey Rachitskiy <pl0h0yp1@gmail.com>
2026-10-30 19:47 ` Jacob Champion <jacob.champion@enterprisedb.com>
2026-10-30 19:59 ` Andrey Rachitskiy <pl0h0yp1@gmail.com>
2026-10-30 21:36 ` Andrey Rachitskiy <pl0h0yp1@gmail.com>
2026-10-31 00:28 ` Michael Paquier <michael@paquier.xyz>
2026-11-03 12:53 ` Daniel Gustafsson <daniel@yesql.se>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox