mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Dan Rosenberg <drosenberg@vsecurity.com>
Cc: Tony Luck <tony.luck@gmail.com>,
	linux-kernel@vger.kernel.org, davej@redhat.com,
	kees.cook@canonical.com, davem@davemloft.net, eranian@google.com,
	torvalds@linux-foundation.org, adobriyan@gmail.com,
	penberg@kernel.org, hpa@zytor.com,
	Arjan van de Ven <arjan@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [BUG] perf: bogus correlation of kernel symbols
Date: Mon, 23 May 2011 12:49:02 +0200	[thread overview]
Message-ID: <20110523104902.GB24674@elte.hu> (raw)
In-Reply-To: <1306110336.25049.7.camel@dan>


* Dan Rosenberg <drosenberg@vsecurity.com> wrote:

> On Sun, 2011-05-22 at 16:49 -0700, Tony Luck wrote:
> > 
> > 
> > On Sun, May 22, 2011 at 11:45 AM, Dan Rosenberg
> > <drosenberg@vsecurity.com> wrote:
> >         1. Is it ok to assume the existence of rdtsc?  If not, what
> >         are other
> >         ways of gathering entropy early in the boot process?  If this
> >         is the
> >         approach that's going to be taken, system uptime potentially
> >         becomes
> >         useful for attackers.  Any thoughts on how to address this?
> >         
> > There is a cpuid bit to tell you whether the processor supports rdtsc.
> > 
> 
> This might be worth checking, but it also might just be easier to clearly 
> document in the Kconfig that the feature requires rdtsc.  I'll play with it a 
> bit.

All modern x86 boxes have an RDTSC so this not really a practical concern - 
other than not crashing old boxes that do not have an RDTSC.

In theory there's other sources of entropy: we could read out the RTC CMOS as 
well. We could also read the current CPU frequency and fan speeds - those have 
components of thermal noise as well. Obviously it's hard to read this out early 
during bootup, when system devices are not enumerated yet.

What would be very useful is to print out the bootup RDTSC value for several 
bootups. I've done this on a testbox here, with real full reboots inbetween, 
putting the RDTSC printout very close to where you'd sample it for kernel image 
randomization:

[    0.000000] RDTSC: 26615467048
[    0.000000] RDTSC: 26527108278
[    0.000000] RDTSC: 26464738628
[    0.000000] RDTSC: 26554778708
[    0.000000] RDTSC: 26441165788
[    0.000000] RDTSC: 26555252088
[    0.000000] RDTSC: 26431986988
[    0.000000] RDTSC: 26521303608
[    0.000000] RDTSC: 26497878018
[    0.000000] RDTSC: 26455546968
[    0.000000] RDTSC: 26467673718
[    0.000000] RDTSC: 26460404758
[    0.000000] RDTSC: 26496175038

Even visually there's *plenty* of real randomness in the bootup value of the 
cycle counter (look at the above pattern of numbers and squint), even during 
early bootup, on real hardware.

While the last few bits are non-random there's at least 10-20 bits of 
randomness on this (very simple) testbox - possibly more.

I've done a few tests on virtual hardware as well, KVM based:

[    0.000000] RDTSC: 208122033
[    0.000000] RDTSC: 200455104
[    0.000000] RDTSC: 207258945

As expected there's even more randmness on virtual hardware than on real 
hardware: virtual hardware will boot in a complex host CPU state and is so 
exposed to the non-determinisic CPU cache state.

So the cycle counter is plenty good for this.

[ I'd only worry about the cycle counter if a hardware platform is so 
  minimalistic that it boots up very quickly without exposing itself to natural 
  sources of entropy. Eventually we'll get such systems, but right now the 
  cycle counter is good enough. ]

Btw, we already rely on the cycle counter for early bootup randomness: 
boot_init_stack_canary() relies on it.

