glibc/sysdeps/powerpc
Jason A. Donenfeld eaad4f9e8f arc4random: simplify design for better safety
Rather than buffering 16 MiB of entropy in userspace (by way of
chacha20), simply call getrandom() every time.

This approach is doubtlessly slower, for now, but trying to prematurely
optimize arc4random appears to be leading toward all sorts of nasty
properties and gotchas. Instead, this patch takes a much more
conservative approach. The interface is added as a basic loop wrapper
around getrandom(), and then later, the kernel and libc together can
work together on optimizing that.

This prevents numerous issues in which userspace is unaware of when it
really must throw away its buffer, since we avoid buffering all
together. Future improvements may include userspace learning more from
the kernel about when to do that, which might make these sorts of
chacha20-based optimizations more possible. The current heuristic of 16
MiB is meaningless garbage that doesn't correspond to anything the
kernel might know about. So for now, let's just do something
conservative that we know is correct and won't lead to cryptographic
issues for users of this function.

This patch might be considered along the lines of, "optimization is the
root of all evil," in that the much more complex implementation it
replaces moves too fast without considering security implications,
whereas the incremental approach done here is a much safer way of going
about things. Once this lands, we can take our time in optimizing this
properly using new interplay between the kernel and userspace.

getrandom(0) is used, since that's the one that ensures the bytes
returned are cryptographically secure. But on systems without it, we
fallback to using /dev/urandom. This is unfortunate because it means
opening a file descriptor, but there's not much of a choice. Secondly,
as part of the fallback, in order to get more or less the same
properties of getrandom(0), we poll on /dev/random, and if the poll
succeeds at least once, then we assume the RNG is initialized. This is a
rough approximation, as the ancient "non-blocking pool" initialized
after the "blocking pool", not before, and it may not port back to all
ancient kernels, though it does to all kernels supported by glibc
(≥3.2), so generally it's the best approximation we can do.

The motivation for including arc4random, in the first place, is to have
source-level compatibility with existing code. That means this patch
doesn't attempt to litigate the interface itself. It does, however,
choose a conservative approach for implementing it.

Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Cristian Rodríguez <crrodriguez@opensuse.org>
Cc: Paul Eggert <eggert@cs.ucla.edu>
Cc: Mark Harris <mark.hsj@gmail.com>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2022-07-27 08:58:27 -03:00
..
bits Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
fpu math: Add math-use-builtins-fabs (BZ#29027) 2022-05-23 17:49:18 -03:00
nofpu Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
nptl powerpc64: Set up thread register for _dl_relocate_static_pie 2022-04-10 08:33:40 +09:30
power4 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
power6 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
powerpc32 Add bounds check to __libc_ifunc_impl_list 2022-06-10 17:13:29 +01:00
powerpc64 arc4random: simplify design for better safety 2022-07-27 08:58:27 -03:00
sys/platform Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
abort-instr.h Update. 2002-09-15 18:31:23 +00:00
atomic-machine.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
cpu-features.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
cpu-features.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-lookupcfg.h elf: Issue la_symbind for bind-now (BZ #23734) 2022-02-01 14:49:46 -03:00
dl-procinfo.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-procinfo.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-tls.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-tls.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-tunables.list Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
elf-initfini.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ffs.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
fpu_control.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
gccframe.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
hwcapinfo.c powerpc64: Set up thread register for _dl_relocate_static_pie 2022-04-10 08:33:40 +09:30
hwcapinfo.h powerpc64: Set up thread register for _dl_relocate_static_pie 2022-04-10 08:33:40 +09:30
ifunc-sel.h Fix powerpc ifunc-sel.h build for -Os. 2018-03-02 22:27:56 +00:00
jmpbuf-offsets.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
jmpbuf-unwind.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ldsodefs.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
libc-tls.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
locale-defines.sym powerpc: strcasestr optmization for power8 2016-04-22 19:23:13 +05:30
longjmp.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
machine-gmon.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
Makefile powerpc: Fix unrecognized instruction errors with recent binutils 2021-09-29 14:42:20 -05:00
math-tests-snan-cast.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mod-cache-ppc.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mod-tlsopt-powerpc.c elf: Drop elf/tls-macros.h in favor of __thread and tls_model attributes [BZ #28152] [BZ #28205] 2021-08-16 09:59:30 -07:00
mp_clz_tab.c Update. 2002-03-14 20:48:50 +00:00
novmx-longjmp.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
novmx-sigjmp.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
novmxsetjmp.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
preconfigure powerpc: Add support for POWER10 2020-06-29 10:08:38 -03:00
preconfigure.ac powerpc: Add support for POWER10 2020-06-29 10:08:38 -03:00
rtld-global-offsets.sym powerpc: Move cache line size to rtld_global_ro 2020-01-17 09:05:03 -03:00
sigjmp.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sotruss-lib.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
stackinfo.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sysdep.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
test-arith.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
test-arithf.c Update. 1997-08-10 18:37:15 +00:00
test-get_hwcap-static.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
test-get_hwcap.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
test-gettimebase.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-cache-ppc-static-dlopen.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-cache-ppc-static.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-cache-ppc.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-set_ppr.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-stack-align.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-tlsifunc-static.c powerpc64: Set up thread register for _dl_relocate_static_pie 2022-04-10 08:33:40 +09:30
tst-tlsifunc.c elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 2022-04-26 09:26:22 -07:00
tst-tlsopt-powerpc.c tst-tlsopt-powerpc as a shared lib 2017-08-03 15:39:21 +09:30
Versions nptl: Move __pthread_unwind_next into libc 2021-04-21 19:49:50 +02:00