@@ -1382,12 +1382,22 @@ static void try_to_generate_entropy(void)
unsigned long entropy;
struct timer_list timer;
} stack;
+ int i;
+ /*
+ * We must not proceed if we don't actually have a cycle counter. To
+ * detect a cycle counter, check whether random_get_entropy() returns a
+ * new value each time. Check this multiple times to avoid false
+ * positives where a slow counter could be just on the cusp of a change.
+ */
stack.entropy = random_get_entropy();
+ for (i = 0; i < 3; i++) {
+ unsigned long entropy = random_get_entropy();
- /* Slow counter - or none. Don't even bother */
- if (stack.entropy == random_get_entropy())
- return;
+ if (stack.entropy == entropy)
+ return;
+ stack.entropy = entropy;
+ }
timer_setup_on_stack(&stack.timer, entropy_timer, 0);
while (!crng_ready() && !signal_pending(current)) {