From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Kees Cook <keescook@chromium.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, PaX Team <pageexec@freemail.hu>
Subject: Re: [PATCH v2] gcc-plugins: latent_entropy: use /dev/urandom
Date: Tue, 5 Apr 2022 00:47:14 +0200 [thread overview]
Message-ID: <Ykt1cj0wPKEsHL2q@zx2c4.com> (raw)
In-Reply-To: <202204041144.96FC64A8@keescook>
Hi Kees,
On Mon, Apr 4, 2022 at 8:49 PM Kees Cook <keescook@chromium.org> wrote:
> This mixes two changes: the pRNG change and the "use urandom if
> non-deterministic" change. I think these should be split, so the pRNG
> change can be explicitly justified.
Alright, I'll split those. Or, more probably, just drop the xorshift
thing. There's not actually a strong reason for preferring xorshift. I
did it because it produces more uniformity and is faster to compute and
all that. But none of that stuff actually matters here. It was just a
sort of "well I'm at it..." thing.
> > static struct plugin_info latent_entropy_plugin_info = {
> > - .version = "201606141920vanilla",
> > + .version = "202203311920vanilla",
>
> This doesn't really need to be versioned. We can change this to just
> "vanilla", IMO.
Okay. I suppose you want it to be in a different patch too, right? In
which case I'll leave it out and maybe get to it later. (I suppose one
probably needs to double check whether it's used for anything
interesting like dwarf debug info or whatever, where maybe it's
helpful?)
> > + if (deterministic_seed) {
> > + unsigned HOST_WIDE_INT w = deterministic_seed;
> > + w ^= w << 13;
> > + w ^= w >> 7;
> > + w ^= w << 17;
> > + deterministic_seed = w;
> > + return deterministic_seed;
>
> While seemingly impossible, perhaps don't reset "deterministic_seed",
> and just continue to use "seed", so that it can never become "0" again.
Not sure I follow. It's an LFSR. The "L" is important. It'll never become
zero. It's not "seemingly". We can prove it trivially in Magma:
> w := 64;
> K := GF(2);
> I := IdentityMatrix(K, w);
> SHL := HorizontalJoin(RemoveColumn(I, 1), ZeroMatrix(K, w, 1));
> SHR := HorizontalJoin(ZeroMatrix(K, w, 1), RemoveColumn(I, w));
> M := (I + SHL^17) * (I + SHR^7) * (I + SHL^13);
> Order(M) eq 2^64 - 1;
true
> P<x> := MinimalPolynomial(M);
> IsPrimitive(P);
true
> IsInvertible(M);
true
> Rank(M);
64
And more obviously, splitting this into "seed" and "deterministic_seed",
as you suggested, wouldn't actually do much in the case when seed=0,
since 0<<N==0 and 0^0==0.
Jason
WARNING: multiple messages have this Message-ID (diff)
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Kees Cook <keescook@chromium.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, PaX Team <pageexec@freemail.hu>
Subject: Re: [PATCH v2] gcc-plugins: latent_entropy: use /dev/urandom
Date: Tue, 5 Apr 2022 00:47:21 +0200 [thread overview]
Message-ID: <Ykt1cj0wPKEsHL2q@zx2c4.com> (raw)
In-Reply-To: <202204041144.96FC64A8@keescook>
Hi Kees,
On Mon, Apr 4, 2022 at 8:49 PM Kees Cook <keescook@chromium.org> wrote:
> This mixes two changes: the pRNG change and the "use urandom if
> non-deterministic" change. I think these should be split, so the pRNG
> change can be explicitly justified.
Alright, I'll split those. Or, more probably, just drop the xorshift
thing. There's not actually a strong reason for preferring xorshift. I
did it because it produces more uniformity and is faster to compute and
all that. But none of that stuff actually matters here. It was just a
sort of "well I'm at it..." thing.
> > static struct plugin_info latent_entropy_plugin_info = {
> > - .version = "201606141920vanilla",
> > + .version = "202203311920vanilla",
>
> This doesn't really need to be versioned. We can change this to just
> "vanilla", IMO.
Okay. I suppose you want it to be in a different patch too, right? In
which case I'll leave it out and maybe get to it later. (I suppose one
probably needs to double check whether it's used for anything
interesting like dwarf debug info or whatever, where maybe it's
helpful?)
> > + if (deterministic_seed) {
> > + unsigned HOST_WIDE_INT w = deterministic_seed;
> > + w ^= w << 13;
> > + w ^= w >> 7;
> > + w ^= w << 17;
> > + deterministic_seed = w;
> > + return deterministic_seed;
>
> While seemingly impossible, perhaps don't reset "deterministic_seed",
> and just continue to use "seed", so that it can never become "0" again.
Not sure I follow. It's an LFSR. The "L" is important. It'll never become
zero. It's not "seemingly". We can prove it trivially in Magma:
> w := 64;
> K := GF(2);
> I := IdentityMatrix(K, w);
> SHL := HorizontalJoin(RemoveColumn(I, 1), ZeroMatrix(K, w, 1));
> SHR := HorizontalJoin(ZeroMatrix(K, w, 1), RemoveColumn(I, w));
> M := (I + SHL^17) * (I + SHR^7) * (I + SHL^13);
> Order(M) eq 2^64 - 1;
true
> P<x> := MinimalPolynomial(M);
> IsPrimitive(P);
true
> IsInvertible(M);
true
> Rank(M);
64
And more obviously, splitting this into "seed" and "deterministic_seed",
as you suggested, wouldn't actually do much in the case when seed=0,
since 0<<N==0 and 0^0==0.
Jason
next prev parent reply other threads:[~2022-04-04 23:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 0:13 [PATCH] gcc-plugins: latent_entropy: use /dev/urandom Jason A. Donenfeld
2022-04-03 20:12 ` Jason A. Donenfeld
2022-04-03 20:40 ` [PATCH v2] " Jason A. Donenfeld
2022-04-04 18:49 ` Kees Cook
2022-04-04 22:47 ` Jason A. Donenfeld [this message]
2022-04-04 22:47 ` Jason A. Donenfeld
2022-04-04 23:06 ` [PATCH] " Jason A. Donenfeld
2022-04-04 23:07 ` [PATCH v3] " Jason A. Donenfeld
2022-04-05 3:01 ` [PATCH v2] " Kees Cook
2022-04-05 12:38 ` Jason A. Donenfeld
2022-04-05 17:17 ` Kees Cook
2022-04-05 17:40 ` Jason A. Donenfeld
2022-04-05 22:28 ` [PATCH v4] " Jason A. Donenfeld
2022-04-05 22:28 ` Jason A. Donenfeld
2022-04-12 18:32 ` Kees Cook
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=Ykt1cj0wPKEsHL2q@zx2c4.com \
--to=jason@zx2c4.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pageexec@freemail.hu \
--cc=stable@vger.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 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.