From owner-freebsd-current@FreeBSD.ORG Sat Nov 26 05:51:10 2011 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0AE6B106566C; Sat, 26 Nov 2011 05:51:10 +0000 (UTC) (envelope-from ache@vniz.net) Received: from vniz.net (vniz.net [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 837DB8FC0C; Sat, 26 Nov 2011 05:51:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by vniz.net (8.14.5/8.14.5) with ESMTP id pAQ5p7h1015194; Sat, 26 Nov 2011 09:51:07 +0400 (MSK) (envelope-from ache@vniz.net) Received: (from ache@localhost) by localhost (8.14.5/8.14.5/Submit) id pAQ5p7I4015193; Sat, 26 Nov 2011 09:51:07 +0400 (MSK) (envelope-from ache) Date: Sat, 26 Nov 2011 09:51:07 +0400 From: Andrey Chernov To: das@freebsd.org, current@freebsd.org, secteam@freebsd.org Message-ID: <20111126055107.GA15148@vniz.net> Mail-Followup-To: Andrey Chernov , das@freebsd.org, current@freebsd.org, secteam@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Subject: Fix for pure initial seeding of libkern/arc4random.c X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Nov 2011 05:51:10 -0000 This is preliminary patch just to illustrate idea how bad (31bit) initial seeding of kernel's arc4random() can be fixed. Do you like it? --- yarrow.c.bak 2011-11-26 09:40:49.000000000 +0400 +++ yarrow.c 2011-11-26 09:44:05.000000000 +0400 @@ -59,6 +59,8 @@ static void reseed(u_int); /* The reseed thread mutex */ struct mtx random_reseed_mtx; +static arc4rand_reseed = 1; + /* Process a single stochastic event off the harvest queue */ void random_process_event(struct harvest *event) @@ -261,6 +263,11 @@ reseed(u_int fastslow) /* Release the reseed mutex */ mtx_unlock(&random_reseed_mtx); + + if (arc4rand_reseed) { + arc4rand_reseed = 0; + arc4rand(NULL, 0, 1); + } } /* Internal function to return processed entropy from the PRNG */ -- http://ache.vniz.net/