diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-26 13:59:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-26 13:59:56 -0400 |
commit | 665fa0000aedb5f3d6b4d3b040d323074e1b7c40 (patch) | |
tree | 96c8b50e34fda7390edc340d690d9921416ec673 | |
parent | 1334ac11d93167fcc2953e9dd71837459b97d610 (diff) | |
parent | 4e00b339e264802851aff8e73cde7d24b57b18ce (diff) |
Merge tag 'random_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random
Pull /dev/random fixes from Ted Ts'o:
"Fix a regression on NUMA kernels and suppress excess unseeded entropy
pool warnings"
* tag 'random_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
random: rate limit unseeded randomness warnings
random: fix possible sleeping allocation from irq context
-rw-r--r-- | drivers/char/random.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 3cd3aae24d6d..cd888d4ee605 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -261,6 +261,7 @@ | |||
261 | #include <linux/ptrace.h> | 261 | #include <linux/ptrace.h> |
262 | #include <linux/workqueue.h> | 262 | #include <linux/workqueue.h> |
263 | #include <linux/irq.h> | 263 | #include <linux/irq.h> |
264 | #include <linux/ratelimit.h> | ||
264 | #include <linux/syscalls.h> | 265 | #include <linux/syscalls.h> |
265 | #include <linux/completion.h> | 266 | #include <linux/completion.h> |
266 | #include <linux/uuid.h> | 267 | #include <linux/uuid.h> |
@@ -438,6 +439,16 @@ static void _crng_backtrack_protect(struct crng_state *crng, | |||
438 | static void process_random_ready_list(void); | 439 | static void process_random_ready_list(void); |
439 | static void _get_random_bytes(void *buf, int nbytes); | 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 | * OS independent entropy store. Here are the functions which handle | 454 | * OS independent entropy store. Here are the functions which handle |
@@ -789,7 +800,7 @@ static void crng_initialize(struct crng_state *crng) | |||
789 | } | 800 | } |
790 | 801 | ||
791 | #ifdef CONFIG_NUMA | 802 | #ifdef CONFIG_NUMA |
792 | static void numa_crng_init(void) | 803 | static void do_numa_crng_init(struct work_struct *work) |
793 | { | 804 | { |
794 | int i; | 805 | int i; |
795 | struct crng_state *crng; | 806 | struct crng_state *crng; |
@@ -810,6 +821,13 @@ static void numa_crng_init(void) | |||
810 | kfree(pool); | 821 | kfree(pool); |
811 | } | 822 | } |
812 | } | 823 | } |
824 | |||
825 | static DECLARE_WORK(numa_crng_init_work, do_numa_crng_init); | ||
826 | |||
827 | static void numa_crng_init(void) | ||
828 | { | ||
829 | schedule_work(&numa_crng_init_work); | ||
830 | } | ||
813 | #else | 831 | #else |
814 | static void numa_crng_init(void) {} | 832 | static void numa_crng_init(void) {} |
815 | #endif | 833 | #endif |
@@ -925,6 +943,18 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) | |||
925 | process_random_ready_list(); | 943 | process_random_ready_list(); |
926 | wake_up_interruptible(&crng_init_wait); | 944 | wake_up_interruptible(&crng_init_wait); |
927 | pr_notice("random: crng init done\n"); | 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 | } | ||
928 | } | 958 | } |
929 | } | 959 | } |
930 | 960 | ||
@@ -1565,8 +1595,9 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, | |||
1565 | #ifndef CONFIG_WARN_ALL_UNSEEDED_RANDOM | 1595 | #ifndef CONFIG_WARN_ALL_UNSEEDED_RANDOM |
1566 | print_once = true; | 1596 | print_once = true; |
1567 | #endif | 1597 | #endif |
1568 | pr_notice("random: %s called from %pS with crng_init=%d\n", | 1598 | if (__ratelimit(&unseeded_warning)) |
1569 | func_name, caller, crng_init); | 1599 | pr_notice("random: %s called from %pS with crng_init=%d\n", |
1600 | func_name, caller, crng_init); | ||
1570 | } | 1601 | } |
1571 | 1602 | ||
1572 | /* | 1603 | /* |
@@ -1760,6 +1791,10 @@ static int rand_initialize(void) | |||
1760 | init_std_data(&blocking_pool); | 1791 | init_std_data(&blocking_pool); |
1761 | crng_initialize(&primary_crng); | 1792 | crng_initialize(&primary_crng); |
1762 | crng_global_init_time = jiffies; | 1793 | crng_global_init_time = jiffies; |
1794 | if (ratelimit_disable) { | ||
1795 | urandom_warning.interval = 0; | ||
1796 | unseeded_warning.interval = 0; | ||
1797 | } | ||
1763 | return 0; | 1798 | return 0; |
1764 | } | 1799 | } |
1765 | early_initcall(rand_initialize); | 1800 | early_initcall(rand_initialize); |
@@ -1827,9 +1862,10 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) | |||
1827 | 1862 | ||
1828 | if (!crng_ready() && maxwarn > 0) { | 1863 | if (!crng_ready() && maxwarn > 0) { |
1829 | maxwarn--; | 1864 | maxwarn--; |
1830 | printk(KERN_NOTICE "random: %s: uninitialized urandom read " | 1865 | if (__ratelimit(&urandom_warning)) |
1831 | "(%zd bytes read)\n", | 1866 | printk(KERN_NOTICE "random: %s: uninitialized " |
1832 | current->comm, nbytes); | 1867 | "urandom read (%zd bytes read)\n", |
1868 | current->comm, nbytes); | ||
1833 | spin_lock_irqsave(&primary_crng.lock, flags); | 1869 | spin_lock_irqsave(&primary_crng.lock, flags); |
1834 | crng_init_cnt = 0; | 1870 | crng_init_cnt = 0; |
1835 | spin_unlock_irqrestore(&primary_crng.lock, flags); | 1871 | spin_unlock_irqrestore(&primary_crng.lock, flags); |