random: remove incomplete last_data logic
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 12 Jan 2022 14:22:30 +0000 (15:22 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 18 Jan 2022 12:03:55 +0000 (13:03 +0100)
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.

Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c

index 8b7567b5a6e6f6b6ce6e282ae4e2127bdf031b09..07354e2283412661585d5c9ce1877a0322d58a0a 100644 (file)
 #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 {
        u16 add_ptr;
        u16 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) \