]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Attach/detach to the listening child socket when accepting TLS
authorOndřej Surý <ondrej@isc.org>
Wed, 7 Aug 2024 06:43:12 +0000 (08:43 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 7 Aug 2024 15:16:50 +0000 (15:16 +0000)
When TLS connection (TLSstream) connection was accepted, the children
listening socket was not attached to sock->server and thus it could have
been freed before all the accepted connections were actually closed.

In turn, this would cause us to call isc_tls_free() too soon - causing
cascade errors in pending SSL_read_ex() in the accepted connections.

Properly attach and detach the children listening socket when accepting
and closing the server connections.

(cherry picked from commit 684f3eb8e62fb2dd2e6adf3272e87b1fd4b08579)

lib/isc/netmgr/tlsstream.c

index 7990351217c1b8d72a88099ae4d68c0ed5789e67..acb8f71c5da823df6e4eaf1a2bacf6fa449fb559 100644 (file)
@@ -916,6 +916,7 @@ tlslisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
        tlssock = isc_mempool_get(handle->sock->worker->nmsocket_pool);
        isc__nmsocket_init(tlssock, handle->sock->worker, isc_nm_tlssocket,
                           &local, NULL);
+       isc__nmsocket_attach(tlslistensock, &tlssock->server);
 
        /* We need to initialize SSL now to reference SSL_CTX properly */
        tlsctx = tls_get_listener_tlsctx(tlslistensock, isc_tid());
@@ -1174,6 +1175,10 @@ isc__nm_tls_close(isc_nmsocket_t *sock) {
                isc__nmsocket_detach(&sock->listener);
        }
 
+       if (sock->server != NULL) {
+               isc__nmsocket_detach(&sock->server);
+       }
+
        /* Further cleanup performed in isc__nm_tls_cleanup_data() */
        sock->closed = true;
        sock->active = false;