Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1695410

Re: [PATCH v3 1/2] x86/boot/KASLR: exclude EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 1/2] x86/boot/KASLR: exclude EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice
Date Tue, 25 Jul 2017 08:30:01 +0200
Message-ID <u71vX-7IB-3@gated-at.bofh.it> (permalink)
References <u1zK2-Wq-9@gated-at.bofh.it> <u1zTJ-Zs-11@gated-at.bofh.it> <u6Lrc-5li-13@gated-at.bofh.it>
X-Original-To Matt Fleming <matt@codeblueprint.co.uk>
Thread-Topic [PATCH v3 1/2] x86/boot/KASLR: exclude EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice
Thread-Index AQHTBH8qi9Rzb/SLAkeDdA0kMcwBWqJje26A
Accept-Language en-US, ja-JP
Content-Language ja-JP
X-Originating-IP [10.128.101.4]
Content-Type text/plain; charset="iso-2022-jp"
Content-ID <D9CA4E31CB646D45ACEDE76BF8B9D035@gisp.nec.co.jp>
Content-Transfer-Encoding 8BIT
MIME-Version 1.0
X-Tm-As-Mml disable
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 51
Organization linux.* mail to news gateway
X-Original-Cc Baoquan He <bhe@redhat.com>, Kees Cook <keescook@chromium.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "x86@kernel.org" <x86@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>, "izumi.taku@jp.fujitsu.com" <izumi.taku@jp.fujitsu.com>, Thomas Garnier <thgarnie@google.com>, "fanc.fnst@cn.fujitsu.com" <fanc.fnst@cn.fujitsu.com>, Junichi Nomura <j-nomura@ce.jp.nec.com>, Ard Biesheuvel <ard.biesheuvel@linaro.org>
X-Original-Date Tue, 25 Jul 2017 06:17:11 +0000
X-Original-Message-ID <20170725061711.GB18610@hori1.linux.bs1.fc.nec.co.jp>
X-Original-References <20170710054733.GA22619@hori1.linux.bs1.fc.nec.co.jp> <1499665896-23731-1-git-send-email-n-horiguchi@ah.jp.nec.com> <20170724131707.GA11076@codeblueprint.co.uk>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1695410

Show key headers only | View raw


On Mon, Jul 24, 2017 at 02:17:07PM +0100, Matt Fleming wrote:
> On Mon, 10 Jul, at 02:51:35PM, Naoya Horiguchi wrote:
> > KASLR chooses kernel location from E820_TYPE_RAM regions by walking over
> > e820 entries now. E820_TYPE_RAM includes EFI_BOOT_SERVICES_CODE and
> > EFI_BOOT_SERVICES_DATA, so those regions can be the target. According to
> > UEFI spec, all memory regions marked as EfiBootServicesCode and
> > EfiBootServicesData are available for free memory after the first call
> > of ExitBootServices(). So such regions should be usable for kernel on
> > spec basis.
> > 
> > In x86, however, we have some workaround for broken firmware, where we
> > keep such regions reserved until SetVirtualAddressMap() is done.
> > See the following code in should_map_region():
> > 
> > 	static bool should_map_region(efi_memory_desc_t *md)
> > 	{
> > 		...
> > 		/*
> > 		 * Map boot services regions as a workaround for buggy
> > 		 * firmware that accesses them even when they shouldn't.
> > 		 *
> > 		 * See efi_{reserve,free}_boot_services().
> > 		 */
> > 		if (md->type == EFI_BOOT_SERVICES_CODE ||
> > 			md->type == EFI_BOOT_SERVICES_DATA)
> > 				return false;
> > 
> > This workaround suppressed a boot crash, but potential issues still
> > remain because no one prevents the regions from overlapping with kernel
> > image by KASLR.
> > 
> > So let's make sure that EFI_BOOT_SERVICES_{CODE|DATA} regions are never
> > chosen as kernel memory for the workaround to work fine.
> > 
> > Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> > ---
> > v2 -> v3:
> > - skip EFI_LOADER_CODE and EFI_LOADER_DATA in region scan
> > 
> > v1 -> v2:
> > - switch efi_mirror_found to local variable
> > - insert break when EFI_MEMORY_MORE_RELIABLE found
> > ---
> >  arch/x86/boot/compressed/kaslr.c | 44 +++++++++++++++++++++++++++++-----------
> >  1 file changed, 32 insertions(+), 12 deletions(-)
> 
> I think the patch content is fine, but please update the comments and
> the changelog to say why EFI_CONVENTIONAL_MEMORY was chosen, i.e. that
> it's the only memory type that we know to be free.

OK, I'll update this.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: [PATCH v3 1/2] x86/boot/KASLR: exclude  EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice Matt Fleming <matt@codeblueprint.co.uk> - 2017-07-24 15:20 +0200
  Re: [PATCH v3 1/2] x86/boot/KASLR: exclude  EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2017-07-25 08:30 +0200

csiph-web