File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,14 +23,16 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
2323 for _ in 0 ..RETRY_LIMIT {
2424 let mut el = mem:: uninitialized ( ) ;
2525 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 .
2828 // 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 ( ) ) ;
3233 }
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.
3436 }
3537 }
3638 error ! ( "RDRAND failed, CPU issue likely" ) ;
You can’t perform that action at this time.
0 commit comments