From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [216.12.86.13]) by sourceware.org (Postfix) with ESMTPS id 90B8E383A30C for ; Mon, 25 Jul 2022 17:44:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 90B8E383A30C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=libc.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=libc.org Date: Mon, 25 Jul 2022 13:44:30 -0400 From: Rich Felker To: Florian Weimer Cc: Yann Droneaud , "Jason A. Donenfeld" , libc-alpha@sourceware.org, Michael@phoronix.com, jann@thejh.net Subject: Re: arc4random - are you sure we want these? Message-ID: <20220725174430.GI7074@brightrain.aerifal.cx> References: <6bf352e9-1312-40de-4733-3219721b343c@linaro.org> <20220725153303.GF7074@brightrain.aerifal.cx> <878rohp2ll.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878rohp2ll.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 17:44:33 -0000 On Mon, Jul 25, 2022 at 06:40:54PM +0200, Florian Weimer via Libc-alpha wrote: > * Rich Felker: > > > On Sat, Jul 23, 2022 at 02:39:29PM -0300, Adhemerval Zanella Netto via Libc-alpha wrote: > >> On 23/07/22 13:25, Jason A. Donenfeld wrote: > >> > Firstly, for what use cases does this actually help? As of recent > >> > changes to the Linux kernels -- now backported all the way to 4.9! -- > >> > getrandom() and /dev/urandom are extremely fast and operate over per-cpu > >> > states locklessly. Sure you avoid a syscall by doing that in userspace, > >> > but does it really matter? Who exactly benefits from this? > >> > >> Mainly performance, since glibc both export getrandom and getentropy. > >> There were some discussion on maillist and we also decided to explicit > >> state this is not a CSRNG on our documentation. > > > > This is an extreme documentation/specification bug that *hurts* > > portability and security. The core contract of the historical > > arc4random function is that it *is* a CSPRNG. Having a function by > > that name that's allowed not to be one means now all software using it > > has to add detection for the broken glibc variant. > > > > If the glibc implementation has flaws that actually make it not a > > CSPRNG, this absolutely needs to be fixed. Not doing so is > > irresponsible and will set everyone back a long ways. > > The core issue is that on some kernels/architectures, reading from > /dev/urandom can degrade to GRND_INSECURE (approximately), and while the > result is likely still unpredictable, not everyone would label that as a > CSPRNG. Then don't fallback to /dev/urandom. It's not even a failsafe fallback anyway (ENFILE, EMFILE, sandboxes, etc.) so it can't safely be used here. Instead use SYS_sysctl and poll for entropy_avail, looping until it's ready. AFAICT this works reliably on all kernels as far back as glibc supports (assuming nothing idiotic like intentionally patching or configuring out random support, but then it's PEBKAC error, as no distros did this). Rich