|
354 | 354 | #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5)) |
355 | 355 | #define OUTPUT_POOL_SHIFT 10 |
356 | 356 | #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5)) |
357 | | -#define SEC_XFER_SIZE 512 |
358 | 357 | #define EXTRACT_SIZE 10 |
359 | 358 |
|
360 | 359 |
|
@@ -803,7 +802,6 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) |
803 | 802 | if (entropy_bits >= random_read_wakeup_bits && |
804 | 803 | wq_has_sleeper(&random_read_wait)) { |
805 | 804 | wake_up_interruptible(&random_read_wait); |
806 | | - kill_fasync(&fasync, SIGIO, POLL_IN); |
807 | 805 | } |
808 | 806 | /* If the input pool is getting full, and the blocking |
809 | 807 | * pool has room, send some entropy to the blocking |
@@ -1031,6 +1029,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) |
1031 | 1029 | crng_init = 2; |
1032 | 1030 | process_random_ready_list(); |
1033 | 1031 | wake_up_interruptible(&crng_init_wait); |
| 1032 | + kill_fasync(&fasync, SIGIO, POLL_IN); |
1034 | 1033 | pr_notice("random: crng init done\n"); |
1035 | 1034 | if (unseeded_warning.missed) { |
1036 | 1035 | pr_notice("random: %d get_random_xx warning(s) missed " |
@@ -1982,43 +1981,6 @@ void rand_initialize_disk(struct gendisk *disk) |
1982 | 1981 | } |
1983 | 1982 | #endif |
1984 | 1983 |
|
1985 | | -static ssize_t |
1986 | | -_random_read(int nonblock, char __user *buf, size_t nbytes) |
1987 | | -{ |
1988 | | - ssize_t n; |
1989 | | - |
1990 | | - if (nbytes == 0) |
1991 | | - return 0; |
1992 | | - |
1993 | | - nbytes = min_t(size_t, nbytes, SEC_XFER_SIZE); |
1994 | | - while (1) { |
1995 | | - n = extract_entropy_user(&blocking_pool, buf, nbytes); |
1996 | | - if (n < 0) |
1997 | | - return n; |
1998 | | - trace_random_read(n*8, (nbytes-n)*8, |
1999 | | - ENTROPY_BITS(&blocking_pool), |
2000 | | - ENTROPY_BITS(&input_pool)); |
2001 | | - if (n > 0) |
2002 | | - return n; |
2003 | | - |
2004 | | - /* Pool is (near) empty. Maybe wait and retry. */ |
2005 | | - if (nonblock) |
2006 | | - return -EAGAIN; |
2007 | | - |
2008 | | - wait_event_interruptible(random_read_wait, |
2009 | | - blocking_pool.initialized && |
2010 | | - (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits)); |
2011 | | - if (signal_pending(current)) |
2012 | | - return -ERESTARTSYS; |
2013 | | - } |
2014 | | -} |
2015 | | - |
2016 | | -static ssize_t |
2017 | | -random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
2018 | | -{ |
2019 | | - return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes); |
2020 | | -} |
2021 | | - |
2022 | 1984 | static ssize_t |
2023 | 1985 | urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes, |
2024 | 1986 | loff_t *ppos) |
@@ -2051,15 +2013,26 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
2051 | 2013 | return urandom_read_nowarn(file, buf, nbytes, ppos); |
2052 | 2014 | } |
2053 | 2015 |
|
| 2016 | +static ssize_t |
| 2017 | +random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
| 2018 | +{ |
| 2019 | + int ret; |
| 2020 | + |
| 2021 | + ret = wait_for_random_bytes(); |
| 2022 | + if (ret != 0) |
| 2023 | + return ret; |
| 2024 | + return urandom_read_nowarn(file, buf, nbytes, ppos); |
| 2025 | +} |
| 2026 | + |
2054 | 2027 | static __poll_t |
2055 | 2028 | random_poll(struct file *file, poll_table * wait) |
2056 | 2029 | { |
2057 | 2030 | __poll_t mask; |
2058 | 2031 |
|
2059 | | - poll_wait(file, &random_read_wait, wait); |
| 2032 | + poll_wait(file, &crng_init_wait, wait); |
2060 | 2033 | poll_wait(file, &random_write_wait, wait); |
2061 | 2034 | mask = 0; |
2062 | | - if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits) |
| 2035 | + if (crng_ready()) |
2063 | 2036 | mask |= EPOLLIN | EPOLLRDNORM; |
2064 | 2037 | if (ENTROPY_BITS(&input_pool) < random_write_wakeup_bits) |
2065 | 2038 | mask |= EPOLLOUT | EPOLLWRNORM; |
|
0 commit comments