Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp274983imn; Mon, 25 Jul 2022 16:15:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tg6GmAzhByyzRNfjgWzV5jsNY53EU+JkY6G+rydnQE0qMRkeSSaoDVCXP/nWaZNwg94eLB X-Received: by 2002:a17:907:d9e:b0:72b:394b:ad34 with SMTP id go30-20020a1709070d9e00b0072b394bad34mr12335504ejc.109.1658790905732; Mon, 25 Jul 2022 16:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658790905; cv=none; d=google.com; s=arc-20160816; b=iJk+XtYoZLesnUCQ3LtXSM3jDFzAeNqk48k8unip53IKXgKhwPX0/Pad+t0FqQTlgu wjBLKmwRmwKWqRxSecCVL8x5FgQhJ6mt92BJpGNK+2OdWzXzYbTKrXkOrmnkjW/vmUp2 3h7DwQlhleMaGb8YJb/Q1FEz7eoKeIFlQXBQrmecDNrwQrRKZQ1tRAacYTQBmio2QWVC X5WXVPzUu4VTCoHpUzaCv7XZJtNuOOkXvafszQ1cbUiIx2XNbimQp12vm+jzcuNJ22LS Uugbt3xu5zotc2/3BVH5gYeG+GvZNhgevOy5gS5x5Y7fcg1PN3g2KXlspcRDxs3LAz3Y 2/vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=SB4KTdSkXPi/bTr8S5rSUPOkMtDOp8QOMJ8QIRrQICw=; b=N0fGYNJXGk2bj6wTL4Qx33PuPyohHx6AyNZ1ussO2O7yLufI7saGoYUjkXvAhWCWHO psdZIty+tUARrE2fWhjBNQ7n96UDTyE9bJNwOvYDigjtpmxGpB8jhw5EVmK73UX+p+vl 6oju+pG57jI/LWhy6V9NO1Jg2SyNkk6HhVcSr3odeKmvZWqQrB3VjBoJhPCeRIX8xLz3 o91EnRvB+PZV9l3u00AQvyopIr0/tLUqgCjfA4MhljmxLaIyimXP9y28Ox8HTISKMobm IrgQsKG80WUoKoE2xStQT0Ih/tRlTrwSXSyZj/Y7I10q3R3ztQs9vY6bctEjyAb86IFT iYFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@libc.org header.s=20210105 header.b=NhjeFJF4; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i19-20020a056402055300b0043ac66b0d92si11910428edx.379.2022.07.25.16.14.31; Mon, 25 Jul 2022 16:15:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@libc.org header.s=20210105 header.b=NhjeFJF4; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236750AbiGYXGR (ORCPT + 99 others); Mon, 25 Jul 2022 19:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbiGYXGQ (ORCPT ); Mon, 25 Jul 2022 19:06:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F9D213F23 for ; Mon, 25 Jul 2022 16:06:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E8E816142E for ; Mon, 25 Jul 2022 23:06:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD52AC341C6 for ; Mon, 25 Jul 2022 23:06:13 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=libc.org header.i=@libc.org header.b="NhjeFJF4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libc.org; s=20210105; t=1658790372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SB4KTdSkXPi/bTr8S5rSUPOkMtDOp8QOMJ8QIRrQICw=; b=NhjeFJF4B46cavCCuslhSwuS0htf+zuiox6jVZfkzsGEqSZ3uurYk0rjX4wspgPyLCeDpS PDbEyTtG5GvM2M/8cLISmLh3dZ9GWW+MGXreYTHu1DSpec89X+tVeuGDwgOijTZhkVA6gk bKqzrv6Sfy8KlqNMUfeYgon9H3laWgE= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id f0920b05 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Mon, 25 Jul 2022 23:06:12 +0000 (UTC) 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, linux-crypto@vger.kernel.org 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,DATE_IN_PAST_03_06, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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