]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: ssl: never return 0 from the BIO read callback
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 1 Dec 2026 14:35:29 +0000 (15:35 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 1 Dec 2026 14:25:21 +0000 (15:25 +0100)
Commit "BUG/MEDIUM: ssl: ignore unexpected EOFs reported by the SSL
library" sets SSL_OP_IGNORE_UNEXPECTED_EOF so that a close without a
close_notify is no longer turned into an error by OpenSSL 4.0 and AWS-LC
5.9. But with this option, the library reports such a close exactly as
if a close_notify had been received, so there is no way to tell them
apart anymore. We don't use that information for now, but we may want
to in the future.

Let's remove the option, and make ha_ssl_read() return -1 with no retry
flag instead of 0 when the connection is shut or in error, as is already
done for a shutdown during a frontend handshake. The library then
reports a syscall failure, as older versions did, which
ssl_sock_to_buf() handles as a regular shutdown.

This should not be backported, the commit above is enough for the
stable versions.

src/ssl_sock.c

index c296474589be8ee82bdde032b3492982c1b9ca41..5e975724afcf2757d7a908e74e3f538e536ee78d 100644 (file)
@@ -448,8 +448,10 @@ static int ha_ssl_read(BIO *h, char *buf, int size)
                ret = -1;
        }
        BIO_clear_retry_flags(h);
-       if (ret == 0 && !(ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))) {
-               BIO_set_retry_read(h);
+       if (ret == 0) {
+               /* never return 0, recent libs take it for an EOF and fail the connection */
+               if (!(ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)))
+                       BIO_set_retry_read(h);
                ret = -1;
        }
 #ifdef HA_USE_KTLS
@@ -4363,9 +4365,6 @@ ssl_sock_initial_ctx(struct bind_conf *bind_conf)
 #ifdef SSL_OP_NO_RENEGOTIATION
        options |= SSL_OP_NO_RENEGOTIATION;
 #endif
-#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
-       options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
-#endif
 
 #ifdef SSL_OP_NO_RX_CERTIFICATE_COMPRESSION
        if (global_ssl.certificate_compression == 0)
@@ -5658,9 +5657,6 @@ static int ssl_sock_prepare_srv_ssl_ctx(const struct server *srv, SSL_CTX *ctx)
        else if (srv->ssl_ctx.renegotiate == SSL_RENEGOTIATE_ON)
                options &= ~SSL_OP_NO_RENEGOTIATION;
 #endif
-#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
-       options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
-#endif
 
 #ifdef SSL_OP_NO_RX_CERTIFICATE_COMPRESSION
        if (global_ssl.certificate_compression == 0)