From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752256AbdGDOal (ORCPT ); Tue, 4 Jul 2017 10:30:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33008 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750891AbdGDOak (ORCPT ); Tue, 4 Jul 2017 10:30:40 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69E478123A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=bhe@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69E478123A Date: Tue, 4 Jul 2017 22:30:34 +0800 From: Baoquan He To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, mingo@kernel.org, keescook@chromium.org, thgarnie@google.com, caoj.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com Subject: Re: [PATCH v2 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Message-ID: <20170704143034.GA25192@x1> References: <1499155442-17467-1-git-send-email-bhe@redhat.com> <1499155442-17467-3-git-send-email-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.0 (2016-08-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 04 Jul 2017 14:30:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/04/17 at 04:00pm, Thomas Gleixner wrote: > On Tue, 4 Jul 2017, Baoquan He wrote: > > +/* Marks if efi mirror regions have been found and handled. */ > > +static bool efi_mirror_found; > > + > > +static void process_efi_entry(unsigned long minimum, unsigned long image_size) > > +{ > > + struct efi_info *e = &boot_params->efi_info; > > + struct mem_vector region; > > + efi_memory_desc_t *md; > > + unsigned long pmap; > > + char *signature; > > + u32 nr_desc; > > + int i; > > + > > + > > +#ifdef CONFIG_EFI > > + signature = (char *)&boot_params->efi_info.efi_loader_signature; > > +#endif > > So if CONFIG_EFI=n you happily dereference the uninitialized signature > pointer ... Right, this is a mistake. Thanks for pointing it out. I should have checked if the pointer is NULL. In fact I just referred to code in setup_arch(). Now I have a question, though CONFIG_EFI=y but efi firmware is not enabled, boot_params.efi_info.efi_loader_signature should be initilized to 0. Then below code is also problematic. #ifdef CONFIG_EFI if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, EFI32_LOADER_SIGNATURE, 4)) { set_bit(EFI_BOOT, &efi.flags); } else if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, EFI64_LOADER_SIGNATURE, 4)) { set_bit(EFI_BOOT, &efi.flags); set_bit(EFI_64BIT, &efi.flags); } if (efi_enabled(EFI_BOOT)) efi_memblock_x86_reserve_range(); #endif > > Why is process_efi_entry() invoked at all if EFI is not enabled? Yeah, and it's better to check if CONFIG_EFI is enabled before invocation of process_efi_entry(). Let me change it as below and repost. Thanks again for looking into this patchset. +#ifdef CONFIG_EFI process_efi_entry(minimum, image_size); +#endif > > > + if (strncmp(signature, EFI32_LOADER_SIGNATURE, 4) && > > + strncmp(signature, EFI64_LOADER_SIGNATURE, 4)) > > + return; > > + > > Thanks, > > tglx