Skip to content

Conversation

@theuni
Copy link
Member

@theuni theuni commented May 4, 2017

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.

@dcousens
Copy link
Contributor

dcousens commented May 4, 2017

Alternative solutions welcome.

return 0? (aka, do nothing)
I assume we are already mixing /dev/urandom elsewhere though - if not, ACK

@sipa
Copy link
Member

sipa commented May 4, 2017

Alternative solutions welcome.

How about not using getentropy on Linux? It's a BSD compatibility function. The Really Good (TM) solution is using SYS_getrandom, but if that's not available, just fallback to using /dev/urandom directly.

I assume we are already mixing /dev/urandom elsewhere though.

No. getrandom / getentropy replace the need for /dev/urandom.

@theuni
Copy link
Member Author

theuni commented May 4, 2017

Just had a quick chat about this on IRC. I'll fix this up as discussed.

@laanwj
Copy link
Member

laanwj commented May 4, 2017

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, getentropy is detected on newer versions of glibc, causing that to be used. That should be avoided, the SYS_getrandom path should always be used on Linux, getentropy is for BSD.

@theuni theuni force-pushed the getentropy-back-compat branch 3 times, most recently from 88d2feb to e596faf Compare May 4, 2017 17:36
theuni added 2 commits May 4, 2017 13:39
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.
@theuni
Copy link
Member Author

theuni commented May 4, 2017

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?

@sipa
Copy link
Member

sipa commented May 4, 2017

@theuni This commit simplifies the fallback logic a bit: sipa@0abac37

Both this PR or just disabling getentropy on Linux are fine solutions to me.

@laanwj
Copy link
Member

laanwj commented May 5, 2017

Would you like to explicitly disable getentropy for linux on the build side as well?

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...

@ryanofsky
Copy link
Contributor

ryanofsky commented May 10, 2017

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.

@laanwj
Copy link
Member

laanwj commented Jun 24, 2017

@theuni can you comment on @sipa's implementation?

@theuni
Copy link
Member Author

theuni commented Jul 17, 2017

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?

@laanwj
Copy link
Member

laanwj commented Jul 17, 2017

Yes, sounds good to me.

@theuni
Copy link
Member Author

theuni commented Jul 17, 2017

Ok, closing this and opening a new PR as this no long has anything to do with back-compat.

@theuni theuni closed this Jul 17, 2017
laanwj added a commit that referenced this pull request Jul 18, 2017
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 24, 2019
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants