linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Reshetova, Elena" <elena.reshetova@intel.com>
To: Andy Lutomirski <luto@amacapital.net>, Theodore Ts'o <tytso@mit.edu>
Cc: Eric Biggers <ebiggers3@gmail.com>,
	"ebiggers@google.com" <ebiggers@google.com>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	David Laight <David.Laight@aculab.com>,
	"Ingo Molnar" <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	"keescook@chromium.org" <keescook@chromium.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"luto@kernel.org" <luto@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jpoimboe@redhat.com" <jpoimboe@redhat.com>,
	"jannh@google.com" <jannh@google.com>,
	"Perla, Enrico" <enrico.perla@intel.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Subject: RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall
Date: Mon, 29 Apr 2019 07:46:41 +0000	[thread overview]
Message-ID: <2236FBA76BA1254E88B949DDB74E612BA4C66A8A@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <57357E35-3D9B-4CA7-BAB9-0BE89E0094D2@amacapital.net>


> > On Apr 26, 2019, at 7:01 AM, Theodore Ts'o <tytso@mit.edu> wrote:
> >
> >> On Fri, Apr 26, 2019 at 11:33:09AM +0000, Reshetova, Elena wrote:
> >> Adding Eric and Herbert to continue discussion for the chacha part.
> >> So, as a short summary I am trying to find out a fast (fast enough to be used per
> syscall
> >> invocation) source of random bits with good enough security properties.
> >> I started to look into chacha kernel implementation and while it seems that it is
> designed to
> >> work with any number of rounds, it does not expose less than 12 rounds primitive.
> >> I guess this is done for security sake, since 12 is probably the lowest bound we
> want people
> >> to use for the purpose of encryption/decryption, but if we are to build an efficient
> RNG,
> >> chacha8 probably is a good tradeoff between security and speed.
> >>
> >> What are people's opinions/perceptions on this? Has it been considered before to
> create a
> >> kernel RNG based on chacha?
> >
> > Well, sure.  The get_random_bytes() kernel interface and the
> > getrandom(2) system call uses a CRNG based on chacha20.  See
> > extract_crng() and crng_reseed() in drivers/char/random.c.
> >
> > It *is* possible to use an arbitrary number of rounds if you use the
> > low level interface exposed as chacha_block(), which is an
> > EXPORT_SYMBOL interface so even modules can use it.  "Does not expose
> > less than 12 rounds" applies only if you are using the high-level
> > crypto interface.
> >
> > We have used cut down crypto algorithms for performance critical
> > applications before; at one point, we were using a cut down MD4(!) for
> > initial TCP sequence number generation.  But that was getting rekeyed
> > every five minutes, and the goal was to make it just hard enough that
> > there were other easier ways of DOS attacking a server.
> >
> > I'm not a cryptographer, so I'd really us to hear from multiple
> > experts about the security level of, say, ChaCha8 so we understand
> > exactly kind of security we'd offering.  And I'd want that interface
> > to be named so that it's clear it's only intended for a very specific
> > use case, since it will be tempting for other kernel developers to use
> > it in other contexts, with undue consideration.
> >
> >
> 
> I don’t understand why we’re even considering weaker primitives. 

I guess one reasoning here was that cryptographic primitives are expensive performance-wise
and we are not really have a full crypto use case here with all standard requirements
for CRNG, such as reconstructing earlier inputs, etc. So, it was a natural wish to try to find smth
cheaper that does the job, but if we can make performance reasonable, I am all for the
proper primitives. 

>It seems to me
> that we should be using the “fast-erasure” construction for all get_random_bytes()
> invocations. Specifically, we should have a per cpu buffer that stores some random
> bytes and a count of how many random bytes there are. get_random_bytes() should
> take bytes from that buffer and *immediately* zero those bytes in memory. When
> the buffer is empty, it gets refilled with the full strength CRNG.

Ideally it would be great to call smth fast and secure on each syscall without a per-cpu
buffer, so that's why I was asking on chacha8. As Eric pointed it should not be used for
cryptographic purpose, but I think it is reasonably secure for our purpose, especially if
the generator is sometimes reseeded with fresh entropy. 
However, it very well might be that is too slow anyway. 

So, I think then we can do the per-cpu approach as you suggesting. 
Have a per-cpu buffer big enough as you suggested (couple of pages) from where
we regularly read 8 bits at the time and zero them as we go. 

I am just not sure on the right refill strategy in this case?
Should we try to maintain this per-cpu buffer always with some random bytes by
having a work queued that would refill it (or part of it, i.e. a page from a set of 4 pages) 
regularly from CRNG source? 
I guess how often we need to refill will depend so much on the syscall rate
on that cpu, so it might be hard to find a reasonable period.
In any case we need to prepare to do a refill straight from a syscall,
if despite our best efforts to keep the buffer refilled we run out of bits.
Is it ok to get a visible performance hit at this point? In worse case we will need to
generate n pages worth of random numbers, which is going to take a
while. 

I will try doing this PoC and measure implications (without the worker
refill to start with). Let's see how bad (performance wise it looks).

