Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/tls-earlyentropy]: src/sys The printf entropy source seems to have a loc...



details:   https://anonhg.NetBSD.org/src/rev/46e082d1847b
branches:  tls-earlyentropy
changeset: 795279:46e082d1847b
user:      tls <tls%NetBSD.org@localhost>
date:      Sun Aug 10 08:10:31 2014 +0000

description:
The printf entropy source seems to have a lock-recursion problem.
Temporarily disable it unless options RND_PRINTF is set.

diffstat:

 sys/conf/files       |   5 ++++-
 sys/kern/init_main.c |   7 +++++--
 sys/kern/subr_prf.c  |  25 ++++++++++++++++++++-----
 3 files changed, 29 insertions(+), 8 deletions(-)

diffs (182 lines):

diff -r ce5cd636147d -r 46e082d1847b sys/conf/files
--- a/sys/conf/files    Sun Aug 10 06:51:22 2014 +0000
+++ b/sys/conf/files    Sun Aug 10 08:10:31 2014 +0000
@@ -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_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
diff -r ce5cd636147d -r 46e082d1847b sys/kern/init_main.c
--- a/sys/kern/init_main.c      Sun Aug 10 06:51:22 2014 +0000
+++ b/sys/kern/init_main.c      Sun Aug 10 08:10:31 2014 +0000
@@ -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 @@
 #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 @@
        /* 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. */
diff -r ce5cd636147d -r 46e082d1847b sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c       Sun Aug 10 06:51:22 2014 +0000
+++ b/sys/kern/subr_prf.c       Sun Aug 10 08:10:31 2014 +0000
@@ -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 @@
 #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 @@
                                   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 @@
  * functions
  */
 
+#ifdef RND_PRINTF
 static void kprintf_rnd_get(size_t bytes, void *priv)
 {
        if (kprnd_added)  {
@@ -167,6 +172,8 @@
        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 @@
 {
 
        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 @@
        callout_schedule(&kprnd_callout, hz);
        kprintf_inited_callout = true;
 }
+#endif
 
 void
 kprintf_lock(void)
@@ -450,9 +461,10 @@
 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 @@
        }
 #endif
 
+#ifdef RND_PRINTF
        if (__predict_true(kprintf_inited)) {
                rbuf[cursor] = c;
                if (cursor == sizeof(rbuf) - 1) {
@@ -485,6 +498,7 @@
                        cursor++;
                }
        }
+#endif
 }
 
 /*
@@ -1536,7 +1550,8 @@
        (*v_flush)();
 
        (void)nanotime(&ts);
+#ifdef RND_PRINTF
        SHA512_Update(&kprnd_sha, (char *)&ts, sizeof(ts));
-
+#endif
        return ret;
 }



Home | Main Index | Thread Index | Old Index