diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-12-22 14:36:22 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2011-12-29 19:49:45 -0500 |
commit | cf833d0b9937874b50ef2867c4e8badfd64948ce (patch) | |
tree | f2eb260e524387c6dce6de17b5c06ec0c34adef7 /drivers/char/random.c | |
parent | 5f0a6e2d503896062f641639dacfe5055c2f593b (diff) |
random: Use arch_get_random_int instead of cycle counter if avail
We still don't use rdrand in /dev/random, which just seems stupid. We
accept the *cycle*counter* as a random input, but we don't accept
rdrand? That's just broken.
Sure, people can do things in user space (write to /dev/random, use
rdrand in addition to /dev/random themselves etc etc), but that
*still* seems to be a particularly stupid reason for saying "we
shouldn't bother to try to do better in /dev/random".
And even if somebody really doesn't trust rdrand as a source of random
bytes, it seems singularly stupid to trust the cycle counter *more*.
So I'd suggest the attached patch. I'm not going to even bother
arguing that we should add more bits to the entropy estimate, because
that's not the point - I don't care if /dev/random fills up slowly or
not, I think it's just stupid to not use the bits we can get from
rdrand and mix them into the strong randomness pool.
Link: http://lkml.kernel.org/r/CA%2B55aFwn59N1=m651QAyTy-1gO1noGbK18zwKDwvwqnravA84A@mail.gmail.com
Acked-by: "David S. Miller" <davem@davemloft.net>
Acked-by: "Theodore Ts'o" <tytso@mit.edu>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r-- | drivers/char/random.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 6035ab8d5ef7..85da8740586b 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -624,8 +624,8 @@ static struct timer_rand_state input_timer_state; | |||
624 | static void add_timer_randomness(struct timer_rand_state *state, unsigned num) | 624 | static void add_timer_randomness(struct timer_rand_state *state, unsigned num) |
625 | { | 625 | { |
626 | struct { | 626 | struct { |
627 | cycles_t cycles; | ||
628 | long jiffies; | 627 | long jiffies; |
628 | unsigned cycles; | ||
629 | unsigned num; | 629 | unsigned num; |
630 | } sample; | 630 | } sample; |
631 | long delta, delta2, delta3; | 631 | long delta, delta2, delta3; |
@@ -637,7 +637,11 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num) | |||
637 | goto out; | 637 | goto out; |
638 | 638 | ||
639 | sample.jiffies = jiffies; | 639 | sample.jiffies = jiffies; |
640 | sample.cycles = get_cycles(); | 640 | |
641 | /* Use arch random value, fall back to cycles */ | ||
642 | if (!arch_get_random_int(&sample.cycles)) | ||
643 | sample.cycles = get_cycles(); | ||
644 | |||
641 | sample.num = num; | 645 | sample.num = num; |
642 | mix_pool_bytes(&input_pool, &sample, sizeof(sample)); | 646 | mix_pool_bytes(&input_pool, &sample, sizeof(sample)); |
643 | 647 | ||