diff options
author | ru <ru@FreeBSD.org> | 2009-10-20 16:36:51 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2009-10-20 16:36:51 +0000 |
commit | 8bb7f5309bf62bb21a6bc77ddbe7f2c67f8d8f0d (patch) | |
tree | 23890c4ec64fce2a9ff4295f6e7cd69e571d097f /sys/kern/init_main.c | |
parent | 7a2f24399a43897e9175a59961eec097338a6703 (diff) | |
download | FreeBSD-src-8bb7f5309bf62bb21a6bc77ddbe7f2c67f8d8f0d.zip FreeBSD-src-8bb7f5309bf62bb21a6bc77ddbe7f2c67f8d8f0d.tar.gz |
Random number generator initialization cleanup:
- Introduce new SI_SUB_RANDOM point in boot sequence to make it
clear from where one may start using random(9). It should be as
early as possible, so place it just after SI_SUB_CPU where we
have some randomness on most platforms via get_cyclecount().
- Move stack protector initialization to be after SI_SUB_RANDOM
as before this point we have no randomness at all. This fixes
stack protector to actually protect stack with some random guard
value instead of a well-known one.
Note that this patch doesn't try to address arc4random(9) issues.
With current code, it will be implicitly seeded by stack protector
and hence will get the same entropy as random(9). It will be
securely reseeded once /dev/random is feeded by some entropy from
userland.
Submitted by: Maxim Dounin <mdounin@mdounin.ru>
MFC after: 3 days
Diffstat (limited to 'sys/kern/init_main.c')
-rw-r--r-- | sys/kern/init_main.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 0af22fa..f1508c8 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -570,6 +570,19 @@ proc0_post(void *dummy __unused) } SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post, NULL); +static void +random_init(void *dummy __unused) +{ + + /* + * After CPU has been started we have some randomness on most + * platforms via get_cyclecount(). For platforms that don't + * we will reseed random(9) in proc0_post() as well. + */ + srandom(get_cyclecount()); +} +SYSINIT(random, SI_SUB_RANDOM, SI_ORDER_FIRST, random_init, NULL); + /* *************************************************************************** **** |