From patchwork Sun Jul 16 17:22:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9843551 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B880F60212 for ; Sun, 16 Jul 2017 17:22:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7CE728475 for ; Sun, 16 Jul 2017 17:22:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A99C928497; Sun, 16 Jul 2017 17:22:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1447328475 for ; Sun, 16 Jul 2017 17:22:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbdGPRWN (ORCPT ); Sun, 16 Jul 2017 13:22:13 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:56941 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751158AbdGPRWM (ORCPT ); Sun, 16 Jul 2017 13:22:12 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id e0bfdf0c; Sun, 16 Jul 2017 17:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id; s=mail; bh=Q++PUw9EmsB9y8y1A29ch8pG8gc =; b=vf3/96FpwmR5X4XUQeeOShpWKUySgNnNxiVncLO2nxBtr7ylYgBctlUg4hA wWLXdzFoDw3aDdAiIOOAlko4hEekuSyIlbitRJR/naGPvn3kwf9afk5wZa/KIojh ci9YnCo0t9WKAl9n3s2bDidOKzJbZzAbNWIklUxAlcD+J5qbR0sUZJRw91DMUmmR 2Rn6AbFQEo7WEhsxFo9jBzJtKpRb28l/Y85kJFFRvcheByP54TuNgkF22VwrKH8t Qx3/D3W2Hld0651PpBBEuF7hbJVK0wTYTvk5qFyzPx5V334DEaiURbNbCRQvAuyC a9xDREf6JxCuT30oc10/hqAsvcw== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 9074aaf4 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Sun, 16 Jul 2017 17:16:49 +0000 (UTC) From: "Jason A. Donenfeld" To: Neil Horman , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" , Herbert Xu Subject: [PATCH] crypto/rng: ensure that the RNG is ready before using Date: Sun, 16 Jul 2017 19:22:06 +0200 Message-Id: <20170716172206.6541-1-Jason@zx2c4.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- crypto/rng.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto/rng.c b/crypto/rng.c index 5e8469244960..b4a618668161 100644 --- a/crypto/rng.c +++ b/crypto/rng.c @@ -43,12 +43,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; }