linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>,
	"Ahmed S. Darwish" <darwish.07@gmail.com>,
	Lennart Poettering <mzxreary@0pointer.de>,
	"Theodore Y. Ts'o" <tytso@mit.edu>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"Alexander E. Patrakov" <patrakov@gmail.com>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	Willy Tarreau <w@1wt.eu>, Matthew Garrett <mjg59@srcf.ucam.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Linux API <linux-api@vger.kernel.org>,
	linux-man <linux-man@vger.kernel.org>
Subject: Re: [PATCH RFC v4 1/1] random: WARN on large getrandom() waits and introduce getrandom2()
Date: Fri, 20 Sep 2019 10:52:30 -0700	[thread overview]
Message-ID: <CALCETrV=4TX2a4uV5t2xOFzv+zM_jnOtMLJna8Vb7uXz6S=wSw@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wgW8rN2EVL_Rdn63V9vQO0GkZ=RQFeqqsYJM==8fujpPg@mail.gmail.com>

On Fri, Sep 20, 2019 at 9:30 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Fri, Sep 20, 2019 at 7:34 AM Andy Lutomirski <luto@kernel.org> wrote:
> >
> > What is this GRND_EXPLICIT thing?
>
> Your own email gives the explanation:
>
> > Linus, I disagree that blocking while waiting for randomness is an
> > error.  Sometimes you want to generate a key
>
> That's *exactly* why GRND_EXPLICIT needs to be done regardless.
>
> The keyword there is "Sometimes".
>
> But people currently use "getrandom(0)" when they DO NOT want a key,
> they just want some miscellaneous random numbers for some totally
> non-security-related reason.
>
> And that will continue. Exactly because the people who do not want a
> key by definition aren't thinking about it very hard.

I fully agree that this is a problem.  It's a problem we brought on
ourselves because we screwed up the ABI from the beginning.  The
question is what to do about it that doesn't cause its own set of
nasty problems.

> So GRND_EXPLICIT is there very much to make sure people who want true
> secure keys will say so, and five years from now we will not have the
> confusion between "Oh, I wasn't thinking about bootup". Because at a
> minimum, in the near future getrandom(0) will warn about the
> ambiguity. Or it will use some questionable jitter entropy that some
> real key users will look at sideways and go "I don't want that".

There are programs that call getrandom(0) *today* that expect secure
output.  openssl does a horrible dance in which it calls getentropy()
if available and falls back to syscall(__NR_getrandom, buf, buflen, 0)
otherwise.  We can't break this use case.  Changing the semantics of
getrandom(0) out from under them seems like the worst kind of ABI
break -- existing applications will *appear* to continue working but
will, in fact, become insecure.

IMO, from the beginning, we should have done this:

GRND_INSECURE: insecure.  always works.

GRND_SECURE_BLOCKING: does exactly what it says.

0: -EINVAL.

Using it correctly would be obvious.  Something like GRND_EXPLICIT
would be a head-scratcher: people would have to look at the man page
and actually think about it, and it's still easy to get wrong:

getrandom(..., GRND_EXPLICIT): just fscking give me a number.  it
seems to work and it shuts up the warning

And we're back to square one.


I think that, given existing software, we should make two or three
changes to fix the basic problems here:

1. Add GRND_INSECURE: at least let new applications do the right thing
going forward.

2. Fix what is arguably a straight up kernel bug, not even an ABI
issue: when a user program is blocking in getrandom(..., 0), the
kernel happily sits there doing absolutely nothing and deadlocks the
system as a result.  This IMO isn't an ABI issue -- it's an
implementation problem.  How about we make getrandom() (probably
actually wait_for_random_bytes()) do something useful to try to seed
the RNG if the system is otherwise not doing IO.

3. Optionally, entirely in user code: Get glibc to add new *library*
functions: getentropy_secure_blocking() and getentropy_insecure() or
whatever they want to call them.  Deprecate getentropy().

