linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: "Michal Suchánek" <msuchanek@suse.de>,
	linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org
Cc: Kees Cook <keescook@chromium.org>
Subject: Re: ppc64 early slub caches have zero random value
Date: Fri, 17 Apr 2020 19:19:17 +0200	[thread overview]
Message-ID: <8c93960b-587e-a576-91b8-666f106f8b60@suse.cz> (raw)
In-Reply-To: <20200417165304.GF25468@kitsune.suse.cz>

On 4/17/20 6:53 PM, Michal Suchánek wrote:
> Hello,

Hi, thanks for reproducing on latest upstream!

> instrumenting the kernel with the following patch
> 
> ---
>  mm/slub.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index d6787bbe0248..d40995d5f8ff 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3633,6 +3633,7 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
>  	s->flags = kmem_cache_flags(s->size, flags, s->name, s->ctor);
>  #ifdef CONFIG_SLAB_FREELIST_HARDENED
>  	s->random = get_random_long();
> +	pr_notice("Creating cache %s with s->random=%ld\n", s->name, s->random);
>  #endif
>  
>  	if (!calculate_sizes(s, -1))
> 
> I get:
> 
> [    0.000000] random: get_random_u64 called from kmem_cache_open+0x3c/0x5b0
with crng_init=0
> [    0.000000] Creating cache kmem_cache_node with s->random=0
> [    0.000000] Creating cache kmem_cache with s->random=0
> [    0.000000] Creating cache kmalloc-8 with s->random=0
> [    0.000000] Creating cache kmalloc-16 with s->random=0
> [    0.000000] Creating cache kmalloc-32 with s->random=0
> [    0.000000] Creating cache kmalloc-64 with s->random=0
> [    0.000000] Creating cache kmalloc-96 with s->random=0
> [    0.000000] Creating cache kmalloc-128 with s->random=0
> [    0.000000] Creating cache kmalloc-192 with s->random=-682532147323126958
> 
> The earliest caches created invariably end up with s->random of zero.

It seems that reliably it's the first 8 calls get_random_u64(), which sounds
more like some off-by-X bug than a genuine lack entropy that would become fixed
in the meanwhile?

> This is a problem for crash which does not recognize these as randomized
> and fails to read them. While this can be addressed in crash is it
> intended to create caches with zero random value in the kernel?

Definitely not. The question is more likely what guarantees we have with
crng_init=0. Probably we can't expect cryptographically strong randomness, but
zeroes still do look like a bug to me?

> This is broken at least in the 5.4~5.7 range but it is not clear if this
> ever worked. All examples of earlier kernels I have at hand use slab mm.
> 
> Thanks
> 
> Michal
> 


  reply	other threads:[~2020-04-17 17:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17 16:53 ppc64 early slub caches have zero random value Michal Suchánek
2020-04-17 17:19 ` Vlastimil Babka [this message]
2020-04-21  8:39   ` Nicolai Stange
2020-04-22 11:13     ` Vlastimil Babka

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=8c93960b-587e-a576-91b8-666f106f8b60@suse.cz \
    --to=vbabka@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=msuchanek@suse.de \
    /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).