From: "Jörn Engel" <joern@purestorage.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] random: make try_to_generate_entropy() more robust
Date: Fri, 18 Oct 2019 13:42:20 -0700 [thread overview]
Message-ID: <20191018204220.GD31027@cork> (raw)
In-Reply-To: <20191018203704.GC31027@cork>
On Fri, Oct 18, 2019 at 01:37:04PM -0700, Jörn Engel wrote:
> Sorry for coming late to the discussion. I generally like the approach
> in try_to_generate_entropy(), but I think we can do a little better
> still. Would something like this work?
Fixed lkml address.
> From 90078333edb6e720f13f6668376a69c0f9c570f5 Mon Sep 17 00:00:00 2001
> From: Joern Engel <joern@purestorage.com>
> Date: Fri, 18 Oct 2019 13:25:52 -0700
> Subject: [PATCH] random: make try_to_generate_entropy() more robust
>
> We can generate entropy on almost any CPU, even if it doesn't provide a
> high-resolution timer for random_get_entropy(). As long as the CPU is
> not idle, it changed the register file every few cycles. As long as the
> ALU isn't fully synchronized with the timer, the drift between the
> register file and the timer is enough to generate entropy from.
>
> Also print a warning on systems where entropy collection might be a
> problem. I have good confidence in two unsynchronized timers generating
> entropy. But I cannot tell whether timer and ALU are synchronized and
> we ought to warn users if all their crypto is likely to be broken.
>
> Signed-off-by: Joern Engel <joern@purestorage.com>
> ---
> drivers/char/random.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index de434feb873a..00a04efd0686 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -1748,6 +1748,16 @@ EXPORT_SYMBOL(get_random_bytes);
> */
> static void entropy_timer(struct timer_list *t)
> {
> + struct pt_regs *regs = get_irq_regs();
> +
> + /*
> + * Even if we don't have a high-resolution timer in our system,
> + * the register file itself is a high-resolution timer. It
> + * isn't monotonic or particularly useful to read the current
> + * time. But it changes with every retired instruction, which
> + * is enough to generate entropy from.
> + */
> + mix_pool_bytes(&input_pool, regs, sizeof(*regs));
> credit_entropy_bits(&input_pool, 1);
> }
>
> @@ -1764,9 +1774,8 @@ static void try_to_generate_entropy(void)
>
> stack.now = random_get_entropy();
>
> - /* Slow counter - or none. Don't even bother */
> - if (stack.now == random_get_entropy())
> - return;
> + /* Slow counter - or none. Warn user */
> + WARN_ON(stack.now == random_get_entropy());
>
> timer_setup_on_stack(&stack.timer, entropy_timer, 0);
> while (!crng_ready()) {
> --
> 2.20.1
>
Jörn
--
...one more straw can't possibly matter...
-- Kirby Bakken
next parent reply other threads:[~2019-10-18 20:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191018203704.GC31027@cork>
2019-10-18 20:42 ` Jörn Engel [this message]
2019-10-18 22:58 ` [PATCH] random: make try_to_generate_entropy() more robust Linus Torvalds
2019-10-19 2:25 ` Linus Torvalds
2019-10-19 7:39 ` Ingo Molnar
2019-10-19 10:13 ` Thomas Gleixner
2019-10-19 10:49 ` Thomas Gleixner
2019-10-19 14:37 ` Jörn Engel
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=20191018204220.GD31027@cork \
--to=joern@purestorage.com \
--cc=linux-kernel@vger.kernel.org \
--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