File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -23,14 +23,16 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
23
23
for _ in 0 ..RETRY_LIMIT {
24
24
let mut el = mem:: uninitialized ( ) ;
25
25
if _rdrand64_step ( & mut el) == 1 {
26
- // AMD CPUs from families 14h to 16h (pre Ryzen) will sometimes give
27
- // bogus random data. Discard these values and warn the user .
26
+ // AMD CPUs from families 14h to 16h (pre Ryzen) sometimes fail to
27
+ // set CF on bogus random data, so we check these values explictly .
28
28
// See https://github.com/systemd/systemd/issues/11810#issuecomment-489727505
29
- if cfg ! ( not( target_env = "sgx" ) ) && ( el == 0 || el == !0 ) {
30
- error ! ( "RDRAND returned suspicious value {}, CPU RNG is broken" , el) ;
31
- return Err ( Error :: UNKNOWN ) ;
29
+ // We perform this check regardless of target to guard against
30
+ // any implementation that incorrectly fails to set CF.
31
+ if el != 0 && el != !0 {
32
+ return Ok ( el. to_ne_bytes ( ) ) ;
32
33
}
33
- return Ok ( el. to_ne_bytes ( ) ) ;
34
+ error ! ( "RDRAND returned {:X}, CPU RNG may be broken" , el) ;
35
+ // Keep looping in case this was a false positive.
34
36
}
35
37
}
36
38
error ! ( "RDRAND failed, CPU issue likely" ) ;
You can’t perform that action at this time.
0 commit comments