Skip to content

Commit e8236c4

Browse files
author
H. Peter Anvin
committed
x86, kaslr: Add a circular multiply for better bit diffusion
If we don't have RDRAND (in which case nothing else *should* matter), most sources have a highly biased entropy distribution. Use a circular multiply to diffuse the entropic bits. A circular multiply is a good operation for this: it is cheap on standard hardware and because it is symmetric (unlike an ordinary multiply) it doesn't introduce its own bias. Cc: Kees Cook <keescook@chromium.org> Signed-off-by: H. Peter Anvin <hpa@zytor.com> Link: http://lkml.kernel.org/r/20131111222839.GA28616@www.outflux.net
1 parent a653f35 commit e8236c4

File tree

1 file changed

+11
-0
lines changed
  • arch/x86/boot/compressed

1 file changed

+11
-0
lines changed

arch/x86/boot/compressed/aslr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ static unsigned long get_random_boot(void)
6464

6565
static unsigned long get_random_long(void)
6666
{
67+
#ifdef CONFIG_X86_64
68+
const unsigned long mix_const = 0x5d6008cbf3848dd3UL;
69+
#else
70+
const unsigned long mix_const = 0x3f39e593UL;
71+
#endif
6772
unsigned long raw, random = get_random_boot();
6873
bool use_i8254 = true;
6974

@@ -90,6 +95,12 @@ static unsigned long get_random_long(void)
9095
random ^= i8254();
9196
}
9297

98+
/* Circular multiply for better bit diffusion */
99+
asm("mul %3"
100+
: "=a" (random), "=d" (raw)
101+
: "a" (random), "rm" (mix_const));
102+
random += raw;
103+
93104
debug_putstr("...\n");
94105

95106
return random;

0 commit comments

Comments
 (0)