mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: "Theodore Ts'o" <tytso@mit.edu>, LKML <linux-kernel@vger.kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH cleanups/resubmit 4/4] crypto/rng: ensure that the RNG is ready before using
Date: Thu,  8 Jun 2017 14:29:32 +0200	[thread overview]
Message-ID: <20170608122932.23769-5-Jason@zx2c4.com> (raw)
In-Reply-To: <20170608122932.23769-1-Jason@zx2c4.com>

Otherwise, we might be seeding the RNG using bad randomness, which is
dangerous. The one use of this function from within the kernel -- not
from userspace -- is being removed (keys/big_key), so that call site
isn't relevant in assessing this.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
This is the same as v4/v5.

 crypto/rng.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/crypto/rng.c b/crypto/rng.c
index f46dac5288b9..e042437e64b4 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -48,12 +48,14 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
 		if (!buf)
 			return -ENOMEM;
 
-		get_random_bytes(buf, slen);
+		err = get_random_bytes_wait(buf, slen);
+		if (err)
+			goto out;
 		seed = buf;
 	}
 
 	err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
-
+out:
 	kzfree(buf);
 	return err;
 }
-- 
2.13.0

  parent reply	other threads:[~2017-06-08 12:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08 12:29 [PATCH cleanups/resubmit 0/4] Cleanups & Resubmissions for Random-dev Jason A. Donenfeld
2017-06-08 12:29 ` [PATCH cleanups/resubmit 1/4] security/keys: ensure RNG is seeded before use Jason A. Donenfeld
2017-06-08 12:29 ` [PATCH cleanups/resubmit 2/4] random: squelch sh compiler warning and ensure safe optimization Jason A. Donenfeld
2017-06-08 12:29 ` [PATCH cleanups/resubmit 3/4] bluetooth/smp: ensure RNG is properly seeded before ECDH use Jason A. Donenfeld
2017-06-08 12:29 ` Jason A. Donenfeld [this message]
2017-06-08 21:58 ` [PATCH cleanups/resubmit 0/4] Cleanups & Resubmissions for Random-dev Theodore Ts'o
2017-06-09  0:57   ` Jason A. Donenfeld
2017-06-09 17:44     ` Jason A. Donenfeld

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=20170608122932.23769-5-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®