-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Accept getrandom syscall being unknown in mbedtls_platform_entropy_poll() for linux #2117
Conversation
This commit fixes issue Mbed-TLS#1212 related to platform-specific entropy polling in an syscall-emulated environment. Previously, the implementation of the entropy gathering function `mbedtls_platform_entropy_poll()` for linux machines used the following logic to determine how to obtain entropy from the kernel: 1. If the getrandom() system call identifier SYS_getrandom is present and the kernel version is 3.17 or higher, use syscall( SYS_getrandom, ... ) 2. Otherwise, fall back to reading from /dev/random. There are two issues with this: 1. Portability: When cross-compiling the code for a different architecture and running it through system call emulation in qemu, qemu reports the host kernel version through uname but, as of v.2.5.0, doesn't support emulating the getrandom() syscall. This leads to `mbedtls_platform_entropy_poll()` failing even though reading from /dev/random would have worked. 2. Style: Extracting the linux kernel version from the output of `uname` is slightly tedious. This commit fixes both by implementing the suggestion in Mbed-TLS#1212: - It removes the kernel-version detection through uname(). - Instead, it checks whether `syscall( SYS_getrandom, ... )` fails with errno set to ENOSYS indicating an unknown system call. If so, it falls through to trying to read from /dev/random. Fixes Mbed-TLS#1212.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very nice improvement to the code as it's now more portable, cleaner and more compact. Now I feel bad for not writing it that way in the first place :)
Note: the issue fixed by this PR is labeled as a bug and the ChangeLog entry in under "Bugfix", so for consistency I'm relabeling this PR as "bug", hence "needs backports". |
@hanno-arm Could you please investigate and fix the Ci failures too? Jenkins probably wants you to rebase on development so that it finds its config file, and Travis tells us |
retest |
Failure in Travis CI:
|
@sbutcher-arm I couldn't reproduce this so far, and the CI log doesn't give any information on what went wrong. Merged |
@mpg @k-stachowiak Could you please re-review this PR? |
@sbutcher-arm I don't know how |
retest |
Wasn't spotted earlier because it's guarded by `! HAVE_GETRANDOM`.
1535150
to
9772da8
Compare
@sbutcher-arm I removed the merge-commit as requested. |
@sbutcher-arm @mpg @k-stachowiak Removing the merge commit rewrote the history starting for the last trivial commit 9772da8. Could you please re-review? |
Context: This PR fixes #1212 related to platform-specific entropy polling in runs using qemu user emulation.
Summary: Previously, the implementation of the entropy gathering function
mbedtls_platform_entropy_poll()
for linux machines used the following logic to determine how to obtain entropy from the kernel:getrandom()
system call identifierSYS_getrandom
is present and the kernel version is 3.17 or higher, usesyscall( SYS_getrandom, ... )
/dev/random.
There are two issues with this:
Portability: When cross-compiling the code for a different architecture and running it through system call emulation in qemu, qemu reports the host kernel version through
uname
but, as of v.2.5.0, doesn't support emulating thegetrandom()
syscall. This leads tombedtls_platform_entropy_poll()
failing even though reading from/dev/random
would have worked.Complexity: Extracting the linux kernel version from the output of
uname
is slightly tedious.This commit fixes both by implementing the suggestion in #1212:
syscall( SYS_getrandom, ... )
fails witherrno
set toENOSYS
indicating an unknown system call. If so, it falls through to trying to read from/dev/random
.Fixes #1212.
Internal Reference: IOTSSL-1948.