lkml.org 
[lkml]   [2014]   [Feb]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH,RFC] random: collect cpu randomness
Il 02/02/2014 21:36, Jörn Engel ha scritto:
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wuninitialized"
> + input[0] ^= cycles ^ jiffies;
> + input[1] ^= (unsigned long)caller;
> + input[2] ^= (unsigned long)val;
> + input[3] ^= (unsigned long)&input;
> +#pragma GCC diagnostic pop

Your tests demonstrate that this works, and presumably you have checked
the assembly too. Still, this is invoking undefined behavior and the
compiler could justifiably change those "^=" to "=".

An "asm" would be a safer way to convince the compiler that input[] is
now initialized:

asm volatile ("" :
"=m" (input[0]), "=m" (input[1]),
"=m" (input[2]), "=m" (input[3]));

and *really* XOR the values into the contents of the stack.

Of course the compiler could still have a "feature" where it
pre-initializes the whole stack frame with some kind of canary, but that
would be a problem even with your version of the code.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2014-02-20 11:21    [W:0.141 / U:0.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site