freebsd-dev/sys
Conrad Meyer 13774e8228 random(4): Block read_random(9) on initial seeding
read_random() is/was used, mostly without error checking, in a lot of
very sensitive places in the kernel -- including seeding the widely used
arc4random(9).

Most uses, especially arc4random(9), should block until the device is seeded
rather than proceeding with a bogus or empty seed.  I did not spy any
obvious kernel consumers where blocking would be inappropriate (in the
sense that lack of entropy would be ok -- I did not investigate locking
angle thoroughly).  In many instances, arc4random_buf(9) or that family
of APIs would be more appropriate anyway; that work was done in r345865.

A minor cleanup was made to the implementation of the READ_RANDOM function:
instead of using a variable-length array on the stack to temporarily store
all full random blocks sufficient to satisfy the requested 'len', only store
a single block on the stack.  This has some benefit in terms of reducing
stack usage, reducing memcpy overhead and reducing devrandom output leakage
via the stack.  Additionally, the stack block is now safely zeroed if it was
used.

One caveat of this change is that the kern.arandom sysctl no longer returns
zero bytes immediately if the random device is not seeded.  This means that
FreeBSD-specific userspace applications which attempted to handle an
unseeded random device may be broken by this change.  If such behavior is
needed, it can be replaced by the more portable getrandom(2) GRND_NONBLOCK
option.

On any typical FreeBSD system, entropy is persisted on read/write media and
used to seed the random device very early in boot, and blocking is never a
problem.

This change primarily impacts the behavior of /dev/random on embedded
systems with read-only media that do not configure "nodevice random".  We
toggle the default from 'charge on blindly with no entropy' to 'block
indefinitely.'  This default is safer, but may cause frustration.  Embedded
system designers using FreeBSD have several options.  The most obvious is to
plan to have a small writable NVRAM or NAND to persist entropy, like larger
systems.  Early entropy can be fed from any loader, or by writing directly
to /dev/random during boot.  Some embedded SoCs now provide a fast hardware
entropy source; this would also work for quickly seeding Fortuna.  A 3rd
option would be creating an embedded-specific, more simplistic random
module, like that designed by DJB in [1] (this design still requires a small
rewritable media for forward secrecy).  Finally, the least preferred option
might be "nodevice random", although I plan to remove this in a subsequent
revision.

To help developers emulate the behavior of these embedded systems on
ordinary workstations, the tunable kern.random.block_seeded_status was
added.  When set to 1, it blocks the random device.

I attempted to document this change in random.4 and random.9 and ran into a
bunch of out-of-date or irrelevant or inaccurate content and ended up
rototilling those documents more than I intended to.  Sorry.  I think
they're in a better state now.

PR:		230875
Reviewed by:	delphij, markm (earlier version)
Approved by:	secteam(delphij), devrandom(markm)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D19744
2019-04-15 18:40:36 +00:00
..
amd64 Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
arm Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
arm64 Merge ACPICA 20190329. 2019-03-29 20:21:28 +00:00
bsm Create new EINTEGRITY error with message "Integrity check failed". 2019-01-17 06:35:45 +00:00
cam Add new fields to mmc_data in preparation to SDIO CMD53 block mode support 2019-04-10 19:49:35 +00:00
cddl powerpc/dtrace: Fix dtrace powerpc asm, and simplify stack walking 2019-04-13 03:32:21 +00:00
compat Regen after r345982. 2019-04-06 09:37:10 +00:00
conf Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
contrib The nvlist_report_missing is also used by the cnvlist. 2019-04-11 04:24:41 +00:00
crypto Embedded chacha: Add 0-bit iv + 128-bit counter mode 2019-03-01 23:30:23 +00:00
ddb ddb: Print the thread's pcb in 'show thread' 2019-02-09 21:08:19 +00:00
dev random(4): Block read_random(9) on initial seeding 2019-04-15 18:40:36 +00:00
dts arm: dts: Remove some old DTS 2019-04-10 19:18:05 +00:00
fs Fix the NFSv4 client to safely find processes. 2019-04-15 01:27:15 +00:00
gdb
geom Implement automatic online expansion of GELI providers - if the underlying 2019-04-03 23:57:37 +00:00
gnu Import DTS files from Linux 5.0 2019-04-10 18:15:36 +00:00
i386 Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
isa
kern random(4): Block read_random(9) on initial seeding 2019-04-15 18:40:36 +00:00
kgssapi * Handle SIGPIPE in gssd 2019-02-21 01:30:37 +00:00
libkern random(4): Block read_random(9) on initial seeding 2019-04-15 18:40:36 +00:00
mips The Atheros AR7241 has 20 GPIO pins 2019-03-25 07:48:52 +00:00
modules Add support for INET6 addresses to the kernel code that dumps open/lock state. 2019-04-13 22:00:09 +00:00
net When sending a routing message, don't allow the user to set the 2019-04-14 10:18:14 +00:00
net80211 net80211: correct check for SMPS node flags updates 2019-03-18 02:40:22 +00:00
netgraph Remove 'dir' argument in ng_ipfw_input, since ip_fw_args now has this info. 2019-03-14 22:30:05 +00:00
netinet When sending IPv4 packets on a SOCK_RAW socket using the IP_HDRINCL option, 2019-04-13 10:47:47 +00:00
netinet6 Reinitialize multicast source filter structures after invalidation. 2019-04-11 08:00:59 +00:00
netipsec Replace read_random(9) with more appropriate arc4rand(9) KPIs 2019-04-04 01:02:50 +00:00
netpfil Use IN_foo() macros from sys/netinet/in.h inplace of handcrafted code 2019-04-04 19:01:13 +00:00
netsmb Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
nfs
nfsclient
nfsserver
nlm
ofed Mechanical cleanup of epoch(9) usage in network stack. 2019-01-09 01:11:19 +00:00
opencrypto Fix another bug introduced during the review process of r344140: 2019-02-25 19:14:16 +00:00
powerpc Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
riscv RISC-V: initialize pcpu slightly earlier 2019-04-07 20:12:24 +00:00
rpc Fix malloc stats for the RPCSEC_GSS server code when DEBUG is enabled. 2019-04-04 01:23:06 +00:00
security Create kernel module to parse Veriexec manifest based on envs 2019-04-03 03:57:37 +00:00
sparc64 Move mpr/mps drivers from per-arch NOTES files into the MI notes 2019-04-13 06:30:45 +00:00
sys random(4): Block read_random(9) on initial seeding 2019-04-15 18:40:36 +00:00
teken Attempt to complete fixing programmable function keys for syscons. 2019-02-20 02:14:41 +00:00
tests Regularize the Netflix copyright 2019-02-04 21:28:25 +00:00
tools make_dtb.sh: Use $CPP instead of assuming that cpp is in $PATH 2018-12-14 23:53:28 +00:00
ufs Handle races when remounting UFS volume from ro to rw. 2019-04-08 15:20:05 +00:00
vm for a cache-only zone the destructor tries to destroy a non-existent keg 2019-04-12 12:46:25 +00:00
x86 pci_cfgreg.c: Use io port config access for early boot time. 2019-04-09 18:07:17 +00:00
xdr
xen xen: introduce a new way to setup event channel upcall 2019-01-30 11:34:52 +00:00
Makefile