lib: call RandFailure() if RDRAND fails #34348

pull michaellappas wants to merge 1 commits into bitcoin:master from michaellappas:fix/handle-rdrand-failure changing 1 files +9 −0
  1. michaellappas commented at 8:50 pm on January 19, 2026: none

    While the risk of the RDRAND instruction failing in such a fashion is minor, the current implementation allows the process to continue if such an occurrence happens.

    Checking for such an occurrence and calling RandFailure() if it occurs is a safer alternative than failing silently.

  2. lib: call RandFailure() if RDRAND fails
    While the risk of the RDRAND instruction failing in such a fashion is minor, the current implementation allows the process to continue if such an occurrence happens.
    
    Checking for such an occurrence and calling RandFailure() if it occurs is a safer alternative than failing silently.
    2ceb172050
  3. DrahtBot commented at 8:51 pm on January 19, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34348.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  4. gmaxwell commented at 10:04 pm on January 22, 2026: contributor

    I’m dubious, since this will cause a total failure on (any?) platforms where its not correctly supported. But on platforms where its detectably not supported it’s just not used. ISTM this should behave like g_rdrand_supported == False, except perhaps in developer/debug builds (because it might be useful to know about specific hardware were rdrand is detected but doesn’t work).

    I believe some early zen cpus could have rdrand failures when the instruction was overused in another thread or maybe some race condition with suspend or something like that.

  5. michaellappas commented at 0:44 am on January 24, 2026: none

    ISTM this should behave like g_rdrand_supported == False, except perhaps in developer/debug builds (because it might be useful to know about specific hardware were rdrand is detected but doesn’t work).

    I don’t believe that these checks are equivalent. g_rdrand_supported represents whether the processor supports the RDRAND instruction. However, this check is not indicative of that; instead, it reflects that execution of the RDRAND instruction is failing in a continuous fashion. This behavior may occur at any time, rather than exclusively during initialization.

    I believe some early zen cpus could have rdrand failures when the instruction was overused in another thread or maybe some race condition with suspend or something like that.

    That scenario also appears to be mentioned in the Software Developer’s Manual:

    Under heavy load, with multiple cores executing RDRAND in parallel, it is possible, though unlikely, for the demand of random numbers by software processes/threads to exceed the rate at which the random number generator hardware can supply them. This will lead to the RDRAND instruction returning no data transitorily. The RDRAND instruction indicates the occurrence of this rare situation by clearing the CF flag.

  6. maflcko commented at 10:50 am on January 26, 2026: member
    It would be good to explain why this is the correct fix. To me it seems that this may kill Bitcoin Core at any point of uptime, if someone started a (weird) monte carlo simulation, even if it was just a rand-strengthen and not a rand-init? Maybe it would be better to allow rdrand exhaustion during SeedHardwareFast, but disallow it during SeedHardwareSlow, possibly just using a pause-loop, like for rdseed. However, I wonder if there are still any CPUs out there that have rdrand, but not rdseed. If not, it would make testing this change hard, and if the rdrand fallback isn’t taken ever in practise, any code change to it will be meaningless.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-27 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me