-
Notifications
You must be signed in to change notification settings - Fork 38.7k
back-compat: add fallback getentropy implementation #10335
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
Conversation
|
How about not using
No. |
|
Just had a quick chat about this on IRC. I'll fix this up as discussed. |
|
Huh? we should never be using getentropy() on Linux, that's why the getrandom() syscall is called directly. What is going wrong here exactly? Edit: ok after discussion on IRC understand, |
88d2feb to
e596faf
Compare
Additionally, ensure that getentropy uses the fallback in the event that it's unsupported at runtime.
getentropy was added in glibc 2.25. This ensures that binaries linked against later versions have a runtime fallback. This fallback simply returns ENOSYS, indicating that /dev/urandom should be used instead.
|
Updated as discussed with @sipa on IRC. @laanwj: specifically, the problem is building against a newer glibc, and older linux kernel headers for compatibility. So getentropy() is defined, but the syscall isn't. That's what I ran into here. Would you like to explicitly disable getentropy for linux on the build side as well? |
|
@theuni This commit simplifies the fallback logic a bit: sipa@0abac37 Both this PR or just disabling |
I don't see why we'd need it. I made the syscall-based path for Linux to avoid having to rely on any function provided by glibc (e.g. to require a certain glibc version) for kernel randomness. But I don't care deeply, as long as it works... |
|
utACK e596faf. Unclear from discussion above whether there is agreement to continue allowing fallback to getentropy on linux, though IMO it makes the code cleaner to fall straight through all the available calls like this PR does (despite the need for the weak symbol workaround). sipa's simplification sipa@0abac37 also seems good. |
|
Looking at this again with fresh eyes, I think the most straightforward is to only enable getentropy for openbsd, where we know what it's doing: #elif defined(HAVE_GETENTROPY) && defined(__OpenBSD__) Then we can drop all of the compat stuff. Sound reasonable? |
|
Yes, sounds good to me. |
|
Ok, closing this and opening a new PR as this no long has anything to do with back-compat. |
077d01f random: only use getentropy on openbsd (Cory Fields) Pull request description: Follow-up from #10335. I can confirm that this fixes my issue when building against a new glibc + old linux headers for back-compat. Tree-SHA512: a0fcf26995fbd3636f970e729a172c6e1d7c0de371e703f0653cd9776600f438ec43acd2b1eb92f2678a011968da8fbbeef8a54599434851f4c6ffe78291c172
077d01f random: only use getentropy on openbsd (Cory Fields) Pull request description: Follow-up from bitcoin#10335. I can confirm that this fixes my issue when building against a new glibc + old linux headers for back-compat. Tree-SHA512: a0fcf26995fbd3636f970e729a172c6e1d7c0de371e703f0653cd9776600f438ec43acd2b1eb92f2678a011968da8fbbeef8a54599434851f4c6ffe78291c172
Yet another fallback needed for getentropy :(
When building on a newer linux machine (glibc >= 2.25), the resulting binary will fail to run on an older one (<2.25), due to missing symbols. This adds a weak symbol for our own implementation for use as a last resort.
Alternative solutions welcome.