Module Name: src Committed By: tls Date: Sun Aug 10 08:10:31 UTC 2014
Modified Files: src/sys/conf [tls-earlyentropy]: files src/sys/kern [tls-earlyentropy]: init_main.c subr_prf.c Log Message: The printf entropy source seems to have a lock-recursion problem. Temporarily disable it unless options RND_PRINTF is set. To generate a diff of this commit: cvs rdiff -u -r1.1090.2.3 -r1.1090.2.4 src/sys/conf/files cvs rdiff -u -r1.454.2.3 -r1.454.2.4 src/sys/kern/init_main.c cvs rdiff -u -r1.153.2.3 -r1.153.2.4 src/sys/kern/subr_prf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/conf/files diff -u src/sys/conf/files:1.1090.2.3 src/sys/conf/files:1.1090.2.4 --- src/sys/conf/files:1.1090.2.3 Sun Aug 10 06:54:36 2014 +++ src/sys/conf/files Sun Aug 10 08:10:31 2014 @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1090.2.3 2014/08/10 06:54:36 tls Exp $ +# $NetBSD: files,v 1.1090.2.4 2014/08/10 08:10:31 tls Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20100430 @@ -116,6 +116,9 @@ defflag opt_gre.h GRE_DEBUG defflag opt_wapbl.h WAPBL WAPBL_DEBUG defparam opt_wapbl.h WAPBL_DEBUG_PRINT +# printf entropy source +defflag opt_rnd_printf.h RND_PRINTF + # compatibility options # defflag opt_compat_netbsd.h COMPAT_NETBSD Index: src/sys/kern/init_main.c diff -u src/sys/kern/init_main.c:1.454.2.3 src/sys/kern/init_main.c:1.454.2.4 --- src/sys/kern/init_main.c:1.454.2.3 Sun Aug 10 06:55:58 2014 +++ src/sys/kern/init_main.c Sun Aug 10 08:10:31 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.454.2.3 2014/08/10 06:55:58 tls Exp $ */ +/* $NetBSD: init_main.c,v 1.454.2.4 2014/08/10 08:10:31 tls Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.454.2.3 2014/08/10 06:55:58 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.454.2.4 2014/08/10 08:10:31 tls Exp $"); #include "opt_ddb.h" #include "opt_ipsec.h" @@ -112,6 +112,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c, #include "opt_compat_netbsd.h" #include "opt_wapbl.h" #include "opt_ptrace.h" +#include "opt_rnd_printf.h" #include "drvctl.h" #include "ksyms.h" @@ -529,8 +530,10 @@ main(void) /* Enable deferred processing of RNG samples */ rnd_init_softint(); +#ifdef RND_PRINTF /* Enable periodic injection of console output into entropy pool */ kprintf_init_callout(); +#endif #ifdef SYSVSHM /* Initialize System V style shared memory. */ Index: src/sys/kern/subr_prf.c diff -u src/sys/kern/subr_prf.c:1.153.2.3 src/sys/kern/subr_prf.c:1.153.2.4 --- src/sys/kern/subr_prf.c:1.153.2.3 Thu Jul 17 14:03:33 2014 +++ src/sys/kern/subr_prf.c Sun Aug 10 08:10:31 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_prf.c,v 1.153.2.3 2014/07/17 14:03:33 tls Exp $ */ +/* $NetBSD: subr_prf.c,v 1.153.2.4 2014/08/10 08:10:31 tls Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -37,12 +37,13 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.153.2.3 2014/07/17 14:03:33 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.153.2.4 2014/08/10 08:10:31 tls Exp $"); #include "opt_ddb.h" #include "opt_ipkdb.h" #include "opt_kgdb.h" #include "opt_dump.h" +#include "opt_rnd_printf.h" #include <sys/param.h> #include <sys/stdint.h> @@ -75,7 +76,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v #endif static kmutex_t kprintf_mtx; -static bool kprintf_inited = false, kprintf_inited_callout = false; +static bool kprintf_inited = false; #ifdef KGDB #include <sys/kgdb.h> @@ -113,11 +114,14 @@ long panicstart, panicend; /* position i end of the formatted panicstr. */ int doing_shutdown; /* set to indicate shutdown in progress */ +#ifdef RND_PRINTF +static bool kprintf_inited_callout = false; static SHA512_CTX kprnd_sha; static uint8_t kprnd_accum[SHA512_DIGEST_LENGTH]; static int kprnd_added; static struct callout kprnd_callout; +#endif #ifndef DUMP_ON_PANIC #define DUMP_ON_PANIC 1 @@ -142,6 +146,7 @@ const char HEXDIGITS[] = "0123456789ABCD * functions */ +#ifdef RND_PRINTF static void kprintf_rnd_get(size_t bytes, void *priv) { if (kprnd_added) { @@ -167,6 +172,8 @@ static void kprintf_rnd_callout(void *ar callout_schedule(&kprnd_callout, hz); } +#endif + /* * Locking is inited fairly early in MI bootstrap. Before that * prints are done unlocked. But that doesn't really matter, @@ -177,11 +184,14 @@ kprintf_init(void) { KASSERT(!kprintf_inited && cold); /* not foolproof, but ... */ +#ifdef RND_PRINTF SHA512_Init(&kprnd_sha); +#endif mutex_init(&kprintf_mtx, MUTEX_DEFAULT, IPL_HIGH); kprintf_inited = true; } +#ifdef RND_PRINTF void kprintf_init_callout(void) { @@ -191,6 +201,7 @@ kprintf_init_callout(void) callout_schedule(&kprnd_callout, hz); kprintf_inited_callout = true; } +#endif void kprintf_lock(void) @@ -450,9 +461,10 @@ addlog(const char *fmt, ...) static void putchar(int c, int flags, struct tty *tp) { +#ifdef RND_PRINTF uint8_t rbuf[SHA512_BLOCK_LENGTH]; static int cursor; - +#endif if (panicstr) constty = NULL; if ((flags & TOCONS) && tp == NULL && constty) { @@ -475,6 +487,7 @@ putchar(int c, int flags, struct tty *tp } #endif +#ifdef RND_PRINTF if (__predict_true(kprintf_inited)) { rbuf[cursor] = c; if (cursor == sizeof(rbuf) - 1) { @@ -485,6 +498,7 @@ putchar(int c, int flags, struct tty *tp cursor++; } } +#endif } /* @@ -1536,7 +1550,8 @@ done: (*v_flush)(); (void)nanotime(&ts); +#ifdef RND_PRINTF SHA512_Update(&kprnd_sha, (char *)&ts, sizeof(ts)); - +#endif return ret; }