Skip to content
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

Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD. #66092

Merged
merged 2 commits into from
Nov 6, 2019

Conversation

alarixnia
Copy link
Contributor

This system call is present on all supported NetBSD versions and provides an endless stream of non-blocking random data from the kernel's ChaCha20-based CSPRNG. It doesn't require a file like /dev/urandom to be opened.

The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0

And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273

The semantics are the same as FreeBSD so reading 256 bytes per call is fine.

Similar change for getrandom crate: rust-random/getrandom#115

This system call is present on all supported NetBSD versions and
provides an endless stream of non-blocking random data from the
kernel's ChaCha20-based CSPRNG. It doesn't require a file descriptor
to be opened.

The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0

And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273

The semantics are the same as FreeBSD so reading 256 bytes per call
is fine.

Similar change for getrandom crate: rust-random/getrandom#115
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 4, 2019
@jonas-schievink jonas-schievink added O-netbsd Operating system: NetBSD T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 4, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-04T17:23:58.7372421Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-04T17:23:58.7581797Z ##[command]git config gc.auto 0
2019-11-04T17:23:58.7659002Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-04T17:23:58.7726173Z ##[command]git config --get-all http.proxy
2019-11-04T17:23:58.7881493Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66092/merge:refs/remotes/pull/66092/merge
---
2019-11-04T17:31:07.1728770Z    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
2019-11-04T17:31:09.1484026Z error: multiple `cfg` predicates are specified
2019-11-04T17:31:09.1493089Z    --> src/libstd/sys/unix/rand.rs:146:30
2019-11-04T17:31:09.1493563Z     |
2019-11-04T17:31:09.1493853Z 146 | #[cfg(target_os = "freebsd", target_os = "netbsd")]
2019-11-04T17:31:09.1494211Z 
2019-11-04T17:31:09.1494646Z error[E0428]: the name `imp` is defined multiple times
2019-11-04T17:31:09.1494928Z    --> src/libstd/sys/unix/rand.rs:147:1
2019-11-04T17:31:09.1496078Z     |
2019-11-04T17:31:09.1496078Z     |
2019-11-04T17:31:09.1496437Z 21  | mod imp {
2019-11-04T17:31:09.1496801Z     | ------- previous definition of the module `imp` here
2019-11-04T17:31:09.1497015Z ...
2019-11-04T17:31:09.1497415Z 147 | mod imp {
2019-11-04T17:31:09.1497734Z     | ^^^^^^^ `imp` redefined here
2019-11-04T17:31:09.1498258Z     = note: `imp` must be defined only once in the type namespace of this module
2019-11-04T17:31:09.1498320Z 
2019-11-04T17:31:09.1498320Z 
2019-11-04T17:31:09.1498583Z error[E0425]: cannot find value `CTL_KERN` in crate `libc`
2019-11-04T17:31:09.1499043Z    --> src/libstd/sys/unix/rand.rs:151:26
2019-11-04T17:31:09.1499275Z     |
2019-11-04T17:31:09.1499559Z 151 |         let mib = [libc::CTL_KERN, libc::KERN_ARND];
2019-11-04T17:31:09.1499877Z     |                          ^^^^^^^^ not found in `libc`
2019-11-04T17:31:09.1499951Z 
2019-11-04T17:31:09.1500215Z error[E0425]: cannot find value `KERN_ARND` in crate `libc`
2019-11-04T17:31:09.1500466Z    --> src/libstd/sys/unix/rand.rs:151:42
2019-11-04T17:31:09.1500690Z     |
2019-11-04T17:31:09.1500971Z 151 |         let mib = [libc::CTL_KERN, libc::KERN_ARND];
2019-11-04T17:31:09.1501313Z     |                                          ^^^^^^^^^ not found in `libc`
2019-11-04T17:31:11.2315310Z error[E0308]: mismatched types
2019-11-04T17:31:11.2316639Z    --> src/libstd/sys/unix/rand.rs:158:30
2019-11-04T17:31:11.2317149Z     |
2019-11-04T17:31:11.2317607Z 158 | ...                   ptr::null(), 0)
2019-11-04T17:31:11.2317607Z 158 | ...                   ptr::null(), 0)
2019-11-04T17:31:11.2318195Z     |                       ^^^^^^^^^^^ types differ in mutability
2019-11-04T17:31:11.2318633Z     |
2019-11-04T17:31:11.2319134Z     = note: expected type `*mut libc::c_void`
2019-11-04T17:31:11.2319573Z                found type `*const _`
2019-11-04T17:31:11.3021461Z error: aborting due to 5 previous errors
2019-11-04T17:31:11.3022380Z 
2019-11-04T17:31:11.3022989Z Some errors have detailed explanations: E0308, E0425, E0428.
2019-11-04T17:31:11.3023425Z For more information about an error, try `rustc --explain E0308`.
---
2019-11-04T17:31:11.3518027Z   local time: Mon Nov  4 17:31:11 UTC 2019
2019-11-04T17:31:11.5109221Z   network time: Mon, 04 Nov 2019 17:31:11 GMT
2019-11-04T17:31:11.5116188Z == end clock drift check ==
2019-11-04T17:31:14.3831320Z 
2019-11-04T17:31:14.3941353Z ##[error]Bash exited with code '1'.
2019-11-04T17:31:14.3968050Z ##[section]Starting: Checkout
2019-11-04T17:31:14.3969694Z ==============================================================================
2019-11-04T17:31:14.3969921Z Task         : Get sources
2019-11-04T17:31:14.3969966Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa
Copy link
Member

nagisa commented Nov 6, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Nov 6, 2019

📌 Commit b4f92ea has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2019
Centril added a commit to Centril/rust that referenced this pull request Nov 6, 2019
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.

This system call is present on all supported NetBSD versions and provides an endless stream of non-blocking random data from the kernel's ChaCha20-based CSPRNG. It doesn't require a file like `/dev/urandom` to be opened.

The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0

And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273

The semantics are the same as FreeBSD so reading 256 bytes per call is fine.

Similar change for getrandom crate: rust-random/getrandom#115
bors added a commit that referenced this pull request Nov 6, 2019
Rollup of 9 pull requests

Successful merges:

 - #65776 (Rename `LocalInternedString` and more)
 - #65973 (caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.)
 - #66015 (librustc_lexer: Refactor the module)
 - #66062 (Configure LLVM module PIC level)
 - #66086 (bump smallvec to 1.0)
 - #66092 (Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.)
 - #66103 (Add target thumbv7neon-unknown-linux-musleabihf)
 - #66133 (Update the bundled `wasi-libc` repository)
 - #66139 (use American spelling for `pluralize!`)

Failed merges:

r? @ghost
@bors bors merged commit b4f92ea into rust-lang:master Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-netbsd Operating system: NetBSD S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants