Commit ba461afb authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'random-5.19-rc4-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random

Pull random number generator fixes from Jason Donenfeld:

 - A change to schedule the interrupt randomness mixing less often, yet
   credit a little more each time, to reduce overhead during interrupt
   storms.

 - Squelch an undesired pr_warn() from __ratelimit(), which was causing
   problems in the reporters' CI.

 - A trivial comment fix.

* tag 'random-5.19-rc4-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random:
  random: update comment from copy_to_user() -> copy_to_iter()
  random: quiet urandom warning ratelimit suppression message
  random: schedule mix_interrupt_randomness() less often
parents fa1796a8 63b8ea5e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ static struct fasync_struct *fasync;

/* Control how we warn userspace. */
static struct ratelimit_state urandom_warning =
	RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3);
	RATELIMIT_STATE_INIT_FLAGS("urandom_warning", HZ, 3, RATELIMIT_MSG_ON_RELEASE);
static int ratelimit_disable __read_mostly =
	IS_ENABLED(CONFIG_WARN_ALL_UNSEEDED_RANDOM);
module_param_named(ratelimit_disable, ratelimit_disable, int, 0644);
@@ -408,7 +408,7 @@ static ssize_t get_random_bytes_user(struct iov_iter *iter)

	/*
	 * Immediately overwrite the ChaCha key at index 4 with random
	 * bytes, in case userspace causes copy_to_user() below to sleep
	 * bytes, in case userspace causes copy_to_iter() below to sleep
	 * forever, so that we still retain forward secrecy in that case.
	 */
	crng_make_state(chacha_state, (u8 *)&chacha_state[4], CHACHA_KEY_SIZE);
@@ -1009,7 +1009,7 @@ void add_interrupt_randomness(int irq)
	if (new_count & MIX_INFLIGHT)
		return;

	if (new_count < 64 && !time_is_before_jiffies(fast_pool->last + HZ))
	if (new_count < 1024 && !time_is_before_jiffies(fast_pool->last + HZ))
		return;

	if (unlikely(!fast_pool->mix.func))
+8 −4
Original line number Diff line number Diff line
@@ -23,12 +23,16 @@ struct ratelimit_state {
	unsigned long	flags;
};

#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) {		\
#define RATELIMIT_STATE_INIT_FLAGS(name, interval_init, burst_init, flags_init) { \
		.lock		= __RAW_SPIN_LOCK_UNLOCKED(name.lock),		  \
		.interval	= interval_init,				  \
		.burst		= burst_init,					  \
		.flags		= flags_init,					  \
	}

#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) \
	RATELIMIT_STATE_INIT_FLAGS(name, interval_init, burst_init, 0)

#define RATELIMIT_STATE_INIT_DISABLED					\
	RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)