linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Ahmed S. Darwish" <darwish.07@gmail.com>,
	Lennart Poettering <mzxreary@0pointer.de>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"Alexander E. Patrakov" <patrakov@gmail.com>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linux-ext4@vger.kernel.org, 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 09:08:56 -0400	[thread overview]
Message-ID: <20190920130856.GA16111@mit.edu> (raw)
In-Reply-To: <CAHk-=wgqbBy84ovtr8wPFqRo6U8jvp59rvQ8a6TvXuoyb-4L-Q@mail.gmail.com>

On Thu, Sep 19, 2019 at 08:20:57AM -0700, Linus Torvalds wrote:
> And unlike your theoretical state extension attack, I can point you to
> black hat presentations that literally talk about using the fact that
> we delay m,ixing in the input pull hash to know what's going on:
> 
>   https://www.blackhat.com/docs/eu-14/materials/eu-14-Kedmi-Attacking-The-Linux-PRNG-On-Android-Weaknesses-In-Seeding-Of-Entropic-Pools-And-Low-Boot-Time-Entropy.pdf
> 
> That's a real attack. Based on the REAL fact that we currently have to
> use the urandom logic because the entropy-waiting one is useless, and
> in fact depends on the re-seeding happening too late.

Actually, that particular case proves my point.

In that particular attack was against Android 4.3 (Android KitKat).
In the 3.4 kernel used by KitKat, before the urandom pool is
considered initialized, 100% of the entropy from
add_interrupt_randomness() goes to the urandom pool, NOT the input
pool.  add_device_entropy() also fed the urandom pool.  And on an
Android device, it doesn't have a keyboard, mouse, or spinning HDD, so
add_timer_randomness() and add_disk_randomness() weren't a factor.

The real problem was that the Android zygote process sampled the the
urandom pool too early, and what the attack did was essentially one
where they were trying to determine the state of the pool by looking
at that sampled output of /dev/urandom.

If we make getrandom(0) work like /dev/urandom, it doesn't solve the
problem, because if you read from the entropy pool before we can get
high quality randomness, you're screwed.  The only real answers are
(a) try to get better entropy early, or (b) get userspace to wait
until it's safe to read from /dev/urandom.

Long-term, (a) is the only real way to solve the problem, and whether
you trust the bootloader, or trust the built-in hardware random number
generator (whether it's RDRAND, or some secure element in the device,
etc), we can't control userspace.  We can try to enforce userspace to
be safe by blocking, but that makes people unhappy.  We can certainly
try to influence userspace by annoying them with WARN() stack traces
in the logs, and hope they pay attention, but that's not guaranteed.

> But honestly, this isn't realistic. I can point to emails where *you*
> are  arguing against other hashing algorithms because the whole state
> extension attack simply isn't realistic.

The blackhat presentation which you pointed at *was* actually a state
extension attack.  When I argued against state extension attacks, that
was in cases where people worried about recovery after the pool is
exposed --- and my argument was if you can read from kernel memory
enough to grab the pool state, you have other problems.  Your
observation that if you can install malware that runs at system
initscript/userspace bootup time, you probably have other problems, is
a similar argument, and it's a fair one.  But it *has* happened, as
the blackhat paper demonstrates.

My thinking at the time is that if people are reading from the CRNG
before it's initialized (which could only happen via /dev/urandom),
that was kind of a disaster anyway, so resetting the initialization
count would at least get us to the point where when the CRNG *was*
declared to be initialized, that was something could state with high
confidence that we were in a secure state.  

> > I'm happy this proposed is not changing the behavior of getrandom(0).
> > Why not just remap 0 to GRND_EXPLICIT | GRND_WAIT_ENTROPY, though?  It
> > will have the same effect, and it's make it clear what we're doing.
> 
> Have you you not followed the whole discussion? Didn't you read the comment?
> 
> People use "getrandom(0)" not because they want secure randomness, but
> because that's the default.
> 
> And we *will* do something about it. This patch didn't, because I want
> to be able to backport it to stable, so that everybody is happier with
> saying "ok, I'll use the new getrandom(GRND_INSECURE)".
> 
> Because getrandom(0) will NOT be the the same as GRND_EXPLICIT |
> GRND_WAIT_ENTROPY.

No, I did read the comment.  And I agree that at the moment, that yes,
it is ambiguous.  What I really care about though, is the HUGE
DEPLOYED BASE which is using getrandom(0) *because* they are
generating cryptographic keys, and we will be changing things out from
under them.

We agree that we don't want to change things out from under the stable
users.  I'm pleading that we not screw over existing userspace --- at
least not right away.  Give them *time* to release update their source
bases to use getrandom(GRND_SECURE).  So what if we make getrandom(0)
print a ratelimited KERN_ERR deprecation notice that program should
switch to either specify either GRND_INSECURE or GRND_SECURE, and not
change the current semantics of getrandom(0) for some period of time?
Say, a year.  Or even six months.

If that's not good enough, what if we change getrandom(0) immediately,
but only for those platforms which have a functional
arch_get_random_long() or random_get_entropy()?  That gets us the x86
platform, which is where pretty much all of the users who have
complained have been coming from.  For the IOT/embedded user cases,
blocking is actually a feature, because the problem will be caught
while the product is in development, when the userspace code can be
fixed.

						- Ted

  parent reply	other threads:[~2019-09-20 13:09 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 [this message]
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
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=20190920130856.GA16111@mit.edu \
    --to=tytso@mit.edu \
    --cc=darwish.07@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=mzxreary@0pointer.de \
    --cc=patrakov@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /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).