Add cryptographic operation counts to prevent process crashes#100371
Merged
vcsjones merged 8 commits intodotnet:mainfrom Apr 11, 2024
Merged
Add cryptographic operation counts to prevent process crashes#100371vcsjones merged 8 commits intodotnet:mainfrom
vcsjones merged 8 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
bartonjs
reviewed
Mar 27, 2024
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Shake128.cs
Outdated
Show resolved
Hide resolved
bartonjs
reviewed
Mar 27, 2024
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Shake128.cs
Outdated
Show resolved
Hide resolved
am11
reviewed
Mar 28, 2024
...ibraries/System.Security.Cryptography/src/System/Security/Cryptography/ConcurrentSafeKmac.cs
Show resolved
Hide resolved
vcsjones
commented
Mar 29, 2024
| } | ||
|
|
||
| _hHash = hHash; | ||
| SafeBCryptHashHandle? previousHash = Interlocked.Exchange(ref _hHash, hHash); |
Member
Author
There was a problem hiding this comment.
Assuming this made it past the _running guard, this
- Disposed the current handle in DestroyHash
- Nulled out
_hHash - Created a new hash
- Assigned
_hHashto the new one.
If another thread attempted to use that hash during 2 or 3, then some asserts would trip because we never expected _hHash to be null.
Now, we
- Create a new hash.
- Exchange old and new
- Dispose of old.
This ensures we don't have a period of time where _hHash can be null and trip asserts during test runs.
Member
Author
|
Benchmarks basically showed no major change when the interlocked value is not under contention. I didn't both to benchmark when it is under contention since that is an error path. |
bartonjs
approved these changes
Apr 10, 2024
5 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
OpenSSL, CNG, and CommonCrypto are not thread safe, and some improper uses result in hard process crashes. This is easiest to hit in paths that use initialize and reset primitives because the internal init routine frees and re-creates structures that might be in use by other operations. This has been observed in all three of our desktop platforms.
This pull request adds counts to in-flight operations for Hash and HMAC primitives so that we can throw managed exceptions in this scenario instead of process crashes.