aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/random.c58
-rw-r--r--include/linux/random.h4
2 files changed, 29 insertions, 33 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index e5b3d3ba4660..e027e7fa1472 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -709,7 +709,8 @@ retry:
709 } 709 }
710 710
711 /* should we wake readers? */ 711 /* should we wake readers? */
712 if (entropy_bits >= random_read_wakeup_bits) { 712 if (entropy_bits >= random_read_wakeup_bits &&
713 wq_has_sleeper(&random_read_wait)) {
713 wake_up_interruptible(&random_read_wait); 714 wake_up_interruptible(&random_read_wait);
714 kill_fasync(&fasync, SIGIO, POLL_IN); 715 kill_fasync(&fasync, SIGIO, POLL_IN);
715 } 716 }
@@ -732,7 +733,7 @@ retry:
732 733
733static int credit_entropy_bits_safe(struct entropy_store *r, int nbits) 734static int credit_entropy_bits_safe(struct entropy_store *r, int nbits)
734{ 735{
735 const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1)); 736 const int nbits_max = r->poolinfo->poolwords * 32;
736 737
737 if (nbits < 0) 738 if (nbits < 0)
738 return -EINVAL; 739 return -EINVAL;
@@ -963,7 +964,6 @@ static ssize_t extract_crng_user(void __user *buf, size_t nbytes)
963struct timer_rand_state { 964struct timer_rand_state {
964 cycles_t last_time; 965 cycles_t last_time;
965 long last_delta, last_delta2; 966 long last_delta, last_delta2;
966 unsigned dont_count_entropy:1;
967}; 967};
968 968
969#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, }; 969#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, };
@@ -1029,35 +1029,33 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
1029 * We take into account the first, second and third-order deltas 1029 * We take into account the first, second and third-order deltas
1030 * in order to make our estimate. 1030 * in order to make our estimate.
1031 */ 1031 */
1032 delta = sample.jiffies - state->last_time;
1033 state->last_time = sample.jiffies;
1034
1035 delta2 = delta - state->last_delta;
1036 state->last_delta = delta;
1037
1038 delta3 = delta2 - state->last_delta2;
1039 state->last_delta2 = delta2;
1040
1041 if (delta < 0)
1042 delta = -delta;
1043 if (delta2 < 0)
1044 delta2 = -delta2;
1045 if (delta3 < 0)
1046 delta3 = -delta3;
1047 if (delta > delta2)
1048 delta = delta2;
1049 if (delta > delta3)
1050 delta = delta3;
1032 1051
1033 if (!state->dont_count_entropy) { 1052 /*
1034 delta = sample.jiffies - state->last_time; 1053 * delta is now minimum absolute delta.
1035 state->last_time = sample.jiffies; 1054 * Round down by 1 bit on general principles,
1036 1055 * and limit entropy entimate to 12 bits.
1037 delta2 = delta - state->last_delta; 1056 */
1038 state->last_delta = delta; 1057 credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
1039
1040 delta3 = delta2 - state->last_delta2;
1041 state->last_delta2 = delta2;
1042
1043 if (delta < 0)
1044 delta = -delta;
1045 if (delta2 < 0)
1046 delta2 = -delta2;
1047 if (delta3 < 0)
1048 delta3 = -delta3;
1049 if (delta > delta2)
1050 delta = delta2;
1051 if (delta > delta3)
1052 delta = delta3;
1053 1058
1054 /*
1055 * delta is now minimum absolute delta.
1056 * Round down by 1 bit on general principles,
1057 * and limit entropy entimate to 12 bits.
1058 */
1059 credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
1060 }
1061 preempt_enable(); 1059 preempt_enable();
1062} 1060}
1063 1061
diff --git a/include/linux/random.h b/include/linux/random.h
index 4024f7d9c77d..2ddf13b4281e 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -85,10 +85,8 @@ static inline unsigned long get_random_canary(void)
85static inline int get_random_bytes_wait(void *buf, int nbytes) 85static inline int get_random_bytes_wait(void *buf, int nbytes)
86{ 86{
87 int ret = wait_for_random_bytes(); 87 int ret = wait_for_random_bytes();
88 if (unlikely(ret))
89 return ret;
90 get_random_bytes(buf, nbytes); 88 get_random_bytes(buf, nbytes);
91 return 0; 89 return ret;
92} 90}
93 91
94#define declare_get_random_var_wait(var) \ 92#define declare_get_random_var_wait(var) \