Null-guard EVP_AEAD_CTX_cleanup for fork safety with shared memory#3280
Open
WillChilds-Klein wants to merge 6 commits into
Open
Null-guard EVP_AEAD_CTX_cleanup for fork safety with shared memory#3280WillChilds-Klein wants to merge 6 commits into
WillChilds-Klein wants to merge 6 commits into
Conversation
Applications that use fork() with MAP_SHARED memory for TLS connection state can trigger a SIGSEGV in EVP_AEAD_CTX_cleanup. This occurs because DEFINE_METHOD_FUNCTION lazily initializes AEAD vtables via CRYPTO_once into .bss storage. After fork(), each process has an independent .bss copy. If a child process initializes the vtable (by performing TLS) and stores an EVP_AEAD_CTX in shared memory, the parent process's vtable remains zeroed. When the parent calls EVP_AEAD_CTX_cleanup, it dereferences ctx->aead->cleanup which is NULL, crashing the process. This commit adds a null-check on ctx->aead->cleanup before calling it. This is safe because: - All AES-GCM cleanup functions are no-ops (empty function body) - aead_chacha20_poly1305_cleanup is also a no-op - In the cross-process cleanup scenario, skipping cleanup prevents a crash with no resource leak (the shared memory pool manages lifetime) Also adds aead_fork_test, an isolated test binary that verifies EVP_AEAD_CTX_cleanup tolerates an uninitialized vtable after fork().
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3280 +/- ##
==========================================
- Coverage 78.39% 78.14% -0.25%
==========================================
Files 693 694 +1
Lines 123806 123882 +76
Branches 17195 17197 +2
==========================================
- Hits 97060 96813 -247
- Misses 25826 26147 +321
- Partials 920 922 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Issues:
Resolves #P425555771
Description of changes:
Summary
Applications that use
fork()withMAP_SHAREDmemory for TLS connection state can trigger a SIGSEGV inEVP_AEAD_CTX_cleanup. This occurs becauseDEFINE_METHOD_FUNCTIONlazily initializes AEAD vtables viaCRYPTO_onceinto.bssstorage. Afterfork(), each process has an independent.bsscopy. If a child process initializes the vtable (by performing TLS) and stores anEVP_AEAD_CTXin shared memory, the parent process's vtable remains zeroed. When the parent callsEVP_AEAD_CTX_cleanup, it dereferencesctx->aead->cleanupwhich is NULL, crashing the process.
Call-outs:
n/a
Testing:
Adds
aead_fork_test, an isolated test binary that verifiesEVP_AEAD_CTX_cleanuptolerates an uninitialized vtable afterfork(). The test is a separate executable (likerand_isolated_test) because it requires that AEAD vtables are NOT initialized before the test runs. The FIPS power-on self-test and other tests incrypto_testtrigger vtable initialization as a side effect.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.