aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/random.c43
1 files changed, 4 insertions, 39 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 7d1682ea1e86..6e455bc4a39e 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -910,12 +910,13 @@ void add_interrupt_randomness(int irq, int irq_flags)
910 910
911 /* 911 /*
912 * If we have architectural seed generator, produce a seed and 912 * If we have architectural seed generator, produce a seed and
913 * add it to the pool. For the sake of paranoia count it as 913 * add it to the pool. For the sake of paranoia don't let the
914 * 50% entropic. 914 * architectural seed generator dominate the input from the
915 * interrupt noise.
915 */ 916 */
916 if (arch_get_random_seed_long(&seed)) { 917 if (arch_get_random_seed_long(&seed)) {
917 __mix_pool_bytes(r, &seed, sizeof(seed)); 918 __mix_pool_bytes(r, &seed, sizeof(seed));
918 credit += sizeof(seed) * 4; 919 credit = 1;
919 } 920 }
920 spin_unlock(&r->lock); 921 spin_unlock(&r->lock);
921 922
@@ -1328,37 +1329,6 @@ void rand_initialize_disk(struct gendisk *disk)
1328} 1329}
1329#endif 1330#endif
1330 1331
1331/*
1332 * Attempt an emergency refill using arch_get_random_seed_long().
1333 *
1334 * As with add_interrupt_randomness() be paranoid and only
1335 * credit the output as 50% entropic.
1336 */
1337static int arch_random_refill(void)
1338{
1339 const unsigned int nlongs = 64; /* Arbitrary number */
1340 unsigned int n = 0;
1341 unsigned int i;
1342 unsigned long buf[nlongs];
1343
1344 if (!arch_has_random_seed())
1345 return 0;
1346
1347 for (i = 0; i < nlongs; i++) {
1348 if (arch_get_random_seed_long(&buf[n]))
1349 n++;
1350 }
1351
1352 if (n) {
1353 unsigned int rand_bytes = n * sizeof(unsigned long);
1354
1355 mix_pool_bytes(&input_pool, buf, rand_bytes);
1356 credit_entropy_bits(&input_pool, rand_bytes*4);
1357 }
1358
1359 return n;
1360}
1361
1362static ssize_t 1332static ssize_t
1363_random_read(int nonblock, char __user *buf, size_t nbytes) 1333_random_read(int nonblock, char __user *buf, size_t nbytes)
1364{ 1334{
@@ -1379,11 +1349,6 @@ _random_read(int nonblock, char __user *buf, size_t nbytes)
1379 return n; 1349 return n;
1380 1350
1381 /* Pool is (near) empty. Maybe wait and retry. */ 1351 /* Pool is (near) empty. Maybe wait and retry. */
1382
1383 /* First try an emergency refill */
1384 if (arch_random_refill())
1385 continue;
1386
1387 if (nonblock) 1352 if (nonblock)
1388 return -EAGAIN; 1353 return -EAGAIN;
1389 1354