From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jason A. Donenfeld" Subject: [PATCH RFC v2 4/8] crypto/rng: ensure that the RNG is ready before using Date: Mon, 5 Jun 2017 05:47:53 +0200 Message-ID: <20170605034757.4803-5-Jason@zx2c4.com> References: <20170605034757.4803-1-Jason@zx2c4.com> Cc: "Jason A. Donenfeld" , Herbert Xu To: Theodore Ts'o , Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman Return-path: In-Reply-To: <20170605034757.4803-1-Jason@zx2c4.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-crypto.vger.kernel.org Otherwise, we might be seeding the RNG using bad randomness, which is dangerous. Cc: Herbert Xu Signed-off-by: Jason A. Donenfeld --- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jason A. Donenfeld" Date: Mon, 5 Jun 2017 05:47:53 +0200 Message-Id: <20170605034757.4803-5-Jason@zx2c4.com> In-Reply-To: <20170605034757.4803-1-Jason@zx2c4.com> References: <20170605034757.4803-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH RFC v2 4/8] crypto/rng: ensure that the RNG is ready before using To: Theodore Ts'o , Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com, Greg Kroah-Hartman Cc: "Jason A. Donenfeld" , Herbert Xu List-ID: Otherwise, we might be seeding the RNG using bad randomness, which is dangerous. Cc: Herbert Xu Signed-off-by: Jason A. Donenfeld --- 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