From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751619AbdFHMaB (ORCPT ); Thu, 8 Jun 2017 08:30:01 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:35301 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbdFHM3x (ORCPT ); Thu, 8 Jun 2017 08:29:53 -0400 From: "Jason A. Donenfeld" To: "Theodore Ts'o" , LKML Cc: "Jason A. Donenfeld" , Herbert Xu 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 Message-Id: <20170608122932.23769-5-Jason@zx2c4.com> In-Reply-To: <20170608122932.23769-1-Jason@zx2c4.com> References: <20170608122932.23769-1-Jason@zx2c4.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jason A. Donenfeld --- 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