From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752514AbcHPTt5 (ORCPT ); Tue, 16 Aug 2016 15:49:57 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36390 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266AbcHPTtz (ORCPT ); Tue, 16 Aug 2016 15:49:55 -0400 MIME-Version: 1.0 In-Reply-To: <20160816175008.GA10538@nazgul.tnic> References: <1466556426-32664-7-git-send-email-keescook@chromium.org> <20160814232657.GA10704@x1.redhat.com> <20160816134205.GB11106@nazgul.tnic> <20160816134928.GC11106@nazgul.tnic> <20160816155412.GB15004@nazgul.tnic> <20160816175008.GA10538@nazgul.tnic> From: Kees Cook Date: Tue, 16 Aug 2016 12:49:52 -0700 X-Google-Sender-Auth: OcqFG7cq1HegBxSNk3CAOem0AgQ Message-ID: Subject: Re: [tip:x86/boot] x86/mm: Enable KASLR for physical mapping memory regions To: Borislav Petkov Cc: Brian Gerst , 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" , Ingo Molnar , 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" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 16, 2016 at 10:50 AM, Borislav Petkov wrote: > On Tue, Aug 16, 2016 at 05:54:12PM +0200, Borislav Petkov wrote: >> Ok, I ran this in a guest and it finds the microcode patches properly. > > Here's a better version to take care of the APs too: > > --- > diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c > index 27a0228c9cae..05242322e324 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,12 @@ void load_ucode_amd_ap(void) > if (check_current_patch_level(&rev, false)) > return; > > +#ifdef CONFIG_RANDOMIZE_MEMORY > + cont = container + 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); Am I misreading this? Shouldn't it be: cont = container; #ifdef CONFIG_RANDOMIZE_MEMORY cont += PAGE_OFFSET - __PAGE_OFFSET_BASE; #endif (otherwise cont is undefined in the RANDOMIZE_MEMORY=n case?) > > eq_id = find_equiv_id(eq, eax); > if (!eq_id) > @@ -434,6 +439,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); > > > -- > Regards/Gruss, > Boris. > > ECO tip #101: Trim your mails when you reply. > -- -Kees -- Kees Cook Nexus Security