You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Does Android 8.0 support the getrandom syscall? #852
In ring 0.14 and earlier, Android always used /dev/urandom and never used the getrandom syscall. The current code in the ring master branch always uses the getrandom syscall. Is this new behavior too aggressive?
However, it is not clear whether the syscall available for use through syscall(SYS_getrandom) in Android 8.0. If not, we need to enable the fallback to /dev/urandom. If so, then the current code is correct.
@josephlr Can you find an authoritative answer to this question?
TL;DR; We need to have a /dev/urandom fallback and will need it at least until the 3.16 kernel ends LTS support in mid 2020.
An Android app has two values that matter when talking about versions. For more info see this article.
minSdkVersion - The minimum version your app supports, for Rust this is 14 (Andorid 4.0, Ice Cream Sandwich) on 32-bit and 21 (Android 5.0, Lollipop) on 64-bit as determined by their CI.
targetSdkVersion - The SDK's whose behavior changes your app has opted into. This allows Android to break backwards compatibility and then have apps opt into this breakage (not unlike Rust editions). This is the value that must increase by a certain date.
The getrandom() syscall was introduced in v3.17, and the earliest ASOP kernel that brings in those changes is Andoird 6.0 Marshmallow = API level 23. So it's on about 75% of Android devices. Of course vendors have kernel patches on top of ASOP, but it's unlikely many added or removed an entire syscall.
So we should determine what ring's minSdkVersion should be, Google uses Andorid 4.4 KitKat = API level 19 for most of our key apps (Youtube and Gmail), which gets you 95% of installed users. So I think 16 or 19 is a reasonable cutoff. We should keep the /dev/urandom fallback for now. We can revisit this when all supported mainline kernel versions have the syscall (April 2020), then it might make sense to remove the fallback for Linux and Android.
There are definitely devices running Android O that do not support getrandom (e.g. Nexus Player). Strictly speaking, even devices with Q don't have to support getrandom via syscall being invoked directly: the thing that's tested is the libc getrandom wrapper, and an OEM could implement that themselves however they wished. There isn't even a requirement that you're running on top of Linux.
In reality, though, I'd expect that the vast majority of devices running O have getrandom, and every device that officially supports P or newer has getrandom.
Thanks for the info. Maybe at some point we should consider calling getrandom() instead of syscall() if the minimum supported Android version is at least Android P. In the meantime, I think it makes sense to do things the way we are currently doing things, especially since BoringSSL does it this way too (BoringSSL: ret = syscall(__NR_getrandom, buf, buf_len, flags);).
ring for ARMv7 Android is built in CI using SDK version 26 targeting API level 18 (Android 4.3+); it is tested in the emulator using the corresponding system image. ring for AArch64 Android is built in CI using SDK version 26 targeting API level 21 (Android 5.0).
getauxval, not getrandom, is what is forces the minimum API level as of now.
Activity
[-]Does Android 8.0 support the `getrandom()` syscall[/-][+]Does Android 8.0 support the `getrandom()` syscall?[/+][-]Does Android 8.0 support the `getrandom()` syscall?[/-][+]Does Android 8.0 support the `getrandom` syscall?[/+]josephlr commentedon Jun 18, 2019
TL;DR; We need to have a
/dev/urandomfallback and will need it at least until the 3.16 kernel ends LTS support in mid 2020.An Android app has two values that matter when talking about versions. For more info see this article.
minSdkVersion- The minimum version your app supports, for Rust this is14(Andorid 4.0, Ice Cream Sandwich) on 32-bit and21(Android 5.0, Lollipop) on 64-bit as determined by their CI.targetSdkVersion- The SDK's whose behavior changes your app has opted into. This allows Android to break backwards compatibility and then have apps opt into this breakage (not unlike Rust editions). This is the value that must increase by a certain date.This repo is a good example. Their
minSdkVersionis16andtargetSdkVersionis28, so this app could be submitted to the Play Store today. Given the distribution of Andorid releases developers generally have a tradeoff to consider where setting a higherminSdkVersionmeans being installable on a smaller number of devices.The
getrandom()syscall was introduced in v3.17, and the earliest ASOP kernel that brings in those changes is Andoird 6.0 Marshmallow = API level 23. So it's on about 75% of Android devices. Of course vendors have kernel patches on top of ASOP, but it's unlikely many added or removed an entire syscall.So we should determine what ring's
minSdkVersionshould be, Google uses Andorid 4.4 KitKat = API level 19 for most of our key apps (Youtube and Gmail), which gets you 95% of installed users. So I think16or19is a reasonable cutoff. We should keep the/dev/urandomfallback for now. We can revisit this when all supported mainline kernel versions have the syscall (April 2020), then it might make sense to remove the fallback for Linux and Android.jmgao commentedon Jun 23, 2019
There are definitely devices running Android O that do not support getrandom (e.g. Nexus Player). Strictly speaking, even devices with Q don't have to support getrandom via syscall being invoked directly: the thing that's tested is the libc getrandom wrapper, and an OEM could implement that themselves however they wished. There isn't even a requirement that you're running on top of Linux.
In reality, though, I'd expect that the vast majority of devices running O have getrandom, and every device that officially supports P or newer has getrandom.
briansmith commentedon Jul 1, 2019
Thanks for the info. Maybe at some point we should consider calling
getrandom()instead ofsyscall()if the minimum supported Android version is at least Android P. In the meantime, I think it makes sense to do things the way we are currently doing things, especially since BoringSSL does it this way too (BoringSSL:ret = syscall(__NR_getrandom, buf, buf_len, flags);).briansmith commentedon Jul 11, 2019
From the new README.md:
getauxval, notgetrandom, is what is forces the minimum API level as of now.See commits d041b73, 1897790, and 904cad6.
Thanks for your help!