Repository navigation
Correctly not try to call handshake() when engine is already closed. - #6090
normanmaurer wants to merge 1 commit into
Conversation
|
@Scottmitch @nmittler @trustin PTAL Also @johnou FYI |
|
@normanmaurer changes LGTM @davidben @kruton FYI ... We'll want to port this change over to conscrypt |
|
Lgtm, many issues left before next 4.0? |
|
@johnou nope... just wrapping up stuff |
|
|
||
| if (engineClosed) { | ||
| return NEED_UNWRAP_CLOSED; | ||
| if (outboundClosed) { |
There was a problem hiding this comment.
consider adding a comment here that we explicitly want to use outboundClosed instead of calling outboundClosed() because we want to drain any bytes if they are available.
| } | ||
| if (engineClosed) { | ||
| // Check if the inbound is considered to be closed if so let us try to wrap again. | ||
| if (isInboundDone()) { |
There was a problem hiding this comment.
use isInboundDone directly to be consistent with the wrap code?
| public final synchronized boolean isOutboundDone() { | ||
| return isOutboundDone; | ||
| // check if there is anything left in the outbound buffer. | ||
| return outboundClosed && (isDestroyed() || SSL.pendingWrittenBytesInBIO(networkBIO) == 0); |
There was a problem hiding this comment.
is checking isDestroyed() necessary? Setting the destroyed variable to "true" also means that outboundClosed will be set to true.
There was a problem hiding this comment.
yes as we only want to call SSL.pendingWrittenBytesInBIO(...) if the engine was not destroyed before. If we not check this it may result in a segfault as the SSL pointer was freed before.
| getEngineStatus(), mayFinishHandshake(status != FINISHED ? getHandshakeStatus() : status) | ||
| , bytesConsumed, bytesProduced); | ||
| return new SSLEngineResult(resultStatus, mayFinishHandshake(status != FINISHED ? getHandshakeStatus() : status), | ||
| bytesConsumed, bytesProduced); |
There was a problem hiding this comment.
nit: line up these args with the args above.
25ccf06 to
f2dc288
Compare
|
@Scottmitch PTAL again |
| @@ -367,7 +366,7 @@ public final synchronized void shutdown() { | |||
| ssl = networkBIO = 0; | |||
|
|
|||
| // internal errors can cause shutdown without marking the engine closed | |||
There was a problem hiding this comment.
this comment is obsolete now right?
There was a problem hiding this comment.
yes let me remove it
| return isOutboundDone; | ||
| // Check if there is anything left in the outbound buffer. | ||
| // We need to ensure we only call SSL.pendingWrittenBytesInBIO(...) if the engine was not destroyed yet. | ||
| return outboundClosed && (isDestroyed() || SSL.pendingWrittenBytesInBIO(networkBIO) == 0); |
There was a problem hiding this comment.
brain fart ... I see isDestroyed() is necessary now. Below is an alternative to avoid a volatile read:
return outboundClosed && (networkBIO == 0 || SSL.pendingWrittenBytesInBIO(networkBIO) == 0)There was a problem hiding this comment.
Ok can do this ... anything else?
Motivation: We need to ensure we not call handshake() when the engine is already closed. Beside this our implementation of isOutboundDone() was not correct as it not took the pending data in the outbound buffer into acount (which may be also generated as part of an ssl alert). Beside this we also called SSL_shutdown(...) while we were still in init state which will produce an error and so noise in the log with openssl later versions. This is also in some extend related to #5931 . Modifications: - Ensure we not call handshake() when already closed - Correctly implement isOutboundDone() - Not call SSL_shutdown(...) when still in init state - Added test-cases Result: More correct behaviour of our openssl SSLEngine implementation.
f2dc288 to
b71136c
Compare
|
@Scottmitch all addressed... PTAL again |
| // Check to make sure the engine has not been closed | ||
| if (isDestroyed()) { | ||
| // Check to make sure the engine has not been closed and the inbound was not marked as done. | ||
| if (isDestroyed() || (handshakeState == HandshakeState.NOT_STARTED && isInboundDone())) { |
There was a problem hiding this comment.
nit: you have parens here but not on line 590 ... can we be consistent? strictly speaking they aren't necessary but as long as we are consistent its all good.
There was a problem hiding this comment.
added them... easier to read.
|
@normanmaurer might be that we need similar guards in place for wrap too? I've only seen this happen once in production so if I deploy a canary build we might be waiting awhile.. |
|
@johnou - Would you mind filing another issue and provide any more details that you may have? |
|
@Scottmitch sounds good. |
Motivation:
We need to ensure we not call handshake() when the engine is already closed. Beside this our implementation of isOutboundDone() was not correct as it not took the pending data in the outbound buffer into acount (which may be also generated as part of an ssl alert). Beside this we also called SSL_shutdown(...) while we were still in init state which will produce an error and so noise in the log with openssl later versions.
This is also in some extend related to #5931 .
Modifications:
Result:
More correct behaviour of our openssl SSLEngine implementation.