Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757777AbcCDCZq (ORCPT ); Thu, 3 Mar 2016 21:25:46 -0500 Received: from mail-vk0-f52.google.com ([209.85.213.52]:35444 "EHLO mail-vk0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757005AbcCDCZo convert rfc822-to-8bit (ORCPT ); Thu, 3 Mar 2016 21:25:44 -0500 MIME-Version: 1.0 In-Reply-To: <20160303122836.GC24621@pd.tnic> References: <20160302181556.GD8362@pd.tnic> <56D73349.3020609@zytor.com> <20160302195053.GG8362@pd.tnic> <56D75C8D.90800@zytor.com> <20160302214654.GK8362@pd.tnic> <56D7612A.4080107@zytor.com> <20160302220954.GL8362@pd.tnic> <56D76527.5020806@zytor.com> <20160302222842.GM8362@pd.tnic> <20160303122836.GC24621@pd.tnic> Date: Thu, 3 Mar 2016 18:25:42 -0800 X-Google-Sender-Auth: 6DSGLIGYHqr2lDc2w_3BM_HKSyQ Message-ID: Subject: Re: [RFC PATCH] x86: Make sure verify_cpu has a good stack From: Yinghai Lu To: Borislav Petkov Cc: "H. Peter Anvin" , Brian Gerst , X86 ML , LKML , Tom Lendacky Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3042 Lines: 86 On Thu, Mar 3, 2016 at 4:28 AM, Borislav Petkov wrote: > From: Borislav Petkov > Date: Sun, 28 Feb 2016 21:35:44 +0100 > Subject: [PATCH -v2] x86/asm: Make sure verify_cpu() has a good stack > 04633df0c43d ("x86/cpu: Call verify_cpu() after having entered long mode too") > added the call to verify_cpu() for sanitizing CPU configuration. > > The latter uses the stack minimally and it can happen that we land in > startup_64() directly from a 64-bit bootloader. Then we want to use our > own, known good stack. > > Reported-by: Tom Lendacky > Signed-off-by: Borislav Petkov > Cc: Brian Gerst > Cc: "H. Peter Anvin" > Cc: Mika Penttilä > --- > arch/x86/kernel/head_64.S | 3 +++ > include/asm-generic/vmlinux.lds.h | 4 +++- > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S > index 22fbf9df61bb..968d6408b887 100644 > --- a/arch/x86/kernel/head_64.S > +++ b/arch/x86/kernel/head_64.S > @@ -64,6 +64,9 @@ startup_64: > * tables and then reload them. > */ > > + /* Setup stack for verify_cpu(). */ > + leaq (__end_init_task - 8)(%rip), %rsp > + > /* Sanitize CPU configuration */ > call verify_cpu > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h > index 772c784ba763..cba2a26628fc 100644 > --- a/include/asm-generic/vmlinux.lds.h > +++ b/include/asm-generic/vmlinux.lds.h > @@ -246,7 +246,9 @@ > > #define INIT_TASK_DATA(align) \ > . = ALIGN(align); \ > - *(.data..init_task) > + VMLINUX_SYMBOL(__start_init_task) = .; \ > + *(.data..init_task) \ > + VMLINUX_SYMBOL(__end_init_task) = .; > > /* > * Read only Data > -- > 2.3.5 I would suggest moving down verify_cpu calling after offset is calcuated, like following instead of adding __end_init_task. diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 22fbf9d..e8c8085 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -64,9 +64,6 @@ startup_64: * tables and then reload them. */ - /* Sanitize CPU configuration */ - call verify_cpu - /* * Compute the delta between the address I am compiled to run at and the * address I am actually running at. @@ -74,6 +71,14 @@ startup_64: leaq _text(%rip), %rbp subq $_text - __START_KERNEL_map, %rbp + /* Setup stack for verify_cpu() */ + movq stack_start(%rip), %rsp + subq $__START_KERNEL_map, %rsp + addq %rbp, %rsp + + /* Sanitize CPU configuration */ + call verify_cpu + /* Is the address not 2M aligned? */ testl $~PMD_PAGE_MASK, %ebp jnz bad_address