about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/getrandom.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright dates with scripts/update-copyrightsJoseph Myers2023-01-061-1/+1
|
* hurd: Make getrandom cache the server portSergey Bugaev2022-12-021-15/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, getrandom would, each time it's called, traverse the file system to find /dev/urandom, fetch some random data from it, then throw away that port. This is quite slow, while calls to getrandom are genrally expected to be fast. Additionally, this means that getrandom can not work when /dev/urandom is unavailable, such as inside a chroot that lacks one. User programs expect calls to getrandom to work inside a chroot if they first call getrandom outside of the chroot. In particular, this is known to break the OpenSSH server, and in that case the issue is exacerbated by the API of arc4random, which prevents it from properly reporting errors, forcing glibc to abort on failure. This causes sshd to just die once it tries to generate a random number. Caching the random server port, in a manner similar to how socket server ports are cached, both improves the performance and works around the chroot issue. Tested on i686-gnu with the following program: pthread_barrier_t barrier; void *worker(void*) { pthread_barrier_wait(&barrier); uint32_t sum = 0; for (int i = 0; i < 10000; i++) { sum += arc4random(); } return (void *)(uintptr_t) sum; } int main() { pthread_t threads[THREAD_COUNT]; pthread_barrier_init(&barrier, NULL, THREAD_COUNT); for (int i = 0; i < THREAD_COUNT; i++) { pthread_create(&threads[i], NULL, worker, NULL); } for (int i = 0; i < THREAD_COUNT; i++) { void *retval; pthread_join(threads[i], &retval); printf("Thread %i: %lu\n", i, (unsigned long)(uintptr_t) retval); } In my totally unscientific benchmark, with this patch, this completes in about 7 seconds, whereas previously it took about 50 seconds. This program was also used to test that getrandom () doesn't explode if the random server dies, but instead reopens the /dev/urandom anew. I have also verified that with this patch, OpenSSH can once again accept connections properly. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20221202135558.23781-1-bugaevc@gmail.com>
* Update copyright dates with scripts/update-copyrightsPaul Eggert2022-01-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
* hurd: Use __trivfs_server_name instead of trivfs_server_nameSamuel Thibault2022-01-011-9/+9
| | | | The latter violates namespace contraints
* hurd: Make getrandom a stub inside the random translatorSamuel Thibault2021-12-311-0/+13
| | | | | | glibc uses /dev/urandom for getrandom(), and from version 2.34 malloc initialization uses it. We have to detect when we are running the random translator itself, in which case we can't read ourself.
* Update copyright dates with scripts/update-copyrightsPaul Eggert2021-01-021-1/+1
| | | | | | | | | | | | | | | | I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 6694 files FOO. I then removed trailing white space from benchtests/bench-pthread-locks.c and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this diagnostic from Savannah: remote: *** pre-commit check failed ... remote: *** error: lines with trailing whitespace found remote: error: hook declined to update refs/heads/master
* Update copyright dates with scripts/update-copyrights.Joseph Myers2020-01-011-1/+1
|
* hurd: Make getrandom honour GRND_NONBLOCKJames Clarke2019-12-171-1/+5
| | | | | | * sysdeps/mach/hurd/getrandom.c (__getrandom): Open the random source with O_NONBLOCK when the GRND_NONBLOCK flag is provided. Message-Id: <20191217182929.90989-1-jrtc27@jrtc27.com>
* hurd: Fix local PLTSamuel Thibault2019-12-131-1/+4
| | | | | | | | | | * include/sys/random.h (__getrandom): Add hidden prototype. * stdlib/getrandom.c (getrandom): Rename to hidden definition __getrandom. Add weak alias. * sysdeps/mach/hurd/getrandom.c (getrandom): Likewise. * sysdeps/unix/sysv/linux/getrandom.c (getrandom): Likewise. * sysdeps/mach/hurd/getentropy.c (getentropy): Use __getrandom instead of getrandom.
* hurd: add getrandom and getentropy implementationsAndrew Eggenberger2019-12-131-0/+43
* sysdeps/mach/hurd/getentropy.c: New file. * sysdeps/mach/hurd/getrandom.c: Likewise.