Repository navigation
Hold MBEDTLSLOCK while ca_chain!, own_cert! and set_alpn! change a config - #319
Merged
Merged
Conversation
…nfig These replace what handshake steps read, and the GC can free the replaced chain or ALPN list. Without the lock, a handshake step on another thread could be using the old one when it's replaced. HTTP.jl sets the chain of its shared config for every connection when HTTP_CA_BUNDLE is set, so this happens in practice; the lock makes the swap wait for the step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #319 +/- ##
==========================================
+ Coverage 88.93% 88.97% +0.03%
==========================================
Files 12 12
Lines 904 907 +3
==========================================
+ Hits 804 807 +3
Misses 100 100 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
ca_chain!,own_cert!andset_alpn!replace what handshake steps read (conf->ca_chain, the own-cert list,conf->alpn_list), and the GC can then free the replaced chain or ALPN list. A handshake step on another thread that already read the old pointer could use it after it's freed. The window is narrow: the GC has to run during one of that step's Julia callbacks (f_verify, say).This matters because HTTP.jl 1.x calls
ca_chain!on its shared global config for every new connection whenHTTP_CA_BUNDLEorCURL_CA_BUNDLEis set (Connections.jl,global_sslconfig). The setters now holdMBEDTLSLOCK(#315), so a swap waits for any in-flight handshake step, and later steps only see the new value.To be clear, this is a defensive fix: I couldn't make master crash. 2,400 threaded handshakes with the chain swapped and fully GC'd in a loop all succeeded, on master and with this change. The fix rests on reading the code. The cost is that these setters wait for a running handshake step.
Found by a fourth independent review pass (as plausible).
🤖 Generated with Claude Code