Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1790501ybj; Sun, 22 Sep 2019 12:01:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqypo6bQKfndkY+5AkdfeNc04/2hISnhe/oZhAI1u5bgLPkU8ObwZJQeyOeirXP2pS2DvdB1 X-Received: by 2002:a50:f09d:: with SMTP id v29mr32469871edl.4.1569178862214; Sun, 22 Sep 2019 12:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569178862; cv=none; d=google.com; s=arc-20160816; b=POcx4yBILy9BX2f1UNtyQAd6nuQOnvroavx+n+7dWO3XltEbxforRovbvHYtIeHnuf 9NqNgYKAwLVKpn9meavZiUOA6kuozTQTGu0hjh9/I5hHlS3RGcwJOs5ripTBXMjXXhFb GQqxePheaM17dVqjwYsAucEo3kuqZzNc1sIA1hRDTiLCo89/ZdrhjB1xUMXPyHZNmkzD BHu/wO/7v7W13hlJuFf37aGcv31J2ZNkEsOQ722wbC7cVFy9j/E3GUs9SQu1Cuzg4yPp nvGJzVqdvxz3CrbrAWohurpgmUE/NM/Bebcmic1CQ9ojH2JlIjXsUvz7Tf9vihYXSlqj /vvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=iT+kXASM3t4AN0zlEwZ69W+BcJUuiSC2XCMfcintbrQ=; b=npt/+LpP2FIesRlgjqOcQeouDnlTnJWWXvaUaF4HTpj/3PVh3JDyADlqNboE+cd4lb Bw38OHPJrjzSGW++TEeFx2a/SD0cs6rlg8ezarvPRCPsbgKFS5L+pcz5V01LUgRk8mYw 2TJVx6pqI+CY/gGOQyUvZA6tNJjfb3NRsJ5UU2TrQgD5+LSp5DvurWefP8OwMBrxO+LT dN2h+4AEIkjCKSgfJ71yMr7HdrMx9GwV+fmOoHf0G8iVqogtbH1d/eeIw6cycrbLeDtG gUbWR+IB1dptliGXRBW/tYndRKVpmIjZGsW5bnHKkmSgzc3189dE7Ln/J+LnKSnNTnKl sXkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K+RGN2fR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sa16si73706ejb.356.2019.09.22.12.00.36; Sun, 22 Sep 2019 12:01:02 -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; dkim=pass header.i=@kernel.org header.s=default header.b=K+RGN2fR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436730AbfITTMS (ORCPT + 99 others); Fri, 20 Sep 2019 15:12:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389212AbfITTMS (ORCPT ); Fri, 20 Sep 2019 15:12:18 -0400 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 955FD217F5 for ; Fri, 20 Sep 2019 19:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569006736; bh=lVnEe8Jn8F2DGIN9/szyr6J/Q78TK+MBqRbgvLHED2c=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=K+RGN2fRSCqQMuwSwlgL5cRll9t73JlHCp8hIdVNw+6wRmZSwS5aJxXtE8wrjupwG ptmGH9gqrBbZMVRKJc+wZedzFpA7qz5UfuhtLU698uq/tI6VKdvquxesniEoJhhmBt k4J8mOqcIzx2hAo5hbLggZPkJ/akXFeSt3LHY934= Received: by mail-wm1-f47.google.com with SMTP id i16so3654231wmd.3 for ; Fri, 20 Sep 2019 12:12:16 -0700 (PDT) X-Gm-Message-State: APjAAAVHaHanTQURp0ZjgnZQay25APdWN4wavWm4sweZYJRt8iUah8oU 8MMCFwNntcUaxDLh6soEkq+I2wDvQzSFAPa4Oe4Rzg== X-Received: by 2002:a1c:5f0b:: with SMTP id t11mr4646168wmb.76.1569006735061; Fri, 20 Sep 2019 12:12:15 -0700 (PDT) MIME-Version: 1.0 References: <20190912034421.GA2085@darwi-home-pc> <20190912082530.GA27365@mit.edu> <20190914122500.GA1425@darwi-home-pc> <008f17bc-102b-e762-a17c-e2766d48f515@gmail.com> <20190915052242.GG19710@mit.edu> <20190918211503.GA1808@darwi-home-pc> <20190918211713.GA2225@darwi-home-pc> <20190920134609.GA2113@pc> In-Reply-To: From: Andy Lutomirski Date: Fri, 20 Sep 2019 12:12:03 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC v4 1/1] random: WARN on large getrandom() waits and introduce getrandom2() To: Linus Torvalds Cc: Andy Lutomirski , "Ahmed S. Darwish" , Lennart Poettering , "Theodore Y. Ts'o" , "Eric W. Biederman" , "Alexander E. Patrakov" , Michael Kerrisk , Willy Tarreau , Matthew Garrett , lkml , Ext4 Developers List , Linux API , linux-man Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org > On Sep 20, 2019, at 11:10 AM, Linus Torvalds wrote: > > =EF=BB=BFOn Fri, Sep 20, 2019 at 10:52 AM Andy Lutomirski wrote: >> >> IMO, from the beginning, we should have done this: >> >> GRND_INSECURE: insecure. always works. >> >> GRND_SECURE_BLOCKING: does exactly what it says. >> >> 0: -EINVAL. > > Violently agreed. And that's kind of what the GRND_EXPLICIT is really > aiming for. > > However, it's worth noting that nobody should ever use GRND_EXPLICIT > directly. That's just the name for the bit. The actual users would use > GRND_INSECURE or GRND_SECURE. > > And yes, maybe it's worth making the name be GRND_SECURE_BLOCKING just > to make people see what the big deal is. > > In the meantime, we need that new bit just to be able to create the > new semantics eventually. With a warning to nudge people in the right > direction. > > We may never be able to return -EINVAL, but we can add the pr_notice() > to discourage people from using it. > The problem is that new programs will have to try the new flag value and, if it returns -EINVAL, fall back to 0. This isn't so great. > And yes, we'll have to block - at least for a time - to get some > entropy. But at some point we either start making entropy up, or we > say "0 means jitter-entropy for ten seconds". > > That will _work_, but it will also make the security-people nervous, > which is just one more hint that they should move to > GRND_SECURE[_BLOCKING]. Wait, are you suggesting that 0 means invoke jitter-entropy or whatever and GRND_SECURE_BLOCKING means not wait forever and deadlock? That's no good -- people will want to continue using 0 because the behavior is better. My point here is that asking for secure random numbers isn=E2=80=99t some legacy oddity =E2=80=94 it=E2=80=99s genuinely n= ecessary. The kernel should do whatever it needs to in order to make it work. We really don=E2=80=99t want a situation where 0 means get me secure random numbers reliably but spam the logs and GRND_SECURE_BLOCKING means don=E2=80=99t spam the logs but risk deadlocking. This will encourage peopl= e to pass 0 to get the improved behavior. > So GRND_EXPLICIT is a bit that basically means "I am explicit about > what behavior I want". But part of that is that you need to _state_ > the behavior too. > > So: > > - GRND_INSECURE is (GRND_EXPLICIT | GRND_NONBLOCK) > > As in "I explicitly ask you not to just not ever block": urandom IMO this is confusing. The GRND_RANDOM flag was IMO a mistake and should just be retired. Let's enumerate useful cases and then give them sane values. > > - GRND_SECURE_BLOCKING is (GRND_EXPLICIT | GRND_RANDOM) > > As in "I explicitly ask you for those secure random numbers" > > - GRND_SECURE_NONBLOCKING is (GRND_EXPLICIT | GRND_RANDOM | GRND_NONBLOCK= ) > > As in "I want explicitly secure random numbers, but return -EAGAIN > if that would block". > > Which are the three sane behaviors (that last one is useful for the "I > can try to generate entropy if you don't have any" case. I'm not sure > anybody will do it, but it definitely conceptually makes sense). > > And I agree that your naming is better. I think this is the complete list of "good" behaviors for new programs: "insecure": always works, never warns. "secure, blocking": always returns *eventually* with secure output, i.e., does something to avoid deadlocks "secure, nonblocking" returns secure output immediately or returns -EAGAIN. And the only real question is how to map existing users to these semantics. I see two sensible choices: 1. 0 means "secure, blocking". I think this is not what we'd do if we could go back in time and chage the ABI from day 1, but I think it's actually good enough. As long as this mode won't deadlock, it's not *that* bad if programs are using it when they wanted "insecure". 2. 0 means "secure, blocking, but warn". Some new value means "secure, blocking, don't warn". The problem is that new applications will have to fall back to 0 to continue supporting old kernels. I briefly thought that maybe GRND_RANDOM would be a reasonable choice for "secure, blocking, don't warn", but the effect on new programs on old kernels will be unfortunate. I'm willing to go along with #2 if you like it better than #1, and I'll update my patches accordingly, but I prefer #1. I do think we should make all the ABI changes that we want to make all in one release. Let's not make programs think about their behavior on more versions than necessary. So I'd like to get rid of the current /dev/random semantics, add "insecure" mode, and do whatever deadlock avoidance scheme we settle on in a single release. --Andy