Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3771525ybe; Mon, 16 Sep 2019 00:33:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl5Cpga2+fW7FBzbA5n4Ziw+TGs+jHFQEWSxphBv4nK1MRwjRmqwKhkDkwKkaS4uTiuo/E X-Received: by 2002:a17:906:7a0d:: with SMTP id d13mr50634343ejo.242.1568619201224; Mon, 16 Sep 2019 00:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568619201; cv=none; d=google.com; s=arc-20160816; b=MZWZD8rTIjsNOxGTtaXVB3SKIcYimQ9wR1zYc7iF4qbk/NE5zvYPxMGz7ok3N5jEZI uRqfOzLr6j6iEuc4SQCTz1PXxIdPWqL96ExZPXcEoJso5BEs5ccRQPZ6QnAR4eXWDG5q uZfM/y/DGakuwADNF2Hq1Xry9c4E4W2y19vDttYOHB41xNATsfBvn2JeXGNbZKDuARiM d/NBQBPxvAXzNYoOAbbfXxhA8o/cPEZhfL10zuipQEq2ufH6BxjPhqFKpKY6WphhQNMv oBofg5dV5Zm87QxRxQ77OZnLIUmzg1/qq7vxgShTcCwuKoqcvQWErAhBvnwmXd425kxG rxCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=TnnGKSUoQ2tf4hjlgqEgtruTkvMlwtxd8JzyikVhrV4=; b=Aj+5F/c0Qd80nib2pCjy/BvwPDqmnR+qZqoaXw6aBZJGAwORFYB4rX0kh+scUH+3hG swEfdj2JyLGfwhzqTwNASEArogRuxWhwpMMmt5VYZ8xB//gW2yP6FAvHy4rS4ybLDkK0 TU6WTRh8SREZsa7lbvho3U1xGt94yKRVERLiUQnFO4NyGpcbSznYclaHo7HIz9fR0c9s lMaHq1yTiPDqpv6nvFqlDtRLMpdYnKP3z78tD/j5z/3HbiX7jN6EmonNtFPjwJfPZv1S PHzzvlsZSbLHq4rg5H8tY8EpsiMeXixkWFneqLhd4pd78vA0+iJwavC4IgEDsEy2FZ2C 19bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si7088640eju.389.2019.09.16.00.32.55; Mon, 16 Sep 2019 00:33:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbfIPGN3 (ORCPT + 99 others); Mon, 16 Sep 2019 02:13:29 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:45723 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbfIPGN3 (ORCPT ); Mon, 16 Sep 2019 02:13:29 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id x8G6Cqap024026; Mon, 16 Sep 2019 08:12:52 +0200 Date: Mon, 16 Sep 2019 08:12:52 +0200 From: Willy Tarreau To: Linus Torvalds Cc: "Theodore Y. Ts'o" , Vito Caputo , "Ahmed S. Darwish" , Lennart Poettering , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , "Alexander E. Patrakov" , zhangjs , linux-ext4@vger.kernel.org, lkml Subject: Re: Linux 5.3-rc8 Message-ID: <20190916061252.GA24002@1wt.eu> References: <20190914150206.GA2270@darwi-home-pc> <20190915065142.GA29681@gardel-login> <20190916014050.GA7002@darwi-home-pc> <20190916014833.cbetw4sqm3lq4x6m@shells.gnugeneration.com> <20190916024904.GA22035@mit.edu> <20190916042952.GB23719@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sun, Sep 15, 2019 at 10:02:02PM -0700, Linus Torvalds wrote: > On Sun, Sep 15, 2019 at 9:30 PM Willy Tarreau wrote: > > > > I'd be in favor of adding in the man page something like "this > > random source is only suitable for applications which will not be > > harmed by getting a predictable value on output, and as such it is > > not suitable for generation of system keys or passwords, please > > use GRND_RANDOM for this". > > The problem with GRND_RANDOM is that it also ends up extracting > entropy, and has absolutely horrendous performance behavior. It's why > hardly anybody uses /dev/random. > > Which nobody should really ever do. I don't understand why people want > that thing, considering that the second law of thermodynamics really > pretty much applies. If you can crack the cryptographic hashes well > enough to break them despite reseeding etc, people will have much more > serious issues than the entropy accounting. That's exactly what I was thinking about a few minutes ago and which drove me back to mutt :-) > So the problem with getrandom() is that it only offered two flags, and > to make things worse they were the wrong ones. (...) > - GRND_RANDOM | GRND_NONBLOCK - don't use > > This won't block, but it will decrease the blocking pool entropy. > > It might be an acceptable "get me a truly secure ring with reliable > performance", but when it fails, you're going to be unhappy, and there > is no obvious fallback. > > So three out of four flag combinations end up being mostly "don't > use", and the fourth one isn't what you'd normally want (which is just > plain /dev/urandom semantics). I'm seeing it from a different angle. I now understand better why getrandom() absolutely wants to have an initialized pool, it's to encourage private key producers to use a secure, infinite source of randomness. Something that neither /dev/random nor /dev/urandom reliably provide. Unfortunately it does it by changing how urandom works while it ought to have done it as the replacement of /dev/random. The 3 random generation behaviors we currently support are : - /dev/random: only returns safe random (blocks), AND depletes entropy. getrandom(GRND_RANDOM) does the same. - /dev/urandom: returns whatever (never blocks), inexhaustible - getrandom(0): returns safe random (blocks), inexhaustible Historically we used to want to rely on /dev/random for SSH keys and certificates. It's arguable that with the massive increase of crypto usage, what used to be done only once in a system's life happens a bit more often and using /dev/random here can sometimes become a problem because it harms the whole system (thus why I said I think that we could almost require CAP_something to access it). Applications falling back to /dev/urandom obviously resulted in the massive mess we've seen years ago, even if it apparently solved the problem for their users. Thus getrandom(0) does make sense, but not as an alternative to urandom but to random, since it returns randoms safe for use for long lived keys. Couldn't we simply change the way things work ? Make GRND_RANDOM *not* deplate entropy, and document it as the only safe source, and make the default call return the same as /dev/urandom ? We can then use your timeout mechanism for the first one (which is not supposed to be called often and would be more accepted with a moderately long delay). Applications need to evolve as well. It's fine to use libraries to do whatever you need for you but ultimately the lib exports a function for a generic use case and doesn't know how to best adapt to the use case. Typically I would expect an SSH/HTTP daemon running in a recovery initramfs to produce unsafe randoms so that I can connect there without having to dance around it. However the self-signed cert produced there must not be saved, just like the SSH host key. But this means that the application (here the ssh-keygen or openssl) also need to be taught to purposely produce insecure keys when explicitly instructed to do so. Otherwise we know what will happen in the long term, since history repeats itself as long as the conditions are not changed :-/ Willy