Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbdGGK6S (ORCPT ); Fri, 7 Jul 2017 06:58:18 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:36081 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751929AbdGGK6R (ORCPT ); Fri, 7 Jul 2017 06:58:17 -0400 Date: Fri, 7 Jul 2017 11:58:14 +0100 From: Matt Fleming To: Naoya Horiguchi Cc: Baoquan He , Kees Cook , LKML , "x86@kernel.org" , Thomas Gleixner , "H. Peter Anvin" , Ingo Molnar , "izumi.taku@jp.fujitsu.com" , Thomas Garnier , "fanc.fnst@cn.fujitsu.com" , Junichi Nomura , Ard Biesheuvel Subject: Re: [PATCH] x86/boot/KASLR: exclude EFI_BOOT_SERVICES_{CODE|DATA} from KASLR's choice Message-ID: <20170707105814.GB9917@codeblueprint.co.uk> References: <20170706083106.GA21796@hori1.linux.bs1.fc.nec.co.jp> <20170706145727.GB3080@codeblueprint.co.uk> <20170707030759.GA2343@x1> <20170707061123.GA32236@hori1.linux.bs1.fc.nec.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170707061123.GA32236@hori1.linux.bs1.fc.nec.co.jp> User-Agent: Mutt/1.5.24+42 (6e565710a064) (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1797 Lines: 41 On Fri, 07 Jul, at 06:11:24AM, Naoya Horiguchi wrote: > On Fri, Jul 07, 2017 at 11:07:59AM +0800, Baoquan He wrote: > > On 07/06/17 at 03:57pm, Matt Fleming wrote: > > > On Thu, 06 Jul, at 08:31:07AM, Naoya Horiguchi wrote: > > > > + for (i = 0; i < nr_desc; i++) { > > > > + md = (efi_memory_desc_t *)(pmap + (i * e->efi_memdesc_size)); > > > > + > > > > + /* > > > > + * EFI_BOOT_SERVICES_{CODE|DATA} are avoided because boot > > > > + * services regions could be accessed after ExitBootServices() > > > > + * due to the workaround for buggy firmware. > > > > + */ > > > > + if (!(md->type == EFI_LOADER_CODE || > > > > + md->type == EFI_LOADER_DATA || > > > > + md->type == EFI_CONVENTIONAL_MEMORY)) > > > > + continue; > > > > > > Wouldn't it make more sense to *only* use EFI_CONVENTIONAL_MEMORY? > > > > > > You can't re-use EFI_LOADER_* regions because the kaslr code is run so > > > early in boot that you've no idea if data the kernel will need is in > > > those EFI_LOADER_* regions. > > > > > > For example, we pass struct setup_data objects inside of > > > EFI_LOADER_DATA regions. > > > > It doesn't matter because we have tried to avoid those memory setup_data > > resides in in mem_avoid_overlap(). Here discarding EFI_LOADER_* could > > discard the whole regions while setup_data could occupy small part of > > them. > > Hi Matt, Baoquan, > > I added these three checks to accept any regions corresponding to > E820_TYPE_RAM except EFI_BOOT_SERVICES_*, just thinking of that it's minimum > surprising. Baoquan gave a good justification on that, so I'll leave it > as-is in next version. I disagree. The least surprising option would be to use the region type that everyone (boot loader, kernel, firmware) agrees is free: EFI_CONVENTIONAL_MEMORY.