I think #2 is critical.  Right now, suppose someone has a system that
neets to do a secure network request (a la Red Hat's Clevis).  I have
no idea what Clevis actually does, but it wouldn't be particularly
crazy to do a DH exchange or sign with an EC key to ask some network
server to help unlock a dm-crypt volume.  If the system does this at
boot, it needs to use getrandom(..., 0), GRND_EXPLICIT, or whatever,
because it NEEDS a secure random number.  No about of ABI fiddling
will change this.  The kernel should *work* in this case rather than
deadlocking.

--Andy

  reply	other threads:[~2019-09-20 17:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAHk-=whW_AB0pZ0u6P9uVSWpqeb5t2NCX_sMpZNGy8shPDyDNg@mail.gmail.com>
     [not found] ` <CAHk-=wi_yXK5KSmRhgNRSmJSD55x+2-pRdZZPOT8Fm1B8w6jUw@mail.gmail.com>
     [not found]   ` <20190911173624.GI2740@mit.edu>
     [not found]     ` <20190912034421.GA2085@darwi-home-pc>
     [not found]       ` <20190912082530.GA27365@mit.edu>
     [not found]         ` <CAHk-=wjyH910+JRBdZf_Y9G54c1M=LBF8NKXB6vJcm9XjLnRfg@mail.gmail.com>
     [not found]           ` <20190914122500.GA1425@darwi-home-pc>
     [not found]             ` <008f17bc-102b-e762-a17c-e2766d48f515@gmail.com>
     [not found]               ` <20190915052242.GG19710@mit.edu>
     [not found]                 ` <CAHk-=wgg2T=3KxrO-BY3nHJgMEyApjnO3cwbQb_0vxsn9qKN8Q@mail.gmail.com>
2019-09-18 21:15                   ` [PATCH RFC v4 0/1] random: WARN on large getrandom() waits and introduce getrandom2() Ahmed S. Darwish
2019-09-18 21:17                     ` [PATCH RFC v4 1/1] " Ahmed S. Darwish
2019-09-18 23:57                       ` Linus Torvalds
2019-09-19 14:34                         ` Theodore Y. Ts'o
2019-09-19 15:20                           ` Linus Torvalds
2019-09-19 15:50                             ` Linus Torvalds
2019-09-20 13:13                               ` Theodore Y. Ts'o
2019-09-19 20:04                             ` Linus Torvalds
2019-09-19 20:45                               ` Alexander E. Patrakov
2019-09-19 21:47                                 ` Linus Torvalds
2019-09-19 22:23                                   ` Alexander E. Patrakov
2019-09-19 23:44                                     ` Alexander E. Patrakov
2019-09-20 13:16                                     ` Theodore Y. Ts'o
2019-09-23 11:55                               ` David Laight
2019-09-20 13:08                             ` Theodore Y. Ts'o
2019-09-20 13:46                         ` Ahmed S. Darwish
2019-09-20 14:33                           ` Andy Lutomirski
2019-09-20 16:29                             ` Linus Torvalds
2019-09-20 17:52                               ` Andy Lutomirski [this message]
2019-09-20 18:09                                 ` Linus Torvalds
2019-09-20 18:16                                   ` Willy Tarreau
2019-09-20 19:12                                   ` Andy Lutomirski
2019-09-20 19:51                                     ` Linus Torvalds
2019-09-20 20:11                                       ` Alexander E. Patrakov
2019-09-20 20:17                                       ` Matthew Garrett
2019-09-20 20:51                                       ` Andy Lutomirski
2019-09-20 22:44                                         ` Linus Torvalds
2019-09-20 23:30                                           ` Andy Lutomirski
2019-09-21  3:05                                             ` Willy Tarreau
2019-09-21  6:07                                   ` Florian Weimer
2019-09-23 18:33                                     ` Andy Lutomirski
2019-09-26 21:11                                       ` Ahmed S. Darwish
2019-09-20 18:12                                 ` Willy Tarreau
2019-09-20 19:22                                   ` Andy Lutomirski
2019-09-20 19:37                                     ` Willy Tarreau
2019-09-20 19:52                                       ` Andy Lutomirski
2019-09-20 20:02                                     ` Linus Torvalds
2019-09-20 18:15                                 ` Alexander E. Patrakov
2019-09-20 18:29                                   ` Andy Lutomirski
2019-09-20 17:26                           ` Willy Tarreau
2019-09-20 17:56                             ` Ahmed S. Darwish
2019-09-26 20:42                         ` [PATCH v5 0/1] random: getrandom(2): warn on large CRNG waits, introduce new flags Ahmed S. Darwish
2019-09-26 20:44                           ` [PATCH v5 1/1] " Ahmed S. Darwish
2019-09-26 21:39                             ` Andy Lutomirski
2019-09-28  9:30                               ` Ahmed S. Darwish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALCETrV=4TX2a4uV5t2xOFzv+zM_jnOtMLJna8Vb7uXz6S=wSw@mail.gmail.com' \
    --to=luto@kernel.org \
    --cc=darwish.07@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=mtk.manpages@gmail.com \
    --cc=mzxreary@0pointer.de \
    --cc=patrakov@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).