From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6912 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Daniel_Cegie=C5=82ka?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: getrandom syscall Date: Wed, 28 Jan 2015 19:12:42 +0100 Message-ID: References: <20150128145410.GH4574@brightrain.aerifal.cx> <20150128154108.GH32318@port70.net> <20150128160352.GI32318@port70.net> <20150128162104.GJ4574@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1422468800 23541 80.91.229.3 (28 Jan 2015 18:13:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 18:13:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6925-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 28 19:13:20 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YGX76-00084A-6B for gllmg-musl@m.gmane.org; Wed, 28 Jan 2015 19:13:16 +0100 Original-Received: (qmail 29920 invoked by uid 550); 28 Jan 2015 18:13:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 29903 invoked from network); 28 Jan 2015 18:13:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=oCImCpnMb4NHDC18UOBybFcPKu5VyFwoMu6fnWQP/xk=; b=T2CSOp3hVf5E86W+FxGUTWMxAiTPqKe7ldyXe2rXUPptGkVu1DaBPEK9zz6VN97L9h pLdrxorE359nTX0RaLGb8dW2firovALCmIi2vG0OeXrXnXN2E//G2LbqXhg939JzWJsD mJG0uBMrFW4YYv6fg1kUBDDB6r21o9skt1fzsaq94YXs0PV3xlSmrSc7HI3XOVjS9AcA 0WIx3vZf4eGE5LRTAwb3oQNlsx3/rTDsFx5bO4cMu2aKwKtyoVt0oj91zPNdcBFy/Wc6 iDzUXdjCL6Q2VhpyCSXRsFTSVWzj6nmSpREcI8lc+LNhC8ikt+9APlPJbV4YF5EkKq99 JdWA== X-Received: by 10.202.97.130 with SMTP id v124mr2879569oib.34.1422468782528; Wed, 28 Jan 2015 10:13:02 -0800 (PST) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:6912 Archived-At: 2015-01-28 18:43 GMT+01:00 Brent Cook : > Here is the wrapper in LibreSSL for getrandom, to hopefully lend to > the discussion: > > https://github.com/libressl-portable/openbsd/blob/master/src/lib/libcrypto/crypto/getentropy_linux.c#L194 > > It tries to avoid a couple of possible issues. FIrst, while <= 256 > byte getrandom should not interrupt, it appears that if the kernel > entropy pool has not been initialized yet, it would still return EINTR > if called early enough in the boot process. How likely this is in > practice, I don't know. > > Then, to avoid modifying errno even though there was an actual > success, the wrapper restores the previous errno value when it > succeeds. > > I just realized that the length check in getentropy_getrandom() is > redundant, since it is checked earlier in getentropy() as well, but > hopefully this is helpful. > > If a getentropy() were added to musl libc, but in such a way that it > might fail on older kernels, that would cause some problems with > LibreSSL, and now OpenNTPD. They will both try to use getentropy() > with arc4random() if it is found in a system, and arc4random() will > treat a getentropy() failure as fatal. Thank you for your feedback. That's right, arc4random() sometimes ended with an abort() and this is a huge problem. I used /dev/urandom as a source of entropy for arc4random(), but it can fail (eg. in a chroot), so if arc4random() calls abort(), then the whole process ends. btw. thanks for your work on OpenNTPD. I was planning to send an adjtimex() patch, but I see that you already did: https://github.com/openntpd-portable/openntpd-portable/commit/eeb97529cd5a332a69a312687e41939eb17f7a81 Daniel > Thanks, and good discussion.