Re: [PATCH,RFC] random: collect cpu randomness

From: Paolo Bonzini
Date: Thu Feb 20 2014 - 04:50:38 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/