Best Regards,
Elena.




 
> The obvious objection is “oh no, a side channel could leak the buffer,” to which I say
> so what?  A side channel could just as easily leak the entire CRNG state.
> 
> For Elena’s specific use case, we would probably want a
> try_get_random_bytes_notrace() that *only* tries the percpu buffer, since this code
> runs so early in the syscall path that we can’t run real C code.  Or it could be moved a
> bit later, I suppose — the really early part is not really an interesting attack surface.

  reply	other threads:[~2019-04-29  7:46 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15  6:09 [PATCH] x86/entry/64: randomize kernel stack offset upon syscall Elena Reshetova
2019-04-15  7:25 ` Ingo Molnar
2019-04-15  8:44   ` Reshetova, Elena
2019-04-16  7:34     ` Ingo Molnar
2019-04-16 11:10       ` Reshetova, Elena
2019-04-16 12:08         ` Peter Zijlstra
2019-04-16 12:45           ` David Laight
2019-04-16 15:43             ` Theodore Ts'o
2019-04-16 16:07               ` Peter Zijlstra
2019-04-16 16:47               ` Reshetova, Elena
2019-04-17  9:28                 ` David Laight
2019-04-17 15:15                   ` Theodore Ts'o
2019-04-17 15:40                     ` Kees Cook
2019-04-17 15:53                     ` David Laight
2019-04-24 11:42                       ` Reshetova, Elena
2019-04-24 13:33                         ` David Laight
2019-04-25 11:23                           ` Reshetova, Elena
2019-04-26 11:33                         ` Reshetova, Elena
2019-04-26 14:01                           ` Theodore Ts'o
2019-04-26 17:44                             ` Eric Biggers
2019-04-26 18:02                               ` Theodore Ts'o
2019-04-27 13:59                                 ` Andy Lutomirski
2019-04-29  8:04                               ` Reshetova, Elena
2019-04-26 18:34                             ` Andy Lutomirski
2019-04-29  7:46                               ` Reshetova, Elena [this message]
2019-04-29 16:08                                 ` Andy Lutomirski
2019-04-30 17:51                                   ` Reshetova, Elena
2019-04-30 18:01                                     ` Kees Cook
2019-05-01  8:23                                     ` David Laight
2019-05-02  8:07                                       ` Reshetova, Elena
2019-05-01  8:41                                     ` David Laight
2019-05-01 23:33                                       ` Andy Lutomirski
2019-05-02  8:15                                       ` Reshetova, Elena
2019-05-02  9:23                                         ` David Laight
2019-05-02 14:47                                           ` Andy Lutomirski
2019-05-02 15:08                                             ` Ingo Molnar
2019-05-02 16:32                                               ` Andy Lutomirski
2019-05-02 16:43                                                 ` Ingo Molnar
2019-05-03 16:40                                                   ` Andy Lutomirski
2019-05-02 16:34                                               ` David Laight
2019-05-02 16:45                                                 ` Ingo Molnar
2019-05-03 16:17                                                   ` Reshetova, Elena
2019-05-03 16:40                                                     ` David Laight
2019-05-03 19:10                                                       ` Linus Torvalds
2019-05-06  6:47                                                         ` Reshetova, Elena
2019-05-06  7:01                                                       ` Reshetova, Elena
2019-05-08 11:18                                                       ` Reshetova, Elena
2019-05-08 11:32                                                         ` Ingo Molnar
2019-05-08 13:22                                                           ` Reshetova, Elena
2019-05-09  5:59                                                             ` Ingo Molnar
2019-05-09  7:01                                                               ` Reshetova, Elena
2019-05-09  8:43                                                                 ` Ingo Molnar
2019-05-11 22:45                                                                   ` Andy Lutomirski
2019-05-12  0:12                                                                     ` Kees Cook
2019-05-12  8:02                                                                       ` Ingo Molnar
2019-05-12 14:33                                                                         ` Kees Cook
2019-05-28 12:28                                                                           ` Reshetova, Elena
2019-05-28 13:33                                                                             ` Theodore Ts'o
2019-05-29 10:13                                                                               ` Reshetova, Elena
2019-05-29 10:51                                                                                 ` David Laight
2019-05-29 18:35                                                                                 ` Kees Cook
2019-05-29 18:37                                                                                 ` Kees Cook
2019-07-29 11:41                                                                                   ` Reshetova, Elena
2019-07-30 18:07                                                                                     ` Kees Cook
2019-08-01  6:35                                                                                     ` Reshetova, Elena
2019-05-09  7:03                                                               ` Reshetova, Elena
2019-05-06  7:32                                               ` Reshetova, Elena
2019-04-29  7:49                             ` Reshetova, Elena
2019-04-26 17:37                           ` Edgecombe, Rick P
2019-04-17  6:24               ` Ingo Molnar
2019-04-16 18:19           ` Reshetova, Elena
     [not found] <20190408061358.21288-1-elena.reshetova@intel.com>
2019-04-08 12:49 ` Josh Poimboeuf
2019-04-08 13:30   ` Reshetova, Elena
2019-04-08 16:21     ` Kees Cook
2019-04-10  8:26   ` Ingo Molnar
2019-04-10  9:00     ` Reshetova, Elena
2019-04-10 10:17       ` Ingo Molnar
2019-04-10 10:24       ` Reshetova, Elena
2019-04-10 14:52         ` Andy Lutomirski
2019-04-12  5:36           ` Reshetova, Elena
2019-04-12 21:16             ` Andy Lutomirski

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=2236FBA76BA1254E88B949DDB74E612BA4C66A8A@IRSMSX102.ger.corp.intel.com \
    --to=elena.reshetova@intel.com \
    --cc=David.Laight@aculab.com \
    --cc=bp@alien8.de \
    --cc=daniel@iogearbox.net \
    --cc=ebiggers3@gmail.com \
    --cc=ebiggers@google.com \
    --cc=enrico.perla@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jannh@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tytso@mit.edu \
    /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).