Re: [patch] random: make get_random_int() more random
From: AmÃrico Wang
Date: Thu May 14 2009 - 21:16:33 EST
On Thu, May 7, 2009 at 4:09 AM, Ingo Molnar <mingo@xxxxxxx> wrote:
>
> * Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
>> On Wed, 6 May 2009, Matt Mackall wrote:
>>
>> > On Wed, May 06, 2009 at 12:30:34PM +0200, Ingo Molnar wrote:
>>
>> > > (Also, obviously "only" covering 95% of the Linux systems has
>> > > its use as well. Most other architectures have their own cycle
>> > > counters as well.)
>> >
>> > X86 might be 95% of desktop. But it's a small fraction of Linux
>> > systems once you count cell phones, video players, TVs, cameras,
>> > GPS devices, cars, routers, etc. almost none of which are
>> > x86-based. In fact, just Linux cell phones (with about an 8%
>> > share of a 1.2billion devices per year market) dwarf Linux
>> > desktops (maybe 5% of a 200m/y market).
>>
>> Matt, are you willing to ack my suggested patch which adds history
>> to the mix? Did somebody test that? I have this memory of there
>> being an "exploit" program to show the non-randomness of the
>> values, but I can't recall details, and would really want to get a
>> second opinion from somebody who cares about PRNG's.
>
> I tested it, and besides booting up fine, i also tested the
> get_random_int() randomness. I did this by adding this quick
> trace_printk() line:
>
> Â trace_printk("get_random_int(): %08x\n", get_random_int());
>
> to sys_prctl() and triggered sys_prctl() in a loop, which gave a
> list of get_random_int() numbers:
>
> # tracer: nop
> #
> # Â Â Â Â Â TASK-PID Â ÂCPU# Â ÂTIMESTAMP ÂFUNCTION
> # Â Â Â Â Â Â Â| | Â Â Â | Â Â Â Â Â| Â Â Â Â |
> Â Â Â Â Â <...>-6288 Â[000] Â 618.151323: sys_prctl: get_random_int(): 2e927f66
> Â Â Â Â Â <...>-6290 Â[000] Â 618.152924: sys_prctl: get_random_int(): d210df1f
> Â Â Â Â Â <...>-6293 Â[000] Â 618.155326: sys_prctl: get_random_int(): 753ad860
> Â Â Â Â Â <...>-6295 Â[000] Â 618.156939: sys_prctl: get_random_int(): c74d935f
> Â Â Â Â Â <...>-6298 Â[000] Â 618.159334: sys_prctl: get_random_int(): bb4e7597
> Â Â Â Â Â <...>-6300 Â[000] Â 618.160936: sys_prctl: get_random_int(): b0119885
> Â Â Â Â Â <...>-6303 Â[000] Â 618.163331: sys_prctl: get_random_int(): 093f5c70
>
I used systemtap to test this patch too, the result is too obvious. :-)
Samples of output are the following:
==before this patch==
get_random_int returns: f3f71569
get_random_int returns: f3f71569
get_random_int returns: f3f71569
get_random_int returns: f3f71569
get_random_int returns: f3f71569
get_random_int returns: f3f71569
get_random_int returns: c3e650c8
get_random_int returns: c3e650c8
get_random_int returns: c3e650c8
get_random_int returns: c3e650c8
get_random_int returns: c3e650c8
get_random_int returns: c3e650c8
==after this patch==
get_random_int returns: b7566a5b
get_random_int returns: f4b86171
get_random_int returns: 25dd8fd8
get_random_int returns: 58ab81ce
get_random_int returns: f39dbcb2
get_random_int returns: cbf308f9
get_random_int returns: 32d9c09e
get_random_int returns: 4eedfcad
get_random_int returns: fe87cb99
get_random_int returns: 1bd42857
get_random_int returns: 837cf921
get_random_int returns: d9a39d80
Hope this helps.
Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/