ocsp: replace stapling_mutex with std::shared_mutex and fix leaks#13226
Open
c-taylor wants to merge 1 commit into
Open
ocsp: replace stapling_mutex with std::shared_mutex and fix leaks#13226c-taylor wants to merge 1 commit into
c-taylor wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the OCSP stapling cache synchronization in ATS’ TLS stack by replacing a per-certinfo ink_mutex with std::shared_mutex, allowing concurrent readers on the TLS handshake hot path while keeping cache updates exclusively locked. It also addresses several lifetime / teardown leaks and an SSL_CTX ownership bug in the stapling initialization error path.
Changes:
- Replace
ink_mutexwithstd::shared_mutexfor stapling response data, using shared locks for readers and exclusive locks for updates. - Modify the stapling callback to copy the cached DER response under a shared lock and perform heap allocation outside the critical section.
- Fix resource cleanup bugs in SSL_CTX teardown (free
cid, and on BoringSSL release theX509_up_ref()taken for the map key), and correct map deletion behavior on init errors.
Contributor
Author
|
Expecting minor conflicts after merging #13229 |
bneradt
previously approved these changes
Jun 9, 2026
Replace the per-certinfo ink_mutex with a std::shared_mutex so readers on the TLS handshake hot path (ssl_callback_ocsp_stapling) and the refresh scan (ocsp_update) can run concurrently; only the cache update takes an exclusive lock. The handshake reader now copies the DER staple to a stack buffer under the shared lock and allocates outside the critical section.
c5880c9 to
e7c30af
Compare
Contributor
Author
|
Rebase + resolve conflicts |
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.
Replace the per-certinfo ink_mutex with a std::shared_mutex so readers on the TLS handshake hot path (ssl_callback_ocsp_stapling) and the refresh scan (ocsp_update) can run concurrently; only the cache update takes an exclusive lock. The handshake reader now copies the DER staple to a stack buffer under the shared lock and allocates outside the critical section.
Because the mutex is no longer a C type, certinfo is allocated with new/delete instead of OPENSSL_malloc.
Also fix three pre-existing bugs:
This is a rework of #13097 to separate into 2x independent PRs
std::shared_mutex vs. bravo
The lock pressure for new TLS connections is less than volume or other event/txn mutex. Favoring the reduced memory overhead in the implementation over perfect hypothetical performance. The majority of the benefit is realised from using ANY shared type.
I would suggest that should bravo be favored it become an isolated PR.