From patchwork Mon Mar 2 20:25:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 445421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D94CC1400EA for ; Tue, 3 Mar 2015 07:26:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754568AbbCBU0X (ORCPT ); Mon, 2 Mar 2015 15:26:23 -0500 Received: from cantor2.suse.de ([195.135.220.15]:42043 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754726AbbCBU0V (ORCPT ); Mon, 2 Mar 2015 15:26:21 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E6E57AAD1; Mon, 2 Mar 2015 20:26:17 +0000 (UTC) Received: by pd.tnic (Postfix, from userid 1000) id 16DFD161751; Mon, 2 Mar 2015 21:25:08 +0100 (CET) Date: Mon, 2 Mar 2015 21:25:08 +0100 From: Borislav Petkov To: Yinghai Lu Cc: Ingo Molnar , Jiri Kosina , Kees Cook , Matt Fleming , Thomas Gleixner , "H. Peter Anvin" , Ingo Molnar , Bjorn Helgaas , Linus Torvalds , Linux Kernel Mailing List , "linux-efi@vger.kernel.org" , "linux-pci@vger.kernel.org" Subject: Re: [PATCH 1/8] x86, kaslr: get kaslr_enabled back correctly Message-ID: <20150302202507.GD17532@pd.tnic> References: <20150301152351.GA17391@gmail.com> <20150301194904.GC7748@pd.tnic> <20150301202938.GD7748@pd.tnic> <20150302085654.GA17532@pd.tnic> <20150302145313.GC17532@pd.tnic> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Mon, Mar 02, 2015 at 10:58:23AM -0800, Yinghai Lu wrote: > On Mon, Mar 2, 2015 at 6:53 AM, Borislav Petkov wrote: > > Well, it seems to work here but it still doesn't look reliable enough to > > me. And this addon_zo thing of arbitrary 256K is strange. > > Thanks for check that out. > > That is not arbitrary number. Need to make that bigger than _end - _rodata > > > objdump -t arch/x86/boot/compressed/vmlinux | grep \ _end > 0000000000996000 g .pgtable 0000000000000000 _end > > objdump -t arch/x86/boot/compressed/vmlinux | grep \ _rodata > 0000000000981780 g .rodata 0000000000000000 _rodata > > We only get that size after arch/x86/boot/compressed/vmlinux > > but need number during building kernel vmlinux. > > other way would be just increase init_size in arch/x86/boot/header.S > instead of put it BRK area. Ok, I'll take a look at this more tomorrow, on a clear head, but why can't we make a special, explicit section which is not touched by the early decompression and relocation code and which we can use for setup_data only? IOW, something like that although that doesn't work yet: diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c index 7083c16cccba..01d5ddf1d22f 100644 --- a/arch/x86/boot/compressed/aslr.c +++ b/arch/x86/boot/compressed/aslr.c @@ -14,12 +14,12 @@ static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION; -struct kaslr_setup_data { - __u64 next; - __u32 type; - __u32 len; - __u8 data[1]; -} kaslr_setup_data; +extern char _setup_data[]; +struct setup_data __attribute__((section (".setup_data"))) ksd = { + .type = SETUP_KASLR, + .len = 1, + .next = 0, +}; #define I8254_PORT_CONTROL 0x43 #define I8254_PORT_COUNTER0 0x40 @@ -306,10 +306,7 @@ static void add_kaslr_setup_data(struct boot_params *params, __u8 enabled) { struct setup_data *data; - kaslr_setup_data.type = SETUP_KASLR; - kaslr_setup_data.len = 1; - kaslr_setup_data.next = 0; - kaslr_setup_data.data[0] = enabled; + ksd.data[0] = enabled; data = (struct setup_data *)(unsigned long)params->hdr.setup_data; @@ -317,10 +314,9 @@ static void add_kaslr_setup_data(struct boot_params *params, __u8 enabled) data = (struct setup_data *)(unsigned long)data->next; if (data) - data->next = (unsigned long)&kaslr_setup_data; + data->next = (unsigned long)&ksd; else - params->hdr.setup_data = (unsigned long)&kaslr_setup_data; - + params->hdr.setup_data = (unsigned long)&ksd; } unsigned char *choose_kernel_location(struct boot_params *params, diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 34d047c98284..26d62f4b27b9 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -29,6 +29,10 @@ SECTIONS .rodata..compressed : { *(.rodata..compressed) } + .setup_data : { + _setup_data = . ; + *(.setup_data) + } .text : { _text = .; /* Text */ *(.text) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 98dc9317286e..0978c61f84bd 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -429,7 +429,11 @@ static void __init reserve_initrd(void) static void __init parse_kaslr_setup(u64 pa_data, u32 data_len) { - kaslr_enabled = (bool)(pa_data + sizeof(struct setup_data)); + struct setup_data *kdata; + + kdata = early_memremap(pa_data, data_len); + kaslr_enabled = kdata->data[0]; + early_iounmap(kdata, data_len); } static void __init parse_setup_data(void)