-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check for broken Ryzen RDRAND #67
Merged
Merged
Conversation
This file contains 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
Some AMD Ryzen CPUs get into a bad state where the output of RDRAND becomes "stuck" on a value of all 1s (e.g., every bit in the output is a one). Unfortunately, it doesn't correctly set the carry flag to indicate an RNG failure. This change detects this case and handles it as a standard RNG error.
bdonlan
reviewed
Oct 30, 2019
lrstewart
reviewed
Oct 30, 2019
This moves where we check for RDRAND being stuck to a better location and also adds tests for this logic. These tests only run with the 'coverage' target. I have validated that the tests work by backing out the fixes and manually verifying the failure.
bdonlan
suggested changes
Oct 30, 2019
Also re-add new-line in test_rdrand.cpp
As discussed with @bdonlan, I've simplified the logic to just discard the suspicious values of I've also restarted the
|
bdonlan
approved these changes
Nov 1, 2019
lrstewart
approved these changes
Nov 1, 2019
praus
approved these changes
Nov 1, 2019
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.
It is important that the
dieharder
acceptance test passes before this PR is merged.Description of changes:
Some AMD Ryzen CPUs get into a bad state where the output of RDRAND becomes "stuck" on a value of all 1s (e.g., every bit in the output is a one). Unfortunately, it doesn't correctly set the carry flag to indicate an RNG failure.
This change detects this case and handles it as a standard RNG error. It does this by watching for the suspicious value of
0xffffffffffffffff
and if it is seen, checks to see if the RNG is stuck on that value. We take this strategy rather than failing upon simply seeing a single instance of0xffffffffffffffff
for two reasons:0xffffffffffffffff
. This avoids all biased output.We also check for the suspicious value of
0
using the same technique. While we believe all modern systems to correctly set the carry flag on failure, some old/non-standard systems used a0
to indicate failure.For more context please see this Ars Technical article and this systemd patch.
To support some libraries which do not define
UINT64_MAX
, I also added a definition for this. As evidence that it is being correctly defined, here is the disassembled version ofrng_rdseed
which is correctly checking against the suspicious value of 64 bits of 1s.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.