mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@kernel.org>,
	Willy Tarreau <w@1wt.eu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86-ml <x86@kernel.org>, "Jason A. Donenfeld" <Jason@zx2c4.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Nicholas Mc Guire <der.herr@hofr.at>
Subject: Re: early x86 unseeded randomness
Date: Tue, 15 Aug 2017 10:25:28 -0400	[thread overview]
Message-ID: <20170815142528.ne5fewtrnazmjzt6@thunk.org> (raw)
In-Reply-To: <alpine.DEB.2.20.1708151546380.1886@nanos>

On Tue, Aug 15, 2017 at 03:48:18PM +0200, Thomas Gleixner wrote:
> > > +u64 __init tsc_early_random(void)
> > > +{
> > > +	u64 uninitialized_var(res);
> > > +	int i;
> > > +
> > > +	if (!boot_cpu_has(X86_FEATURE_TSC))
> > > +		return res;
> > > +
> > > +	res ^= rdtsc();
> > > +	for (i = 0; i < BITS_PER_LONG; i++) {
> > > +		res ^= ((rdtsc() & 0x04) >> 2) << i;
> > > +		udelay(2);
> > > +	}
> > > +	return res;
> > > +}

Reasons why this is probably not the best idea:

1)  Exactly how udelay is implemented varies from architecture to
architecture and in some cases is different on a subarchitectural
level.  Some of them rely on reading the TSC; others rely on
operations that will have a constant number of CPU cycles (e.g., they
aren't doing much if any operations that might even have a tiny
glimmer of hope of adding unpredictability).

2) Given a dozen numbers and saying, "hmm, my human brain doesn't see
a problem, it *must* be good" is hardly the basis on which to make
this kind of security design.  If you don't understand why this is a
bad idea, and can't come up with a counter example in under 5 seconds,
you probably aren't qualified to be designing a RNG which is supposed
to be cryptographically secure.

3)  Depending on when you use this function in early boot, udelay()
might not even have been calibrated yet.

4) As as standalone function, it doesn't take advantage of whatever
randomness might have been available; and if it turns out that the
tsc_early_random() is trivially predictable by someone spends more
time analyizing it for particular target architectures, it could be
disastrous

5) If you use this in addition to the existing get_random_u32(), it
won't hurt from a cryptographic perspective, but it will end up
burning 64-128 microseconds (or potentially more, depending on how
udelay is implemented on the architecture/subarch and whether udelay
has been calibrated yet).  And it's not clear it's really better(tm).

6) It would be the ultimate in irony if Jason, who tried so hard to
get this warning in because he hoped it would make Linux more secure,
actually ends up making Linux *less* secure because something like
this starts getting used....

					- Ted

  reply	other threads:[~2017-08-15 14:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-14 17:35 Borislav Petkov
2017-08-14 17:47 ` Linus Torvalds
2017-08-14 18:00   ` Borislav Petkov
2017-08-14 18:17     ` Linus Torvalds
2017-08-14 19:00       ` Borislav Petkov
2017-08-15  1:31         ` Theodore Ts'o
2017-08-15  6:44           ` Willy Tarreau
2017-08-15  7:42             ` Ingo Molnar
2017-08-15  8:01               ` Willy Tarreau
2017-08-15  8:05                 ` Ingo Molnar
2017-08-15 12:09                   ` Theodore Ts'o
2017-08-15 13:26                     ` Willy Tarreau
2017-08-15 10:47               ` Thomas Gleixner
2017-08-15 13:45                 ` Borislav Petkov
2017-08-15 13:48                   ` Thomas Gleixner
2017-08-15 14:25                     ` Theodore Ts'o [this message]
2017-08-15 14:42                       ` Thomas Gleixner
2017-08-15 15:26                         ` Borislav Petkov
2017-08-15 17:37                         ` Thomas Gleixner
2017-08-16  3:35                           ` Theodore Ts'o
2017-08-16  9:13                             ` Thomas Gleixner
2017-08-16  9:56                               ` Will Deacon
2017-08-16  3:21                         ` Theodore Ts'o
2017-08-15 15:24                     ` Borislav Petkov
2017-08-15 12:48               ` Michael Ellerman

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=20170815142528.ne5fewtrnazmjzt6@thunk.org \
    --to=tytso@mit.edu \
    --cc=Jason@zx2c4.com \
    --cc=bp@alien8.de \
    --cc=der.herr@hofr.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    --cc=x86@kernel.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

all inboxes | Powered by JetHome®