Fix data race on error queue state in wc_LoggingInit - #11449
Open
annihilatorq wants to merge 1 commit into
Open
Conversation
|
Can one of the admins verify this patch? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In builds with the global error queue enabled (OPENSSL_EXTRA without ERROR_QUEUE_PER_THREAD),
wc_LoggingInit()resetswc_errors,wc_errors_count,wc_last_node, andwc_current_nodewithout acquiring thewc_error_mutex, whereas any other access to the queue (e.g.wc_ClearErrorNodes()) read/write the same variables while acquiring this mutex.This may affect the application code because
wolfSSL_CTX_new()implicitly callswolfSSL_Init()internally wheninitRefCount == 0, and a call towolfSSL_ERR_clear_error()may be made beforewolfSSL_Init()is called (for example - asio does this). As a result:Found by TSan in the test-suite of my project that supports asio with OpenSSL-compatible wolfSSL (
vcpkg wolfssl[asio], version 5.8.4 with global error queue, to be exact). In its constructor,asio::ssl::contextfirst callsERR_clear_error(), thenSSL_CTX_new().Fix: acquire the
wc_error_mutexinsidewc_LoggingInitwhile assigning new values towc_errors_count,wc_errors,wc_current_node, andwc_last_nodeTesting
./configure --enable-all --disable-error-queue-per-thread && make checkand./configure --enable-all && make checkboth pass (17 pass, 6 skipped).Minimal repro. wolfSSL should be built with
OPENSSL_EXTRA, disabledERROR_QUEUE_PER_THREAD, and-fsanitize=thread:TSan report (unpatched)
TSan report (patched): clean.
Checklist
No tests were added because the race cannot be deterministically asserted.