[Bug 219464] [PATCH] linux_getrandom always returns 0
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Mon May 22 20:21:57 UTC 2017
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219464
Bug ID: 219464
Summary: [PATCH] linux_getrandom always returns 0
Product: Base System
Version: CURRENT
Hardware: Any
OS: Any
Status: New
Keywords: patch
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: freebsd-bugs at FreeBSD.org
Reporter: maciej at pasternacki.net
Created attachment 182818
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=182818&action=edit
linux_getrandom.patch
In a Linux-based jail, running Ubuntu 16.04, `lsb_release` command (which is
widely used in various scripts and during Factorio startup) hangs. `top` shows
it forks a `python3.5` process which uses 100% CPU. `truss` shows this process
repeatedly calls `linux_getrandom(…)`, which always returns 0.
`man 2 getrandom` on Ubuntu 16.04 specifies that this syscall should return
number of random bytes written
(http://man7.org/linux/man-pages/man2/getrandom.2.html). A short test program
shows that this it returns positive value on Linux, and returns 0 on FreeBSD
despite the fact that random bytes have been written to the buffer:
> $ cat test_getrandom.c
> #define _GNU_SOURCE
> #include <unistd.h>
> #include <sys/syscall.h>
> #include <stdio.h>
> #include <linux/random.h>
>
> int main(void) {
> int rv;
> int buf = 0;
> rv = syscall(SYS_getrandom, &buf, sizeof(buf), GRND_NONBLOCK);
> printf("getrandom(&buf, %d, 0) => %d buf=%d\n", (int)sizeof(buf), rv, buf);
> return 0;
> }
When this program runs natively on Linux, `getrandom(2)` returns size of
buffer:
> $ ./test_getrandom
> getrandom(&buf, 4, 0) => 4 buf=-707083248
On FreeBSD 12-CURRENT (possibly also on 11-STABLE, r315505 which introduces
this implementation is marked for MFC after 1 month), the syscall always
returns 0:
> $ ./test_getrandom
> getrandom(&buf, 4, 0) => 0 buf=-1643413282
After applying attached patch, return value reported from the test program is
the same as on native Linux, and `lsb_release` no longer hangs:
> $ ./test_getrandom
> getrandom(&buf, 4, 0) => 4 buf=-943351330
> $ lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu 16.04.2 LTS
> Release: 16.04
> Codename: xenial
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list