Skip to content

Commit

Permalink
random: remove rng_has_arch_random()
Browse files Browse the repository at this point in the history
With arch randomness being used by every distro and enabled in
defconfigs, the distinction between rng_has_arch_random() and
rng_is_initialized() is now rather small. In fact, the places where they
differ are now places where paranoid users and system builders really
don't want arch randomness to be used, in which case we should respect
that choice, or places where arch randomness is known to be broken, in
which case that choice is all the more important. So this commit just
removes the function and its one user.

Reviewed-by: Petr Mladek <[email protected]> # for vsprintf.c
Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Jun 10, 2022
1 parent 846bb97 commit e052a47
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 16 deletions.
13 changes: 0 additions & 13 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ static void __cold _credit_init_bits(size_t bits)
*
**********************************************************************/

static bool used_arch_random;
static bool trust_cpu __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
static bool trust_bootloader __initdata = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER);
static int __init parse_trust_cpu(char *arg)
Expand Down Expand Up @@ -811,7 +810,6 @@ int __init random_init(const char *command_line)
crng_reseed();
else if (trust_cpu)
_credit_init_bits(arch_bits);
used_arch_random = arch_bits >= POOL_READY_BITS;

WARN_ON(register_pm_notifier(&pm_notifier));

Expand All @@ -820,17 +818,6 @@ int __init random_init(const char *command_line)
return 0;
}

/*
* Returns whether arch randomness has been mixed into the initial
* state of the RNG, regardless of whether or not that randomness
* was credited. Knowing this is only good for a very limited set
* of uses, such as early init printk pointer obfuscation.
*/
bool rng_has_arch_random(void)
{
return used_arch_random;
}

/*
* Add device- or boot-specific data to the input pool to help
* initialize it.
Expand Down
1 change: 0 additions & 1 deletion include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static inline unsigned long get_random_canary(void)

int __init random_init(const char *command_line);
bool rng_is_initialized(void);
bool rng_has_arch_random(void);
int wait_for_random_bytes(void);

/* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes).
Expand Down
3 changes: 1 addition & 2 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,7 @@ static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
static DECLARE_WORK(enable_ptr_key_work, enable_ptr_key_workfn);
unsigned long flags;

if (!system_unbound_wq ||
(!rng_is_initialized() && !rng_has_arch_random()) ||
if (!system_unbound_wq || !rng_is_initialized() ||
!spin_trylock_irqsave(&filling, flags))
return -EAGAIN;

Expand Down

0 comments on commit e052a47

Please sign in to comment.