Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1574485imi; Sat, 23 Jul 2022 09:56:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vIdaRV7H3t5krSPqTZQECjm40/4Pt3f659ahowNFKF9eqzJNtZ+a2UVDQK9rpSfMLW/Nxm X-Received: by 2002:a17:907:2e01:b0:72b:740c:154a with SMTP id ig1-20020a1709072e0100b0072b740c154amr3814179ejc.576.1658595404881; Sat, 23 Jul 2022 09:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658595404; cv=none; d=google.com; s=arc-20160816; b=j5D7ofv7Jrl5niQG9VH85yhIm7sDH6b4ugA7OdmuV5RqW/8bYvSE3oYhxBisqIbnIh elcLmZUWpRa6farGhUTYyGR+JTR4OrtCa10xohZzPGfAs/qEWzjvObWnAwRUbTlC6QF+ pePIewxJjCN5DmrokeRuBo9SXCgZHwUTm3ujchgMrTKFaX/r7EwnP4dvhwATDY1OOEuc vlnmR4pyiTId+/fX1VsvUX0KSrIPCmWEXQXgDNQgRjNYhUmm80hGmiy+Dg51NqYm8vi2 9ad2hKufKdMWl625miyyRntzTDGbQGlko2TfUYRhQE7InYTOlCi4/NJEbPN2Hlq+iwBu 818g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=seQzy75JrVdtoEI8fvcy884GFXRdPiCP5Hc5jYTFtuI=; b=Evn1Ivfc+ZAyP74JMeQEbQSWC2KiRfDxs7DlYy4y0KdrHKb0u66Ol5U7PalX8IBe3p 9Mj17hF3fOASM0fMT4sHKlccR6tvUT1pulJcIkaDa8YiK8v+CMVi2TM55mKJ5lfkFrmJ qQZtjjOE2005hHS5gH4JxWs4Qf1roeP8oJNj5OCHJf5d9ryO9dOdUkyfyx5u49MWSb49 4OdqdMUqRNHsfjuVeU41nfr3s7W3lcM1UBdr/au45Cn6EKL5IXs+hpeqd+pjMwQkiYtL eHaZNI2669Dlgfk1Xa4RxROpMQjdN6hmeLhG7c9D8CehOj/SJRRpOE94QUBl0J/X4QUM Zj9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=gHmbLuyU; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a1709064d8c00b00726abd9108bsi5491568eju.168.2022.07.23.09.56.02; Sat, 23 Jul 2022 09:56:44 -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=pass header.i=@zx2c4.com header.s=20210105 header.b=gHmbLuyU; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbiGWQWx (ORCPT + 99 others); Sat, 23 Jul 2022 12:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236274AbiGWQWu (ORCPT ); Sat, 23 Jul 2022 12:22:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A26140EC for ; Sat, 23 Jul 2022 09:22:49 -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 ams.source.kernel.org (Postfix) with ESMTPS id 65D80B80B8F for ; Sat, 23 Jul 2022 16:22:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21F2CC341C0; Sat, 23 Jul 2022 16:22:46 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="gHmbLuyU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1658593363; 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; bh=seQzy75JrVdtoEI8fvcy884GFXRdPiCP5Hc5jYTFtuI=; b=gHmbLuyUVCb9wJ95QS2XKCVpSB8fIVKBFTA4X9smqVFJpV2eWVlFuycoPRTw+I22vAlvFh fOlarOHzITVHyQLQEpOSaUEMCXz0Lcde63tHT8q6UsPl7I8W4Xrv/SqJrDDnfl+bjCSIpW nIuBCF/6Rwyl2LQb3Ede5uAAmRTvxYo= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 55564dd9 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 23 Jul 2022 16:22:42 +0000 (UTC) Date: Sat, 23 Jul 2022 18:22:39 +0200 From: "Jason A. Donenfeld" To: gibc-alpha@sourceware.org, Adhemerval Zanella Netto , Florian Weimer , Yann Droneaud , jann@thejh.net, Michael@phoronix.com Cc: linux-crypto@vger.kernel.org Subject: arc4random - are you sure we want these? Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 Hi glibc developers, I learned about the addition of the arc4random functions in glibc this morning, thanks to Phoronix. I wish somebody would have CC'd me into those discussions before it got committed, but here we are. I really wonder whether this is a good idea, whether this is something that glibc wants, and whether it's a design worth committing to in the long term. 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? Seen that way, it seems like a lot of complexity for nothing, and complexity that will lead to bugs and various oversights eventually. For example, the kernel reseeds itself when virtual machines fork using an identifier passed to the kernel via ACPI. It also reseeds itself on system resume, both from ordinary S3 sleep but also, more importantly, from hibernation. And in general, being the arbiter of entropy, the kernel is much better poised to determine when it makes sense to reseed. Glibc, on the other hand, can employ some heuristics and make some decisions -- on fork, after 16 MiB, and the like -- but in general these are lacking, compared to the much wider array of information the kernel has. You miss out on this with arc4random, and if that information _is_ to be exported to userspace somehow in the future, it would be awfully nice to design the userspace interface alongside the kernel one. For that reason, past discussion of having some random number generation in userspace libcs has geared toward doing this in the vDSO, somehow, where the kernel can be part and parcel of that effort. Seen from this perspective, going with OpenBSD's older paradigm might be rather limiting. Why not work together, between the kernel and libc, to see if we can come up with something better, before settling on an interface with semantics that are hard to walk back later? As-is, it's hard to recommend that anybody really use these functions. Just keep using getrandom(2), which has mostly favorable semantics. Yes, I get it: it's fun to make a random number generator, and so lots of projects figure out some way to make yet another one somewhere somehow. But the tendency to do so feels like a weird computer tinkerer disease rather something that has ever helped the overall ecosystem. So I'm wondering: who actually needs this, and why? What's the performance requirement like, and why is getrandom(2) insufficient? And is this really the best approach to take? If this is something needed, how would you feel about working together on a vDSO approach instead? Or maybe nobody actually needs this in the first place? And secondly, is there anyway that glibc can *not* do this, or has that ship fully sailed, and I really missed out by not being part of that discussion whenever it was happening? Thanks, Jason