glibc/sysdeps/powerpc/powerpc64
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
..
a2 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
be arc4random: simplify design for better safety 2022-07-27 08:58:27 -03:00
bits Define wordsize.h macros everywhere 2016-11-04 09:37:44 -07:00
cell 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
le powerpc: Fix VSX register number on __strncpy_power9 [BZ #29197] 2022-06-07 15:07:25 -03:00
multiarch Add bounds check to __libc_ifunc_impl_list 2022-06-10 17:13:29 +01:00
power4 powerpc: Remove powerpc64 bzero optimizations 2022-02-23 14:18:18 -03:00
power6 powerpc: Remove powerpc64 bzero optimizations 2022-02-23 14:18:18 -03:00
power7 powerpc: Remove powerpc64 bzero optimizations 2022-02-23 14:18:18 -03:00
power8 arc4random: simplify design for better safety 2022-07-27 08:58:27 -03:00
__longjmp-common.S powerpc64: Use medium model toc accesses throughout 2022-04-10 08:33:06 +09:30
__longjmp.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
addmul_1.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
atomic-machine.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
bsd-_setjmp.S PowerPC64 ABI fixes 2010-08-12 09:19:19 -07:00
bsd-setjmp.S PowerPC64 ABI fixes 2010-08-12 09:19:19 -07:00
configure elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 2022-04-26 09:26:22 -07:00
configure.ac elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 2022-04-26 09:26:22 -07:00
crti.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
crtn.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-dtprocnum.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-funcdesc.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-irel.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-machine.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
dl-machine.h powerpc64: Set up thread register for _dl_relocate_static_pie 2022-04-10 08:33:40 +09:30
dl-trampoline.S powerpc64: Use medium model toc accesses throughout 2022-04-10 08:33:06 +09:30
ffsll.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
hp-timing.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
Implies Revert "Use ieee754/dbl-64/wordsize-64 on powerpc64" 2013-01-10 10:44:05 +01:00
lshift.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
Makefile Remove stale references to libdl.a 2021-06-09 19:14:02 +02:00
memcpy.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
memset.S powerpc: Remove powerpc64 bzero optimizations 2022-02-23 14:18:18 -03:00
mul_1.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ppc-mcount.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
rtld-memset.c powerpc: Use generic memset for RTLD for ppc32/64 2010-09-29 12:21:14 -04:00
setjmp-bug21895.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
setjmp-common.S powerpc64: Use medium model toc accesses throughout 2022-04-10 08:33:06 +09:30
setjmp.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
stackguard-macros.h PowerPC: Fix POINTER_CHK_GUARD thread register for PPC64 2013-09-25 13:43:04 -05:00
start.S powerpc64: Use medium model toc accesses throughout 2022-04-10 08:33:06 +09:30
strchr.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
strcmp.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
strlen.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
strncmp.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
submul_1.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sysdep.h powerpc64: Use medium model toc accesses throughout 2022-04-10 08:33:06 +09:30
tst-audit.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-setjmp-bug21895-static.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-ucontext-ppc64-vscr.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00