From patchwork Mon Sep 21 07:58:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 11788673 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6F2B618 for ; Mon, 21 Sep 2020 07:59:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D714A20EDD for ; Mon, 21 Sep 2020 07:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbgIUH7v (ORCPT ); Mon, 21 Sep 2020 03:59:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:57702 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726532AbgIUH71 (ORCPT ); Mon, 21 Sep 2020 03:59:27 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BB3A9B51A; Mon, 21 Sep 2020 08:00:00 +0000 (UTC) From: Nicolai Stange To: "Theodore Y. Ts'o" Cc: linux-crypto@vger.kernel.org, LKML , Arnd Bergmann , Greg Kroah-Hartman , "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Peter Matthias , Marcelo Henrique Cerri , Roman Drahtmueller , Neil Horman , Randy Dunlap , Julia Lawall , Dan Carpenter , Andy Lavr , Eric Biggers , "Jason A. Donenfeld" , =?utf-8?q?Stephan_M=C3=BCller?= , Torsten Duwe , Petr Tesarik , Nicolai Stange Subject: [RFC PATCH 20/41] random: provide min_crng_reseed_pool_entropy() Date: Mon, 21 Sep 2020 09:58:36 +0200 Message-Id: <20200921075857.4424-21-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921075857.4424-1-nstange@suse.de> References: <20200921075857.4424-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Currently, the current minimum entropy required from the input_pool for reseeding the primary_crng() is 16 bytes == 128 bits. A future patch will introduce support for obtaining up to a certain fraction thereof from the architecture's RNG, if available. This will effectively lower the minimum input_pool ->entropy_count required for a successful reseed of the primary_crng. As this value is used at a couple of places, namely crng_reseed() itself as well as dispatch_queued_entropy() and __dispatch_queued_entropy_fast(), introduce min_crng_reseed_pool_entropy() to ensure consistency among these. min_crng_reseed_pool_entropy() returns the minimum amount of entropy in bytes required from the input_pool for a successful reseed of the primary_crng. Currently it's hardcoded to 16. Use it in place of the hardcoded constants in crng_reseed(), dispatch_queued_entropy() and __dispatch_queued_entropy_fast(). Signed-off-by: Nicolai Stange --- drivers/char/random.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 1945249597e0..424de1565927 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -516,6 +516,8 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, static ssize_t _extract_entropy(struct entropy_store *r, void *buf, size_t nbytes, int fips); +static int min_crng_reseed_pool_entropy(void); + static void crng_reseed(struct crng_state *crng, struct entropy_store *r); static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy; @@ -916,7 +918,7 @@ static bool __dispatch_queued_entropy_fast(struct entropy_store *r, if (unlikely(r == &input_pool && crng_init < 2)) { const int entropy_bits = entropy_count >> ENTROPY_SHIFT; - return (entropy_bits >= 128); + return (entropy_bits >= min_crng_reseed_pool_entropy() * 8); } return false; @@ -965,7 +967,7 @@ static void dispatch_queued_entropy(struct entropy_store *r, if (crng_init < 2) { const int entropy_bits = entropy_count >> ENTROPY_SHIFT; - if (entropy_bits < 128) + if (entropy_bits < min_crng_reseed_pool_entropy() * 8) return; crng_reseed(&primary_crng, r); } @@ -1182,6 +1184,15 @@ static int crng_slow_load(const char *cp, size_t len) return 1; } +/* + * Minimum amount of entropy in bytes required from the input_pool for + * a successful reseed of the primary_crng. + */ +static int min_crng_reseed_pool_entropy(void) +{ + return 16; +} + static void crng_reseed(struct crng_state *crng, struct entropy_store *r) { unsigned long flags; @@ -1192,7 +1203,8 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) } buf; if (r) { - num = extract_entropy(r, &buf, 32, 16); + num = extract_entropy(r, &buf, 32, + min_crng_reseed_pool_entropy()); if (num == 0) return; } else {