|
261 | 261 | #include <linux/ptrace.h> |
262 | 262 | #include <linux/workqueue.h> |
263 | 263 | #include <linux/irq.h> |
| 264 | +#include <linux/ratelimit.h> |
264 | 265 | #include <linux/syscalls.h> |
265 | 266 | #include <linux/completion.h> |
266 | 267 | #include <linux/uuid.h> |
@@ -438,6 +439,16 @@ static void _crng_backtrack_protect(struct crng_state *crng, |
438 | 439 | static void process_random_ready_list(void); |
439 | 440 | static void _get_random_bytes(void *buf, int nbytes); |
440 | 441 |
|
| 442 | +static struct ratelimit_state unseeded_warning = |
| 443 | + RATELIMIT_STATE_INIT("warn_unseeded_randomness", HZ, 3); |
| 444 | +static struct ratelimit_state urandom_warning = |
| 445 | + RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3); |
| 446 | + |
| 447 | +static int ratelimit_disable __read_mostly; |
| 448 | + |
| 449 | +module_param_named(ratelimit_disable, ratelimit_disable, int, 0644); |
| 450 | +MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression"); |
| 451 | + |
441 | 452 | /********************************************************************** |
442 | 453 | * |
443 | 454 | * OS independent entropy store. Here are the functions which handle |
@@ -932,6 +943,18 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) |
932 | 943 | process_random_ready_list(); |
933 | 944 | wake_up_interruptible(&crng_init_wait); |
934 | 945 | pr_notice("random: crng init done\n"); |
| 946 | + if (unseeded_warning.missed) { |
| 947 | + pr_notice("random: %d get_random_xx warning(s) missed " |
| 948 | + "due to ratelimiting\n", |
| 949 | + unseeded_warning.missed); |
| 950 | + unseeded_warning.missed = 0; |
| 951 | + } |
| 952 | + if (urandom_warning.missed) { |
| 953 | + pr_notice("random: %d urandom warning(s) missed " |
| 954 | + "due to ratelimiting\n", |
| 955 | + urandom_warning.missed); |
| 956 | + urandom_warning.missed = 0; |
| 957 | + } |
935 | 958 | } |
936 | 959 | } |
937 | 960 |
|
@@ -1572,8 +1595,9 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, |
1572 | 1595 | #ifndef CONFIG_WARN_ALL_UNSEEDED_RANDOM |
1573 | 1596 | print_once = true; |
1574 | 1597 | #endif |
1575 | | - pr_notice("random: %s called from %pS with crng_init=%d\n", |
1576 | | - func_name, caller, crng_init); |
| 1598 | + if (__ratelimit(&unseeded_warning)) |
| 1599 | + pr_notice("random: %s called from %pS with crng_init=%d\n", |
| 1600 | + func_name, caller, crng_init); |
1577 | 1601 | } |
1578 | 1602 |
|
1579 | 1603 | /* |
@@ -1767,6 +1791,10 @@ static int rand_initialize(void) |
1767 | 1791 | init_std_data(&blocking_pool); |
1768 | 1792 | crng_initialize(&primary_crng); |
1769 | 1793 | crng_global_init_time = jiffies; |
| 1794 | + if (ratelimit_disable) { |
| 1795 | + urandom_warning.interval = 0; |
| 1796 | + unseeded_warning.interval = 0; |
| 1797 | + } |
1770 | 1798 | return 0; |
1771 | 1799 | } |
1772 | 1800 | early_initcall(rand_initialize); |
@@ -1834,9 +1862,10 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
1834 | 1862 |
|
1835 | 1863 | if (!crng_ready() && maxwarn > 0) { |
1836 | 1864 | maxwarn--; |
1837 | | - printk(KERN_NOTICE "random: %s: uninitialized urandom read " |
1838 | | - "(%zd bytes read)\n", |
1839 | | - current->comm, nbytes); |
| 1865 | + if (__ratelimit(&urandom_warning)) |
| 1866 | + printk(KERN_NOTICE "random: %s: uninitialized " |
| 1867 | + "urandom read (%zd bytes read)\n", |
| 1868 | + current->comm, nbytes); |
1840 | 1869 | spin_lock_irqsave(&primary_crng.lock, flags); |
1841 | 1870 | crng_init_cnt = 0; |
1842 | 1871 | spin_unlock_irqrestore(&primary_crng.lock, flags); |
|
0 commit comments