From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752923AbcHQKT6 (ORCPT ); Wed, 17 Aug 2016 06:19:58 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34097 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbcHQKTz (ORCPT ); Wed, 17 Aug 2016 06:19:55 -0400 Date: Wed, 17 Aug 2016 12:19:48 +0200 From: Ingo Molnar To: Borislav Petkov Cc: Brian Gerst , Kees Cook , Baoquan He , Yinghai Lu , Juergen Gross , Thomas Garnier , Andy Lutomirski , "H. Peter Anvin" , Alexander Kuleshov , Josh Poimboeuf , Christian Borntraeger , Stephen Smalley , "Kirill A. Shutemov" , Joerg Roedel , "Williams, Dan J" , Mark Salter , Borislav Petkov , Jonathan Corbet , Matt Fleming , Xiao Guangrong , "Aneesh Kumar K.V" , Linus Torvalds , Dave Hansen , Toshi Kani , Alexander Popov , Linux Kernel Mailing List , Jan Beulich , Andrew Morton , Boris Ostrovsky , Denys Vlasenko , Peter Zijlstra , Dave Young , Thomas Gleixner , Dmitry Vyukov , Lv Zheng , Martin Schwidefsky , "linux-tip-commits@vger.kernel.org" Subject: Re: [tip:x86/boot] x86/mm: Enable KASLR for physical mapping memory regions Message-ID: <20160817101948.GA31863@gmail.com> References: <20160814232657.GA10704@x1.redhat.com> <20160816134205.GB11106@nazgul.tnic> <20160816134928.GC11106@nazgul.tnic> <20160816155412.GB15004@nazgul.tnic> <20160816175008.GA10538@nazgul.tnic> <20160816210108.GA6332@nazgul.tnic> <20160817091129.GA27516@nazgul.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160817091129.GA27516@nazgul.tnic> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Borislav Petkov wrote: > On Tue, Aug 16, 2016 at 08:31:28PM -0400, Brian Gerst wrote: > > These fixes work for my system. > > Thanks Brian. > > Ingo, please queue this into x86/urgent. > > Thanks! > > --- > From: Borislav Petkov > Date: Wed, 17 Aug 2016 08:23:29 +0200 > Subject: [PATCH] x86/microcode/AMD: Fix initrd loading with CONFIG_RANDOMIZE_MEMORY=y > > Similar to > > efaad554b4ff ("x86/microcode/intel: Fix initrd loading with CONFIG_RANDOMIZE_MEMORY=y") > > fix microcode loading from the initrd on AMD by adding the randomization > offset to the microcode patch container within the initrd. > > Reported-and-tested-by: Brian Gerst > Signed-off-by: Borislav Petkov > Cc: Kees Cook > --- > arch/x86/kernel/cpu/microcode/amd.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c > index 27a0228c9cae..f43b774d0684 100644 > --- a/arch/x86/kernel/cpu/microcode/amd.c > +++ b/arch/x86/kernel/cpu/microcode/amd.c > @@ -355,6 +355,7 @@ void load_ucode_amd_ap(void) > unsigned int cpu = smp_processor_id(); > struct equiv_cpu_entry *eq; > struct microcode_amd *mc; > + u8 *cont; > u32 rev, eax; > u16 eq_id; > > @@ -371,8 +372,14 @@ void load_ucode_amd_ap(void) > if (check_current_patch_level(&rev, false)) > return; > > + cont = container; > + > +#ifdef CONFIG_RANDOMIZE_MEMORY > + cont += PAGE_OFFSET - __PAGE_OFFSET_BASE; > +#endif > + > eax = cpuid_eax(0x00000001); > - eq = (struct equiv_cpu_entry *)(container + CONTAINER_HDR_SZ); > + eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ); > > eq_id = find_equiv_id(eq, eax); > if (!eq_id) > @@ -434,6 +441,10 @@ int __init save_microcode_in_initrd_amd(void) > else > container = cont_va; > > +#ifdef CONFIG_RANDOMIZE_MEMORY > + container += PAGE_OFFSET - __PAGE_OFFSET_BASE; > +#endif > + > eax = cpuid_eax(0x00000001); > eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); So I really hate this pattern, and we already have it in arch/x86/kernel/cpu/microcode/intel.c as well: start += PAGE_OFFSET - __PAGE_OFFSET_BASE; and note that it's not #ifdefed there - I think it's safe to leave out the #ifdef? Thanks, Ingo