[release/10.0] Fix thread safety in SafeEvpPKeyHandle.DuplicateHandle#124613
Open
github-actions[bot] wants to merge 8 commits intorelease/10.0from
Open
[release/10.0] Fix thread safety in SafeEvpPKeyHandle.DuplicateHandle#124613github-actions[bot] wants to merge 8 commits intorelease/10.0from
github-actions[bot] wants to merge 8 commits intorelease/10.0from
Conversation
Use DangerousAddRef/DangerousRelease to prevent the source handle from being disposed by another thread while DuplicateHandle reads the handle value. Capture handle and ExtraHandle values into local variables while the ref count is elevated, so a concurrent Dispose cannot zero them out before they are copied to the new SafeEvpPKeyHandle. Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
…ut catch Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
…t formatting Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
bartonjs
approved these changes
Feb 19, 2026
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.
Backport of #124485 to release/10.0
Customer Impact
Parallel calls to Dispose and DuplicateHandle on SafeEvpPKeyHandle can result in a state where the native handle gets up-ref'd, but the SafeHandle returned from DuplicateHandle is tracking the zero-valued handle, so the underlying free never gets called (and interacting with the returned SafeHandle doesn't do what you want, either).
Regression
Testing
A dedicated test is added with this change.
Risk
Low. DangerousAddRef/DangerousRelease is a standard treatment for SafeHandle atomicity.