linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org, tytso@mit.edu
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH 3/7] random: remove incomplete last_data logic
Date: Thu, 13 Jan 2022 16:44:09 +0100	[thread overview]
Message-ID: <20220113154413.29513-4-Jason@zx2c4.com> (raw)
In-Reply-To: <20220113154413.29513-1-Jason@zx2c4.com>

There were a few things added under the "if (fips_enabled)" banner,
which never really got completed, and the FIPS people anyway are
choosing a different direction. Rather than keep around this halfbaked
code, get rid of it so that we can focus on a single design of the RNG
rather than two designs.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 39 ++++-----------------------------------
 1 file changed, 4 insertions(+), 35 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4b84b95428bc..7a4d858ac731 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -337,7 +337,6 @@
 #include <linux/spinlock.h>
 #include <linux/kthread.h>
 #include <linux/percpu.h>
-#include <linux/fips.h>
 #include <linux/ptrace.h>
 #include <linux/workqueue.h>
 #include <linux/irq.h>
@@ -517,14 +516,12 @@ struct entropy_store {
 	unsigned short add_ptr;
 	unsigned short input_rotate;
 	int entropy_count;
-	unsigned int last_data_init:1;
-	u8 last_data[EXTRACT_SIZE];
 };
 
 static ssize_t extract_entropy(struct entropy_store *r, void *buf,
 			       size_t nbytes, int min, int rsvd);
 static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
-				size_t nbytes, int fips);
+				size_t nbytes);
 
 static void crng_reseed(struct crng_state *crng, struct entropy_store *r);
 static u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
@@ -821,7 +818,7 @@ static void crng_initialize_secondary(struct crng_state *crng)
 
 static void __init crng_initialize_primary(struct crng_state *crng)
 {
-	_extract_entropy(&input_pool, &crng->state[4], sizeof(u32) * 12, 0);
+	_extract_entropy(&input_pool, &crng->state[4], sizeof(u32) * 12);
 	if (crng_init_try_arch_early(crng) && trust_cpu && crng_init < 2) {
 		invalidate_batched_entropy();
 		numa_crng_init();
@@ -1426,22 +1423,13 @@ static void extract_buf(struct entropy_store *r, u8 *out)
 }
 
 static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
-				size_t nbytes, int fips)
+				size_t nbytes)
 {
 	ssize_t ret = 0, i;
 	u8 tmp[EXTRACT_SIZE];
-	unsigned long flags;
 
 	while (nbytes) {
 		extract_buf(r, tmp);
-
-		if (fips) {
-			spin_lock_irqsave(&r->lock, flags);
-			if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
-				panic("Hardware RNG duplicated output!\n");
-			memcpy(r->last_data, tmp, EXTRACT_SIZE);
-			spin_unlock_irqrestore(&r->lock, flags);
-		}
 		i = min_t(int, nbytes, EXTRACT_SIZE);
 		memcpy(buf, tmp, i);
 		nbytes -= i;
@@ -1467,28 +1455,9 @@ 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 min, int reserved)
 {
-	u8 tmp[EXTRACT_SIZE];
-	unsigned long flags;
-
-	/* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
-	if (fips_enabled) {
-		spin_lock_irqsave(&r->lock, flags);
-		if (!r->last_data_init) {
-			r->last_data_init = 1;
-			spin_unlock_irqrestore(&r->lock, flags);
-			trace_extract_entropy(r->name, EXTRACT_SIZE,
-					      ENTROPY_BITS(r), _RET_IP_);
-			extract_buf(r, tmp);
-			spin_lock_irqsave(&r->lock, flags);
-			memcpy(r->last_data, tmp, EXTRACT_SIZE);
-		}
-		spin_unlock_irqrestore(&r->lock, flags);
-	}
-
 	trace_extract_entropy(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
 	nbytes = account(r, nbytes, min, reserved);
-
-	return _extract_entropy(r, buf, nbytes, fips_enabled);
+	return _extract_entropy(r, buf, nbytes);
 }
 
 #define warn_unseeded_randomness(previous) \
-- 
2.34.1


  parent reply	other threads:[~2022-01-13 15:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 15:44 [PATCH 0/7] first in overall series of rng code house cleaning Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 1/7] random: cleanup poolinfo abstraction Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 2/7] random: cleanup integer types Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` Jason A. Donenfeld [this message]
2022-01-16 13:24   ` [PATCH 3/7] random: remove incomplete last_data logic Dominik Brodowski
2022-01-13 15:44 ` [PATCH 4/7] random: remove unused reserved argument Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-16 16:22     ` Jason A. Donenfeld
2022-01-17 17:28       ` Dominik Brodowski
2022-01-17 17:52         ` [PATCH] random: simplify arithmetic function flow in account() Jason A. Donenfeld
2022-01-17 17:55           ` Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 5/7] random: rather than entropy_store abstraction, use global Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 6/7] random: remove unused OUTPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 7/7] random: de-duplicate INPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-14 15:33 ` [PATCH] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-14 15:39   ` David Laight
2022-01-14 15:46     ` Jason A. Donenfeld
2022-01-16 16:35 ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Jason A. Donenfeld
2022-01-16 16:35   ` [PATCH 2/4] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-17 17:31     ` Dominik Brodowski
2022-01-16 16:35   ` [PATCH 3/4] random: access input_pool_data directly rather than through pointer Jason A. Donenfeld
2022-01-17 17:32     ` Dominik Brodowski
2022-01-16 16:35   ` [PATCH 4/4] random: selectively clang-format where it makes sense Jason A. Donenfeld
2022-01-17 17:34     ` Dominik Brodowski
2022-01-17 17:29   ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Dominik Brodowski

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=20220113154413.29513-4-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --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;
as well as URLs for NNTP newsgroup(s).