Skip to content

Commit 55e9c67

Browse files
committed
BUG/MINOR: backend: check delay MUX before conn_prepare()
In connect_server(), when a new connection must be instantiated, MUX initialization is delayed if an ALPN setting is present on the server line configuration, as negotiation must be performed to select the correct MUX. However, this is not the case if the ALPN can already be retrieved on the server cache. This check is performed too late however and may cause issue with the QUIC stack. The problem can happen when the server ALPN is not yet set. In the normal case, quic_conn layer is instantiated and MUX init is delayed until the handshake completion. When the MUX is finally instantiated, it reused without any issue app_ops from its quic_conn, which is derived from the negotiated ALPN. However, there is a race condition if another QUIC connection populates the server ALPN cache. If this happens after the first quic_conn init but prior to the MUX delay check, the MUX will thus immediately start in connect_server(). When app_ops is retrieved from its quic_conn, a crash occurs in qcc_install_app_ops() as the QUIC handshake is not yet finalized : #0 0x000055e242a66df4 in qcc_install_app_ops (qcc=0x7f127c39da90, app_ops=0x0) at src/mux_quic.c:1697 1697 if (app_ops->init && !app_ops->init(qcc)) { [Current thread is 1 (Thread 0x7f12810f06c0 (LWP 25758))] To fix this, MUX delay check is moved up in connect_server(). It is now performed prior conn_prepare() which is responsible for the quic_conn layer instantiation. Thus, it ensures consistency for the QUIC stack : MUX init is always delayed if the quic_conn does not reuses itself the SSL session and ALPN server cache (no quic_reuse_srv_params()). This must be backported up to 3.3.
1 parent 194a676 commit 55e9c67

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

src/backend.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,25 @@ int connect_server(struct stream *s)
20592059
srv_conn->sni_hash = ssl_sock_sni_hash(sni);
20602060
}
20612061
}
2062+
2063+
#if defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
2064+
/* Delay mux initialization if SSL and ALPN/NPN is set
2065+
* and server cache is not yet populated. Note that in
2066+
* TCP mode this check is ignored as only mux-pt is
2067+
* available.
2068+
*
2069+
* This check must be performed before conn_prepare()
2070+
* to ensure consistency accross the whole stack, in
2071+
* particular for QUIC between quic-conn and mux layer.
2072+
*/
2073+
HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2074+
if (IS_HTX_STRM(s) && srv->use_ssl &&
2075+
(srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str) &&
2076+
srv->path_params.nego_alpn[0] == 0)
2077+
may_start_mux_now = 0;
2078+
HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2079+
#endif /* TLSEXT_TYPE_application_layer_protocol_negotiation */
2080+
20622081
#endif /* USE_OPENSSL */
20632082

20642083
if (conn_prepare(srv_conn, proto, srv->xprt)) {
@@ -2091,21 +2110,6 @@ int connect_server(struct stream *s)
20912110
}
20922111
srv_conn->ctx = s->scb;
20932112

2094-
#if defined(USE_OPENSSL) && defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
2095-
/* Delay mux initialization if SSL and ALPN/NPN is set. Note
2096-
* that this is skipped in TCP mode as we only want mux-pt
2097-
* anyway.
2098-
*/
2099-
if (srv) {
2100-
HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2101-
if (IS_HTX_STRM(s) && srv->use_ssl &&
2102-
(srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str) &&
2103-
srv->path_params.nego_alpn[0] == 0)
2104-
may_start_mux_now = 0;
2105-
HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2106-
}
2107-
#endif
2108-
21092113
/* process the case where the server requires the PROXY protocol to be sent */
21102114
srv_conn->send_proxy_ofs = 0;
21112115

0 commit comments

Comments
 (0)