-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Unexpected getrandom error due to Linux kernel bug on QNAP #52609
Comments
I see there is a check in the code (
|
Is this sufficient to fix it? diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs
index 01c0ada4ff..967a517442 100644
--- a/src/libstd/sys/unix/rand.rs
+++ b/src/libstd/sys/unix/rand.rs
@@ -77,7 +77,7 @@ mod imp {
let result = getrandom(&mut buf);
let available = if result == -1 {
let err = io::Error::last_os_error().raw_os_error();
- err != Some(libc::ENOSYS)
+ err != Some(libc::ENOSYS) && err != Some(libc::EPERM)
} else {
true
}; |
I'm trying to reproduce this error with the minimal code. Will get back soon |
The problem is that QNAP kernel returns |
That’s very nonsensical error code usage by QNAP. I can understand |
I totally agree. |
It's also possible to handle this by providing the way to disable
|
According to https://bugs.php.net/bug.php?id=75409, receiving anything besides EINTR or EAGAIN should fallback to |
According to that page, it seems that PHP people aren’t really sure what should have been done either, other than that QNAP should fix their own stuff. Whatever they implemented is just them giving up on a sensible solution. My ultimate suggestion would be to apply a QNAP specific patch for whatever distribution is used by QNAP during compilation/packaging of their rustc package and use that rustc to compile all the rust code. |
It's very common in embedded software to have this type of bugs, which exist for many years without having a chance to fix it someday (including the fact, that some devices' firmware cannot be upgraded at all). If rust targets embedded development, there should always be a clear way on how to deal with it. Rebuilding rustc works, but it's very distracting and unsustainable from the development side. As of this QNAP bug, I fully agree, that I would suggest to refactor this code a bit and implement "random backends" with a clear strategy on how to deal with them. The default should be the same - auto-detect. But in addition to that, the developer would have a chance to select which particular random implementation to use (or even provide own?). I can image many cases where it may be useful, besides this horrible QNAP bug. |
The statement is true, but
For the user code this is absolutely a non-problem. Given that neither of those seem like a satisfactory solution, there already exists a mechanism to tailor for particularities of certain hosted system. Namely, the Bear in mind, that a new target does not necessarily imply that there would be binary artefacts (sysroot and/or librustc itself) for the target, in which case you’d still have to at least build your own sysroot for the target. |
Regardless of how we call it (embedded or embedded-like), there are still hundreds of millions of devices, including routers, NASes, IoT hubs, smart speakers, kiosks, IP cameras, etc. running Linux. And vendors typically provide their SDKs, with the modified kernel and *libc, which may work unpredictably sometimes. It sounds like the idea with custom target makes sense. Will try to use |
On a side note: |
Python treats |
When you'll decide on how to deal with this issue, please also send a patch to rand/getrandom. |
Nominating this. I propose we follow Python here, the rationale that seccomp can block getrandom seems reasonable to me. |
This was discussed recently at a libs triage meeting, and the conclusion was that following python's precedent of handling EPERM as well as ENOSYS makes sense for our usage of |
This can happen because of seccomp or some VMs. Fixes rust-lang#52609.
Fall back to `/dev/urandom` on `EPERM` for `getrandom` This can happen because of seccomp or some VMs. Fixes rust-lang#52609.
http://man7.org/linux/man-pages/man2/getrandom.2.html
|
Hi,
Rust code panics on linux 3.10:
Panic message:
Rustc from rustup, version
1.27.0
The code is running on Qnap NAS
Rust core library relies on
SYS_getrandom
which was introduced only in kernel version3.4.17
.The text was updated successfully, but these errors were encountered: