aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2009-10-24 04:55:14 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2009-10-24 04:55:14 +0000
commitf47552e770ac51134e605d93efd6c534b2809388 (patch)
tree0483c4d2594c00ada1aeb80547a753779f4480c9
parent115753ce9eb755279fea668547d1692b4ec06ddf (diff)
downloadsrc-f47552e770ac51134e605d93efd6c534b2809388.tar.gz
src-f47552e770ac51134e605d93efd6c534b2809388.zip
MFC r198295:
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> Approved by: re (kib)
Notes
Notes: svn path=/stable/8/; revision=198434
-rw-r--r--sys/kern/init_main.c13
-rw-r--r--sys/kern/stack_protector.c3
-rw-r--r--sys/sys/kernel.h1
3 files changed, 15 insertions, 2 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index ce0ea9e6d062..668ca1a1c57f 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -557,6 +557,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);
+
/*
***************************************************************************
****
diff --git a/sys/kern/stack_protector.c b/sys/kern/stack_protector.c
index 554d47d0a833..b5f9973e24cf 100644
--- a/sys/kern/stack_protector.c
+++ b/sys/kern/stack_protector.c
@@ -28,5 +28,4 @@ __stack_chk_init(void *dummy __unused)
for (i = 0; i < __arraycount(guard); i++)
__stack_chk_guard[i] = guard[i];
}
-/* SI_SUB_EVENTHANDLER is right after SI_SUB_LOCK used by arc4rand() init. */
-SYSINIT(stack_chk, SI_SUB_EVENTHANDLER, SI_ORDER_ANY, __stack_chk_init, NULL);
+SYSINIT(stack_chk, SI_SUB_RANDOM, SI_ORDER_ANY, __stack_chk_init, NULL);
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index 5461dfd2b96e..1a9cb5cd003d 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -109,6 +109,7 @@ enum sysinit_sub_id {
SI_SUB_VNET_PRELINK = 0x1E00000, /* vnet init before modules */
SI_SUB_KLD = 0x2000000, /* KLD and module setup */
SI_SUB_CPU = 0x2100000, /* CPU resource(s)*/
+ SI_SUB_RANDOM = 0x2120000, /* random number generator */
SI_SUB_KDTRACE = 0x2140000, /* Kernel dtrace hooks */
SI_SUB_MAC = 0x2180000, /* TrustedBSD MAC subsystem */
SI_SUB_MAC_POLICY = 0x21C0000, /* TrustedBSD MAC policies */