Repository navigation
tls: fix connection close detection while handshake is waiting - #45755
Conversation
When a TLS handshake is waiting on an async operation (such as certificate selection through some extensions, async certificate validation, or async private key provider operations), it was failing to detect if the downstream connection was closed, so that the async operation could be canceled and the TLS connection resources could be released. Added connection.readDisable() while in this state, which changes which socket events ConnectionImpl is registered to receive so that connection close is handled immediately. Without this change, SslSocket::doRead() was discarding the read event which would signal an EOF. Signed-off-by: Greg Greenway <[email protected]>
| HandshakeWaitingForConnectionData, | ||
|
|
||
| // The handshake is in progress and waiting on Envoy to complete an operation before it can | ||
| // continue. | ||
| HandshakeBlockedOnAsyncOperation, |
There was a problem hiding this comment.
These two were renamed for clarity, because now the state machine can go from the 2nd state back to the 1st
| connection->close(Network::ConnectionCloseType::NoFlush); | ||
| connection.reset(); | ||
|
|
||
| test_server_->waitForCounter("aysnc_cert_selection.cert_selection_cancelled", Eq(1), |
There was a problem hiding this comment.
That was pre-existing. Want me to fix it in all the tests? It's ~15 more lines to change.
There was a problem hiding this comment.
Ah, up to you. I didn't realize the scope prefix is wrongly named.
| if (info_->state() == Ssl::SocketState::HandshakeBlockedOnAsyncOperation && !read_disabled_) { | ||
| // Connection close events can only be detected if the connection has reading disabled, | ||
| // because the handshaker won't actually read any data (such as EOF) when the handshake is | ||
| // blocked on an async operation. |
There was a problem hiding this comment.
The comment is a bit confusing. Would we leak async operations here if we read disable and fail to detect connection closure? I think the handshake timer should probably force close it, but want to double check. Apart from this, the rest of the change looks reasonable and safe to deploy since it's mostly debug asserts.
There was a problem hiding this comment.
No, we won't leak async events; Envoy will not detect the downstream close, and so the async operation won't be cancelled when it should be.
Without the source change, the new integration test added will have the timer fire and ENVOY_BUG, instead of cancelling the operation.
Signed-off-by: Greg Greenway <[email protected]>
|
ASAN test failure is real /wait |
|
There's also a real failure in the mobile tests: |
Signed-off-by: Greg Greenway <[email protected]>
phase in the handshake Signed-off-by: Greg Greenway <[email protected]>
|
/retest |
#46676) #45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]>
envoyproxy#46676) envoyproxy#45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]> (cherry picked from commit 70f0729) Signed-off-by: Ryan Northey <[email protected]>
envoyproxy#46676) envoyproxy#45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]> (cherry picked from commit 70f0729) Signed-off-by: Ryan Northey <[email protected]>
envoyproxy#46676) envoyproxy#45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]> (cherry picked from commit 70f0729) Signed-off-by: Ryan Northey <[email protected]>
envoyproxy#46676) envoyproxy#45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]> (cherry picked from commit 70f0729) Signed-off-by: Ryan Northey <[email protected]>
envoyproxy#46676) envoyproxy#45755 allowed the socket state to transition to `ShutdownSent` before cert selection is complete (as intended). However, this could cause `ENVOY_BUG` to be thrown when `SslSocket::onAsynchronousCertificateSelectionComplete()` is invoked. This patch updates `SslSocket::onAsynchronousCertificateSelectionComplete` to allow this socket state which is consistent with the implementation of `SslSocket::onAsynchronousCertValidationComplete` and avoids the `ENVOY_BUG` in the case of valid states such as `ShutdownSent`. Signed-off-by: Ethan Truong <[email protected]> (cherry picked from commit 70f0729) Signed-off-by: Ryan Northey <[email protected]>
When a TLS handshake is waiting on an async operation (such as certificate selection through some extensions, async certificate validation, or async private key provider operations), it was failing to detect if the downstream connection was closed, so that the async operation could be canceled and the TLS connection resources could be released.
Added connection.readDisable() while in this state, which changes which socket events ConnectionImpl is registered to receive so that connection close is handled immediately. Without this change, SslSocket::doRead() was discarding the read event which would signal an EOF.
Risk Level: Medium
Testing: Added new tests; new integration test fails without this fix
Docs Changes: none
Release Notes: added