diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2013-03-25 14:58:29 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2013-03-25 14:58:29 +0000 |
commit | 9e5b1f06effb0aefc0381cf2da1fcb10faa96101 (patch) | |
tree | d9a300b786ffd9ec6ee6810536bc83e48affbff5 | |
parent | cf815072e80de0903ef62b9259ecacf830a4b414 (diff) |
reseed the random pool with 'dmesg' when more devices are attached
from hshoexer@; ok tedu@, "looks good" deraadt@
-rw-r--r-- | sys/dev/rnd.c | 20 | ||||
-rw-r--r-- | sys/dev/rndvar.h | 3 | ||||
-rw-r--r-- | sys/kern/init_main.c | 4 |
3 files changed, 23 insertions, 4 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index cb7ebe491de..711cf14fc83 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rnd.c,v 1.141 2012/06/24 18:25:12 matthew Exp $ */ +/* $OpenBSD: rnd.c,v 1.142 2013/03/25 14:58:28 markus Exp $ */ /* * Copyright (c) 2011 Theo de Raadt. @@ -390,7 +390,7 @@ enqueue_randomness(int state, int val) rndstats.rnd_sb[state] += nbits; if (rnd_qlen() > QEVSLOW/2 && timeout_initialized(&rnd_timeout) && - timeout_pending(&rnd_timeout)) + !timeout_pending(&rnd_timeout)) timeout_add(&rnd_timeout, 1); done: mtx_leave(&entropylock); @@ -681,6 +681,12 @@ random_init(void) void random_start(void) { + /* + * On a cold start the message buffer does not contain any + * unique information yet, just the copyright message and the + * kernel version string. Unique information like MAC adresses + * will be added during autoconf. + */ if (msgbufp && msgbufp->msg_magic == MSG_MAGIC) add_entropy_words((u_int32_t *)msgbufp->msg_bufc, msgbufp->msg_bufs / sizeof(u_int32_t)); @@ -692,6 +698,16 @@ random_start(void) timeout_set(&rnd_timeout, dequeue_randomness, NULL); } +void +random_hostseed(void) +{ + if (msgbufp == NULL || msgbufp->msg_magic != MSG_MAGIC) + return; + add_entropy_words((u_int32_t *)msgbufp->msg_bufc, + msgbufp->msg_bufs / sizeof(u_int32_t)); + arc4_init(NULL, NULL); +} + int randomopen(dev_t dev, int flag, int mode, struct proc *p) { diff --git a/sys/dev/rndvar.h b/sys/dev/rndvar.h index 51e7b084095..9e57a2e2a76 100644 --- a/sys/dev/rndvar.h +++ b/sys/dev/rndvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rndvar.h,v 1.29 2011/01/08 19:45:08 deraadt Exp $ */ +/* $OpenBSD: rndvar.h,v 1.30 2013/03/25 14:58:28 markus Exp $ */ /* * Copyright (c) 1996,2000 Michael Shalayeff. @@ -76,6 +76,7 @@ extern struct rndstats rndstats; void random_init(void); void random_start(void); +void random_hostseed(void); void enqueue_randomness(int, int); void arc4random_buf(void *, size_t); diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 33ee8571bc1..7f87fd6f1c1 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.186 2013/01/01 19:39:50 jasper Exp $ */ +/* $OpenBSD: init_main.c,v 1.187 2013/03/25 14:58:28 markus Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -350,6 +350,8 @@ main(void *framep) /* Configure the devices */ cpu_configure(); + random_hostseed(); + /* Configure virtual memory system, set vm rlimits. */ uvm_init_limits(p); |