Module Name: src Committed By: riastradh Date: Thu Aug 14 16:28:30 UTC 2014
Modified Files: src/sys/kern: subr_cprng.c Log Message: Lock cprng->cs_lock around rndsink_request to avoid race with callback. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sys/kern/subr_cprng.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/kern/subr_cprng.c diff -u src/sys/kern/subr_cprng.c:1.24 src/sys/kern/subr_cprng.c:1.25 --- src/sys/kern/subr_cprng.c:1.24 Sun Aug 10 16:44:36 2014 +++ src/sys/kern/subr_cprng.c Thu Aug 14 16:28:30 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_cprng.c,v 1.24 2014/08/10 16:44:36 tls Exp $ */ +/* $NetBSD: subr_cprng.c,v 1.25 2014/08/14 16:28:30 riastradh Exp $ */ /*- * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.24 2014/08/10 16:44:36 tls Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.25 2014/08/14 16:28:30 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -151,6 +151,7 @@ cprng_strong_create(const char *name, in /* Get some initial entropy. Record whether it is full entropy. */ uint8_t seed[NIST_BLOCK_KEYLEN_BYTES]; + mutex_enter(&cprng->cs_lock); cprng->cs_ready = rndsink_request(cprng->cs_rndsink, seed, sizeof(seed)); if (nist_ctr_drbg_instantiate(&cprng->cs_drbg, seed, sizeof(seed), @@ -168,6 +169,7 @@ cprng_strong_create(const char *name, in if (!cprng->cs_ready && !ISSET(flags, CPRNG_INIT_ANY)) printf("cprng %s: creating with partial entropy\n", cprng->cs_name); + mutex_exit(&cprng->cs_lock); return cprng; }