From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: repeatable boot randomness inside KVM guest
Date: Sat, 14 Apr 2018 18:44:19 -0400 [thread overview]
Message-ID: <20180414224419.GA21830@thunk.org> (raw)
In-Reply-To: <20180414195921.GA10437@avx2>
+linux-mm@kvack.org
kvm@vger.kernel.org, security@kernel.org moved to bcc
On Sat, Apr 14, 2018 at 10:59:21PM +0300, Alexey Dobriyan wrote:
> SLAB allocators got CONFIG_SLAB_FREELIST_RANDOM option which randomizes
> allocation pattern inside a slab:
>
> int cache_random_seq_create(struct kmem_cache *cachep, unsigned int count, gfp_t gfp)
> {
> ...
> /* Get best entropy at this stage of boot */
> prandom_seed_state(&state, get_random_long());
>
> Then I printed actual random sequences for each kmem cache.
> Turned out they were all the same for most of the caches and
> they didn't vary across guest reboots.
The problem is at the super-early state of the boot path, kernel code
can't allocate memory. This is something most device drivers kinda
assume they can do. :-)
So it means we haven't yet initialized the virtio-rng driver, and it's
before interrupts have been enabled, so we can't harvest any entropy
from interrupt timing. So that's why trying to use virtio-rng didn't
help.
> The only way to get randomness for SLAB is to enable RDRAND inside guest.
>
> Is it KVM bug?
No, it's not a KVM bug. The fundamental issue is in how the
CONFIG_SLAB_FREELIST_RANDOM is currently implemented.
What needs to happen is freelist should get randomized much later in
the boot sequence. Doing it later will require locking; I don't know
enough about the slab/slub code to know whether the slab_mutex would
be sufficient, or some other lock might need to be added.
The other thing I would note that is that using prandom_u32_state() doesn't
really provide much security. In fact, if the the goal is to protect
against a malicious attacker trying to guess what addresses will be
returned by the slab allocator, I suspect it's much like the security
patdowns done at airports. It might protect against a really stupid
attacker, but it's mostly security theater.
The freelist randomization is only being done once; so it's not like
performance is really an issue. It would be much better to just use
get_random_u32() and be done with it. I'd drop using prandom_*
functions in slab.c and slubct and slab_common.c, and just use a
really random number generator, if the goal is real security as
opposed to security for show....
(Not that there's necessarily any thing wrong with security theater;
the US spends over 3 billion dollars a year on security theater. As
politicians know, symbolism can be important. :-)
Cheers,
- Ted
next prev parent reply other threads:[~2018-04-14 22:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-14 19:59 repeatable boot randomness inside KVM guest Alexey Dobriyan
2018-04-14 22:41 ` Andy Lutomirski
2018-04-14 23:09 ` Alexey Dobriyan
2018-04-14 22:44 ` Theodore Y. Ts'o [this message]
2018-04-15 0:41 ` Matthew Wilcox
2018-04-17 9:13 ` James Bottomley
2018-04-17 9:13 ` James Bottomley
2018-04-17 11:47 ` Matthew Wilcox
2018-04-17 11:47 ` Matthew Wilcox
2018-04-17 11:57 ` James Bottomley
2018-04-17 11:57 ` James Bottomley
2018-04-17 14:07 ` Matthew Wilcox
2018-04-17 14:07 ` Matthew Wilcox
2018-04-17 15:20 ` James Bottomley
2018-04-17 15:20 ` James Bottomley
2018-04-17 15:16 ` Theodore Y. Ts'o
2018-04-17 15:42 ` James Bottomley
2018-04-17 15:42 ` James Bottomley
2018-04-17 21:40 ` Theodore Y. Ts'o
2018-04-16 15:54 ` Kees Cook
2018-04-16 16:15 ` Thomas Garnier
2018-04-17 0:31 ` Alexey Dobriyan
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=20180414224419.GA21830@thunk.org \
--to=tytso@mit.edu \
--cc=adobriyan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.