From owner-svn-src-stable@FreeBSD.ORG Fri Apr 26 01:56:59 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 2CB4BBE; Fri, 26 Apr 2013 01:56:59 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 039E615C8; Fri, 26 Apr 2013 01:56:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3Q1uwxR035517; Fri, 26 Apr 2013 01:56:58 GMT (envelope-from ache@svn.freebsd.org) Received: (from ache@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3Q1uwKv035510; Fri, 26 Apr 2013 01:56:58 GMT (envelope-from ache@svn.freebsd.org) Message-Id: <201304260156.r3Q1uwKv035510@svn.freebsd.org> From: "Andrey A. Chernov" Date: Fri, 26 Apr 2013 01:56:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r249915 - in stable/9/sys: dev/random libkern sys X-SVN-Group: stable-9 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: Fri, 26 Apr 2013 01:56:59 -0000 Author: ache Date: Fri Apr 26 01:56:58 2013 New Revision: 249915 URL: http://svnweb.freebsd.org/changeset/base/249915 Log: MFC r249631 Attempt to mitigate poor initialization of arc4 by one-shot reinitialization from yarrow right after good entropy is harvested. Approved by: secteam (delphij) Modified: stable/9/sys/dev/random/randomdev_soft.c stable/9/sys/libkern/arc4random.c stable/9/sys/sys/libkern.h Directory Properties: stable/9/sys/ (props changed) stable/9/sys/dev/ (props changed) stable/9/sys/sys/ (props changed) Modified: stable/9/sys/dev/random/randomdev_soft.c ============================================================================== --- stable/9/sys/dev/random/randomdev_soft.c Fri Apr 26 00:53:34 2013 (r249914) +++ stable/9/sys/dev/random/randomdev_soft.c Fri Apr 26 01:56:58 2013 (r249915) @@ -366,6 +366,8 @@ random_yarrow_unblock(void) selwakeuppri(&random_systat.rsel, PUSER); wakeup(&random_systat); } + (void)atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_NONE, + ARC4_ENTR_HAVE); } static int Modified: stable/9/sys/libkern/arc4random.c ============================================================================== --- stable/9/sys/libkern/arc4random.c Fri Apr 26 00:53:34 2013 (r249914) +++ stable/9/sys/libkern/arc4random.c Fri Apr 26 01:56:58 2013 (r249915) @@ -24,6 +24,8 @@ __FBSDID("$FreeBSD$"); #define ARC4_RESEED_SECONDS 300 #define ARC4_KEYBYTES (256 / 8) +int arc4rand_iniseed_state = ARC4_ENTR_NONE; + static u_int8_t arc4_i, arc4_j; static int arc4_numruns = 0; static u_int8_t arc4_sbox[256]; @@ -130,7 +132,8 @@ arc4rand(void *ptr, u_int len, int resee struct timeval tv; getmicrouptime(&tv); - if (reseed || + if (atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_HAVE, + ARC4_ENTR_SEED) || reseed || (arc4_numruns > ARC4_RESEED_BYTES) || (tv.tv_sec > arc4_t_reseed)) arc4_randomstir(); Modified: stable/9/sys/sys/libkern.h ============================================================================== --- stable/9/sys/sys/libkern.h Fri Apr 26 00:53:34 2013 (r249914) +++ stable/9/sys/sys/libkern.h Fri Apr 26 01:56:58 2013 (r249915) @@ -70,6 +70,11 @@ static __inline int abs(int a) { return static __inline long labs(long a) { return (a < 0 ? -a : a); } static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); } +#define ARC4_ENTR_NONE 0 /* Don't have entropy yet. */ +#define ARC4_ENTR_HAVE 1 /* Have entropy. */ +#define ARC4_ENTR_SEED 2 /* Reseeding. */ +extern int arc4rand_iniseed_state; + /* Prototypes for non-quad routines. */ struct malloc_type; uint32_t arc4random(void);