From owner-svn-src-stable@FreeBSD.ORG Sun Oct 13 00:13:58 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 396D37C; Sun, 13 Oct 2013 00:13:58 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2602227E3; Sun, 13 Oct 2013 00:13:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9D0DwDQ060771; Sun, 13 Oct 2013 00:13:58 GMT (envelope-from markm@svn.freebsd.org) Received: (from markm@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9D0DvpN060763; Sun, 13 Oct 2013 00:13:57 GMT (envelope-from markm@svn.freebsd.org) Message-Id: <201310130013.r9D0DvpN060763@svn.freebsd.org> From: Mark Murray Date: Sun, 13 Oct 2013 00:13:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r256414 - stable/10/sys/dev/random X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Oct 2013 00:13:58 -0000 Author: markm Date: Sun Oct 13 00:13:57 2013 New Revision: 256414 URL: http://svnweb.freebsd.org/changeset/base/256414 Log: MFC: There is an issue (not seen in our testing) where "yarrow" and "dummy" switch priorities, and the users are left with no usable /dev/random. The fix assigns priories to these and gives the users what they want. The override tuneable has a stupid name (blame me!) and this fixes it to be something that 'sysctl kern.random' emits and is the right thing to set. Approved by: re (gjb) Approved by: secteam (cperciva) Modified: stable/10/sys/dev/random/dummy_rng.c stable/10/sys/dev/random/random_adaptors.c stable/10/sys/dev/random/randomdev.h stable/10/sys/dev/random/randomdev_soft.c Modified: stable/10/sys/dev/random/dummy_rng.c ============================================================================== --- stable/10/sys/dev/random/dummy_rng.c Sun Oct 13 00:13:29 2013 (r256413) +++ stable/10/sys/dev/random/dummy_rng.c Sun Oct 13 00:13:57 2013 (r256414) @@ -102,6 +102,7 @@ struct random_adaptor dummy_random = { .read = (random_read_func_t *)random_null_func, .reseed = (random_reseed_func_t *)random_null_func, .seeded = 0, /* This device can never be seeded */ + .priority = 1, /* Bottom priority, so goes to last position */ }; static int Modified: stable/10/sys/dev/random/random_adaptors.c ============================================================================== --- stable/10/sys/dev/random/random_adaptors.c Sun Oct 13 00:13:29 2013 (r256413) +++ stable/10/sys/dev/random/random_adaptors.c Sun Oct 13 00:13:57 2013 (r256414) @@ -104,12 +104,13 @@ void random_adaptor_choose(struct random_adaptor **adaptor) { char rngs[128], *token, *cp; - struct random_adaptors *rpp; + struct random_adaptors *rppi, *ramax; + unsigned primax; KASSERT(adaptor != NULL, ("pre-conditions failed")); *adaptor = NULL; - if (TUNABLE_STR_FETCH("rngs_want", rngs, sizeof(rngs))) { + if (TUNABLE_STR_FETCH("kern.random.active_adaptor", rngs, sizeof(rngs))) { cp = rngs; while ((token = strsep(&cp, ",")) != NULL) @@ -120,16 +121,23 @@ random_adaptor_choose(struct random_adap " skipping\n", token); } + primax = 0U; if (*adaptor == NULL) { /* - * Fallback to the first thing that's on the list of - * available RNGs. + * Fall back to the highest priority item on the available + * RNG list. */ sx_slock(&adaptors_lock); - rpp = LIST_FIRST(&adaptors); - if (rpp != NULL) - *adaptor = rpp->rsp; + ramax = NULL; + LIST_FOREACH(rppi, &adaptors, entries) { + if (rppi->rsp->priority >= primax) { + ramax = rppi; + primax = rppi->rsp->priority; + } + } + if (ramax != NULL) + *adaptor = ramax->rsp; sx_sunlock(&adaptors_lock); Modified: stable/10/sys/dev/random/randomdev.h ============================================================================== --- stable/10/sys/dev/random/randomdev.h Sun Oct 13 00:13:29 2013 (r256413) +++ stable/10/sys/dev/random/randomdev.h Sun Oct 13 00:13:57 2013 (r256414) @@ -44,6 +44,7 @@ struct random_adaptor { struct selinfo rsel; const char *ident; int seeded; + unsigned priority; random_init_func_t *init; random_deinit_func_t *deinit; random_block_func_t *block; Modified: stable/10/sys/dev/random/randomdev_soft.c ============================================================================== --- stable/10/sys/dev/random/randomdev_soft.c Sun Oct 13 00:13:29 2013 (r256413) +++ stable/10/sys/dev/random/randomdev_soft.c Sun Oct 13 00:13:57 2013 (r256414) @@ -84,6 +84,7 @@ static struct random_adaptor random_cont .poll = randomdev_poll, .reseed = randomdev_flush_reseed, .seeded = 0, /* This will be seeded during entropy processing */ + .priority = 90, /* High priority, so top of the list. Fortuna may still win. */ }; #define RANDOM_MODULE_NAME yarrow #define RANDOM_CSPRNG_NAME "yarrow" @@ -99,6 +100,7 @@ static struct random_adaptor random_cont .poll = randomdev_poll, .reseed = randomdev_flush_reseed, .seeded = 0, /* This will be excplicitly seeded at startup when secured */ + .priority = 100, /* High priority, so top of the list. Beat Yarrow. */ }; #define RANDOM_MODULE_NAME fortuna #define RANDOM_CSPRNG_NAME "fortuna"