freebsd-skq/sys
cem 2a885b6c3a Fortuna: Fix a race to prevent reseed spamming
If multiple threads enter fortuna_pre_read contemporaneously, such as via
read(2) or getrandom(2), they could race to check how long it has been since
the last update due to a TOCTOU problem with 'now'.

Here is an example problematic execution:

Thread A:                       Thread B:
now_A = getsbinuptime();
                                now_B = getsbinuptime();  // now_B > now_A
                                RANDOM_RESEED_LOCK();
                                if (now - fs_lasttime > SBT_1S/10) {
                                        fs_lasttime = now;
                                        ... // reseed
                                }
                                RANDOM_RESEED_UNLOCK();
RANDOM_RESEED_LOCK();
if (now_A - fs_lasttime > SBT_1S/10)  // now_A - fs_lasttime underflows
        fs_lasttime = now_A;
        ... // reseed again, despite less than 100ms elapsing
}
RANDOM_RESEED_UNLOCK();

To resolve the race, simply check the current time after we win the lock
race.

If getsbinuptime is perceived to be expensive, another option might be to
just accept the race and validate that fs_lasttime isn't "in the future."
(It should be within the last ~2^31 seconds out of ~2^32 seconds
representable duration.)

Reviewed by:	delphij, markm
Approved by:	secteam (delphij)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D16984
2018-10-20 21:09:12 +00:00
..
amd64 Add an assertion to pmap_enter(). 2018-10-20 20:53:35 +00:00
arm Revert r339421 due to unintended files included to commit. 2018-10-18 15:17:58 +00:00
arm64 MFH r339206-r339212, r339215-r339239 2018-10-08 18:06:40 +00:00
bsm
cam Move 32-bit compat support for CDIOREADTOCENTRYS to the right place. 2018-10-02 23:23:56 +00:00
cddl Skip VDEV_IO_DONE stage only for ZIO_TYPE_FREE. 2018-10-15 21:59:24 +00:00
compat Correct COMPAT* macro names in syscalls.master 2018-10-15 21:35:57 +00:00
conf Now that we've branched, turn off building DRM and DRM2 by default. 2018-10-20 19:18:30 +00:00
contrib Import CK as of commit 5221ae2f3722a78c7fc41e47069ad94983d3bccb. 2018-10-16 02:30:13 +00:00
crypto Reapply, with minor tweaks, r338025, from the original commit: 2018-09-26 17:12:14 +00:00
ddb ddb: Enable 'thread <address>' 2018-10-20 20:45:49 +00:00
dev Fortuna: Fix a race to prevent reseed spamming 2018-10-20 21:09:12 +00:00
dts Revert r339421 due to unintended files included to commit. 2018-10-18 15:17:58 +00:00
fs MFH r338661 through r339253. 2018-10-09 14:27:55 +00:00
gdb
geom MFH r338661 through r339200. 2018-10-05 17:53:47 +00:00
gnu dts: Import DTS for arm64 2018-08-23 13:21:01 +00:00
i386 Add an assertion to pmap_enter(). 2018-10-20 20:53:35 +00:00
isa Reapply, with minor tweaks, r338025, from the original commit: 2018-09-26 17:12:14 +00:00
kern dev_refthread: Do not initialize *ref when reference was not acquired 2018-10-20 19:42:38 +00:00
kgssapi
libkern
mips Re-enable kernel modules for the MALTA64EL kernel configuration. 2018-09-06 19:21:31 +00:00
modules Fix modules/nvdimm build issues after r339391 by adding a dependency 2018-10-18 00:51:42 +00:00
net Fix deadlock when destroying VLANs. 2018-10-15 10:29:29 +00:00
net80211 Fix misspellings of transmitter/transmitted 2018-08-10 20:37:32 +00:00
netgraph Remove the Yarrow PRNG algorithm option in accordance with due notice 2018-08-26 12:51:46 +00:00
netinet The handling of RST segments in the SYN-RCVD state exists in the 2018-10-18 19:21:18 +00:00
netinet6 MFH r338661 through r339253. 2018-10-09 14:27:55 +00:00
netipsec Fix witness warning in xform_init(). 2018-09-26 14:47:51 +00:00
netpfil pf synproxy will do the 3WHS on behalf of the target machine, and once 2018-10-20 18:37:21 +00:00
netsmb Make timespecadd(3) and friends public 2018-07-30 15:46:40 +00:00
nfs
nfsclient
nfsserver
nlm
ofed Introduce and use sgid_index in CM requests in ibcore. 2018-09-09 07:20:15 +00:00
opencrypto Add per-session locking to cryptosoft (swcr). 2018-09-26 20:23:12 +00:00
powerpc Initialize SPRG0 before its first possible use 2018-10-15 16:43:07 +00:00
riscv Support RISC-V implementations that do not manage the A and D bits 2018-10-18 15:25:07 +00:00
rpc Set SO_SNDTIMEO in the client side krpc when CLSET_TIMEOUT is done. 2018-07-20 12:03:16 +00:00
security Rework the logic around quick checks for auditing that take place at 2018-10-02 15:58:17 +00:00
sparc64 Prepare the kernel linker to handle PC-relative ifunc relocations. 2018-08-22 20:44:30 +00:00
sys random(4): Translate a comment requirement into a compile-time invariant 2018-10-20 20:49:37 +00:00
teken
tests
tools make_dtb: Always add root directory in the include path 2018-08-23 13:23:21 +00:00
ufs Correct panic messages. 2018-09-22 17:05:49 +00:00
vm Create some global domainsets and refactor NUMA registration. 2018-10-20 17:36:00 +00:00
x86 Create some global domainsets and refactor NUMA registration. 2018-10-20 17:36:00 +00:00
xdr
xen xen: legacy PVH fixes for the new interrupt count 2018-09-13 07:14:11 +00:00
Makefile