> > Sometime soon you'll have "rdrand" available (check a different cpuid bit).
> 
> This of course is highly preferable, but I'd rather implement a solution 
> that's widely supported in hardware today.  Perhaps further down the road it 
> could be switched.

Well, since entropy does not get reduced on addition of independent variables 
the right sequence is (pseudocode):

	rnd  = entropy_cycles();
	rnd += entropy_rdrand();
	rnd += entropy_RTC();
	rnd += entropy_system();

That way systems that do not have RDRAND will still have the other ones as 
fallback.

Of course in your prototype you can use RDTSC as a first step, just make it 
easy to add other sources.

Thanks,

	Ingo

  parent reply	other threads:[~2011-05-23 10:49 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1305292059.1949.0.camel@dan>
2011-05-13 13:29 ` Dan Rosenberg
2011-05-16 15:35   ` Ingo Molnar
2011-05-16 16:14     ` Dan Rosenberg
2011-05-20  0:56     ` Dan Rosenberg
2011-05-20 12:07       ` Ingo Molnar
2011-05-20 12:54         ` Dan Rosenberg
2011-05-20 13:11           ` Ingo Molnar
2011-05-20 17:41             ` Dan Rosenberg
2011-05-20 18:14               ` Linus Torvalds
2011-05-20 18:27                 ` Kees Cook
2011-05-20 18:34                   ` Dan Rosenberg
2011-05-20 18:42                     ` Ingo Molnar
2011-05-20 18:28                 ` Ingo Molnar
2011-05-22  6:11                 ` david
2011-05-20 18:35               ` Ingo Molnar
2011-05-22 18:45             ` Dan Rosenberg
     [not found]               ` <BANLkTik1SK_kWVvGsKk0SqdByQ5-0b5nFg@mail.gmail.com>
2011-05-23  0:25                 ` Dan Rosenberg
2011-05-23  0:37                   ` H. Peter Anvin
2011-05-23 10:49                   ` Ingo Molnar [this message]
2011-05-23 19:02                     ` Ray Lee
2011-05-23 19:35                       ` Ingo Molnar
2011-05-24  1:59                     ` Valdis.Kletnieks
2011-05-24  4:06                       ` Ingo Molnar
2011-05-12 14:48 Stephane Eranian
2011-05-12 18:06 ` David Miller
2011-05-12 18:37   ` Dave Jones
2011-05-12 19:01     ` David Miller
2011-05-12 19:58       ` Pekka Enberg
2011-05-13  6:12         ` Kees Cook
2011-05-13  6:24           ` Pekka Enberg
2011-05-12 20:24       ` Alexey Dobriyan
2011-05-12 21:06   ` Ingo Molnar
2011-05-12 20:31 ` Linus Torvalds
2011-05-12 20:43   ` David Miller
2011-05-12 21:07   ` Stephane Eranian
2011-05-12 21:30     ` Stephane Eranian
2011-05-12 21:35       ` Ingo Molnar
2011-05-12 21:38         ` Stephane Eranian
2011-05-12 21:50           ` Ingo Molnar
2011-05-12 21:56             ` Stephane Eranian
2011-05-12 22:00               ` Ingo Molnar
2011-05-12 22:07             ` Dave Jones
2011-05-12 22:15               ` Stephane Eranian
2011-05-13  9:01                 ` Ingo Molnar
2011-05-13  8:57               ` Ingo Molnar
2011-05-13 16:23                 ` Andi Kleen
2011-05-17 12:17                   ` Ingo Molnar
2011-05-12 21:36     ` Ingo Molnar
2011-05-12 21:41       ` Stephane Eranian
2011-05-12 21:54         ` Ingo Molnar

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=20110523104902.GB24674@elte.hu \
    --to=mingo@elte.hu \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=drosenberg@vsecurity.com \
    --cc=eranian@google.com \
    --cc=hpa@zytor.com \
    --cc=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=tony.luck@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

all inboxes | Powered by JetHome®