Commit cc2187a6 authored by Borislav Petkov's avatar Borislav Petkov Committed by Thomas Gleixner

x86/microcode/AMD: Fix load of builtin microcode with randomized memory

We do not need to add the randomization offset when the microcode is
built in.
Reported-and-tested-by: default avatarEmanuel Czirai <icanrealizeum@gmail.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/20160904093736.GA11939@pd.tnicSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent c6935931
...@@ -54,6 +54,7 @@ static LIST_HEAD(pcache); ...@@ -54,6 +54,7 @@ static LIST_HEAD(pcache);
*/ */
static u8 *container; static u8 *container;
static size_t container_size; static size_t container_size;
static bool ucode_builtin;
static u32 ucode_new_rev; static u32 ucode_new_rev;
static u8 amd_ucode_patch[PATCH_MAX_SIZE]; static u8 amd_ucode_patch[PATCH_MAX_SIZE];
...@@ -281,18 +282,22 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp, ...@@ -281,18 +282,22 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp,
void __init load_ucode_amd_bsp(unsigned int family) void __init load_ucode_amd_bsp(unsigned int family)
{ {
struct cpio_data cp; struct cpio_data cp;
bool *builtin;
void **data; void **data;
size_t *size; size_t *size;
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
data = (void **)__pa_nodebug(&ucode_cpio.data); data = (void **)__pa_nodebug(&ucode_cpio.data);
size = (size_t *)__pa_nodebug(&ucode_cpio.size); size = (size_t *)__pa_nodebug(&ucode_cpio.size);
builtin = (bool *)__pa_nodebug(&ucode_builtin);
#else #else
data = &ucode_cpio.data; data = &ucode_cpio.data;
size = &ucode_cpio.size; size = &ucode_cpio.size;
builtin = &ucode_builtin;
#endif #endif
if (!load_builtin_amd_microcode(&cp, family)) *builtin = load_builtin_amd_microcode(&cp, family);
if (!*builtin)
cp = find_ucode_in_initrd(); cp = find_ucode_in_initrd();
if (!(cp.data && cp.size)) if (!(cp.data && cp.size))
...@@ -373,7 +378,8 @@ void load_ucode_amd_ap(void) ...@@ -373,7 +378,8 @@ void load_ucode_amd_ap(void)
return; return;
/* Add CONFIG_RANDOMIZE_MEMORY offset. */ /* Add CONFIG_RANDOMIZE_MEMORY offset. */
cont += PAGE_OFFSET - __PAGE_OFFSET_BASE; if (!ucode_builtin)
cont += PAGE_OFFSET - __PAGE_OFFSET_BASE;
eax = cpuid_eax(0x00000001); eax = cpuid_eax(0x00000001);
eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ); eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ);
...@@ -439,7 +445,8 @@ int __init save_microcode_in_initrd_amd(void) ...@@ -439,7 +445,8 @@ int __init save_microcode_in_initrd_amd(void)
container = cont_va; container = cont_va;
/* Add CONFIG_RANDOMIZE_MEMORY offset. */ /* Add CONFIG_RANDOMIZE_MEMORY offset. */
container += PAGE_OFFSET - __PAGE_OFFSET_BASE; if (!ucode_builtin)
container += PAGE_OFFSET - __PAGE_OFFSET_BASE;
eax = cpuid_eax(0x00000001); eax = cpuid_eax(0x00000001);
eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment