Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1592454imm; Wed, 8 Aug 2018 21:33:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxSD/vp1wzp6Ly80hqpMxDdmJ89DQ2WKf1+Pnc4zf6CUGN7fQiduCKB4d9Lm7Wnc/e3Ht0z X-Received: by 2002:a62:3856:: with SMTP id f83-v6mr636605pfa.48.1533789192591; Wed, 08 Aug 2018 21:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533789192; cv=none; d=google.com; s=arc-20160816; b=wOaFXAZYKnvh73wtROI99IW2NU4/XA0n0cGH8AMMalq+wo/GGK9Gs7iq1x01tW3Al8 EaI3XsAWN7j+ihdcjzw3q1A7xpDgXCWgljDr0oQ0eSUTany3JAH2m/uFSilcU63j15Yl tWlz2tlF5JgJlBMNAM6Xd0ixAQbZpGYxYvUMGhNzLrKakO2pEoppRTV0oD1kAoHcP6+r xxrPn6DYyBNRecUZfoIktepAPlw2UMraGM3ulrdl6jhtCWpT0cMFEgOo6dlQ1OJwQTZY pHNv9JIfhJX3FFY9KsTo+EjfG8Of+9IqZ/YKK6cery4HBZJlT/dWMGgn7HGyNbIP98Di O1Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=fKDqJxAMCuMpLectkIVNiW+27c9VZ4yVroevk7meN4w=; b=vOqVWVVslmNuWcl+zl49W95xXgHLyakdZ/331EtAGhoefiR1HTLDzhmMCQh2hAPgq1 hiAcvzqQejqK8cRm3jht/NGeM5Spmcxj1+UUE0pThjO3iVDx8azDORQDq+K37yKDAve8 vgq9GGSL6ya2psn/4q54D54jWipitoLUNCVasHXH7EHjA+co2cbfreud+XkjQIr+MKD7 zALWGO+qIFQLwDcXKBhD1+pWoLcekPaphII4Mp64D+EzDCWklo2aDqW19q17EQqHKN/H pGUIMtNc2vn/RLNUcbe9emGrrPc34eVmLwgE4gwNMOxKk6hxSDeae2zGTof1UiX5i2Pl 52ig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w37-v6si6375595pgl.514.2018.08.08.21.32.58; Wed, 08 Aug 2018 21:33:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbeHIGys (ORCPT + 99 others); Thu, 9 Aug 2018 02:54:48 -0400 Received: from mga11.intel.com ([192.55.52.93]:22077 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727211AbeHIGys (ORCPT ); Thu, 9 Aug 2018 02:54:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Aug 2018 21:31:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,213,1531810800"; d="scan'208";a="61024031" Received: from sai-dev-mach.sc.intel.com ([143.183.140.52]) by fmsmga007.fm.intel.com with ESMTP; 08 Aug 2018 21:31:57 -0700 From: Sai Praneeth Prakhya To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ricardo.ner@intel.com, matt@codeblueprint.co.uk, Sai Praneeth , Lee Chun-Yi , Al Stone , Borislav Petkov , Ingo Molnar , Andy Lutomirski , Bhupesh Sharma , Peter Zijlstra , Ard Biesheuvel Subject: [PATCH V1 2/6] x86/efi: Remove __init attribute from memory mapping functions Date: Wed, 8 Aug 2018 21:31:13 -0700 Message-Id: <1533789077-16156-3-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533789077-16156-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1533789077-16156-1-git-send-email-sai.praneeth.prakhya@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Buggy firmware could illegally access EFI_BOOT_SERVICES_CODE/DATA regions even after the kernel has assumed control of the platform. When "CONFIG_EFI_WARN_ON_ILLEGAL_ACCESSES" is enabled, the efi page fault handler will detect/fixup these illegal accesses. The below modified functions are used by the page fault handler to fixup illegal accesses to EFI_BOOT_SERVICES_CODE/DATA regions. As the page fault handler is present during/after kernel boot it doesn't have an __init attribute, but the below functions have it and thus during kernel build, "WARNING: modpost: Found * section mismatch(es)" build warning is observed. To fix it, remove __init attribute for all these functions. In order to not keep these functions needlessly when "CONFIG_EFI_WARN_ON_ILLEGAL_ACCESSES" is not selected, add a new __efi_init_fixup attribute whose value changes based on whether the config option is selected or not. Suggested-by: Matt Fleming Based-on-code-from: Ricardo Neri Signed-off-by: Sai Praneeth Prakhya Cc: Lee Chun-Yi Cc: Al Stone Cc: Borislav Petkov Cc: Ingo Molnar Cc: Andy Lutomirski Cc: Bhupesh Sharma Cc: Peter Zijlstra Cc: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 11 ++++++----- arch/x86/platform/efi/efi.c | 4 ++-- arch/x86/platform/efi/efi_32.c | 2 +- arch/x86/platform/efi/efi_64.c | 9 +++++---- drivers/firmware/efi/efi.c | 6 +++--- include/linux/efi.h | 16 ++++++++++++++-- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index cec5fae23eb3..9b70743400f3 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -103,8 +103,9 @@ struct efi_scratch { preempt_enable(); \ }) -extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size, - u32 type, u64 attribute); +extern void __iomem *__efi_init_fixup efi_ioremap(unsigned long addr, + unsigned long size, u32 type, + u64 attribute); #ifdef CONFIG_KASAN /* @@ -126,13 +127,13 @@ extern int __init efi_memblock_x86_reserve_range(void); extern pgd_t * __init efi_call_phys_prolog(void); extern void __init efi_call_phys_epilog(pgd_t *save_pgd); extern void __init efi_print_memmap(void); -extern void __init efi_memory_uc(u64 addr, unsigned long size); -extern void __init efi_map_region(efi_memory_desc_t *md); +extern void __efi_init_fixup efi_memory_uc(u64 addr, unsigned long size); +extern void __efi_init_fixup efi_map_region(efi_memory_desc_t *md); extern void __init efi_map_region_fixed(efi_memory_desc_t *md); extern void efi_sync_low_kernel_mappings(void); extern int __init efi_alloc_page_tables(void); extern int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages); -extern void __init old_map_region(efi_memory_desc_t *md); +extern void __efi_init_fixup old_map_region(efi_memory_desc_t *md); extern void __init runtime_code_page_mkexec(void); extern void __init efi_runtime_update_mappings(void); extern void __init efi_dump_pagetable(void); diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 9061babfbc83..439c2c40bf03 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -572,7 +572,7 @@ void __init runtime_code_page_mkexec(void) } } -void __init efi_memory_uc(u64 addr, unsigned long size) +void __efi_init_fixup efi_memory_uc(u64 addr, unsigned long size) { unsigned long page_shift = 1UL << EFI_PAGE_SHIFT; u64 npages; @@ -582,7 +582,7 @@ void __init efi_memory_uc(u64 addr, unsigned long size) set_memory_uc(addr, npages); } -void __init old_map_region(efi_memory_desc_t *md) +void __efi_init_fixup old_map_region(efi_memory_desc_t *md) { u64 start_pfn, end_pfn, end; unsigned long size; diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c index 324b93328b37..8f31452bd204 100644 --- a/arch/x86/platform/efi/efi_32.c +++ b/arch/x86/platform/efi/efi_32.c @@ -58,7 +58,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) return 0; } -void __init efi_map_region(efi_memory_desc_t *md) +void __efi_init_fixup efi_map_region(efi_memory_desc_t *md) { old_map_region(md); } diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index 448267f1c073..a04298312fdd 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -408,7 +408,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) return 0; } -static void __init __map_region(efi_memory_desc_t *md, u64 va) +static void __efi_init_fixup __map_region(efi_memory_desc_t *md, u64 va) { unsigned long flags = _PAGE_RW; unsigned long pfn; @@ -426,7 +426,7 @@ static void __init __map_region(efi_memory_desc_t *md, u64 va) md->phys_addr, va); } -void __init efi_map_region(efi_memory_desc_t *md) +void __efi_init_fixup efi_map_region(efi_memory_desc_t *md) { unsigned long size = md->num_pages << PAGE_SHIFT; u64 pa = md->phys_addr; @@ -488,8 +488,9 @@ void __init efi_map_region_fixed(efi_memory_desc_t *md) __map_region(md, md->virt_addr); } -void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size, - u32 type, u64 attribute) +void __iomem *__efi_init_fixup efi_ioremap(unsigned long phys_addr, + unsigned long size, u32 type, + u64 attribute) { unsigned long last_map_pfn; diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index d8a33a781a57..7bc3fac7bfe0 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -768,7 +768,7 @@ int __init efi_get_fdt_params(struct efi_fdt_params *params) } #endif /* CONFIG_EFI_PARAMS_FROM_FDT */ -static __initdata char memory_type_name[][20] = { +static __efi_initdata_fixup char memory_type_name[][20] = { "Reserved", "Loader Code", "Loader Data", @@ -786,8 +786,8 @@ static __initdata char memory_type_name[][20] = { "Persistent Memory", }; -char * __init efi_md_typeattr_format(char *buf, size_t size, - const efi_memory_desc_t *md) +char * __efi_init_fixup efi_md_typeattr_format(char *buf, size_t size, + const efi_memory_desc_t *md) { char *pos; int type_len; diff --git a/include/linux/efi.h b/include/linux/efi.h index 855992b15269..169b5837c72c 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1107,11 +1107,23 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm, for_each_efi_memory_desc_in_map(&efi.memmap, md) /* + * __efi_init_fixup - if CONFIG_EFI_WARN_ON_ILLEGAL_ACCESSES is enabled, + * remove __init modifier. + */ +#ifdef CONFIG_EFI_WARN_ON_ILLEGAL_ACCESSES +#define __efi_init_fixup +#define __efi_initdata_fixup +#else +#define __efi_init_fixup __init +#define __efi_initdata_fixup __initdata +#endif + +/* * Format an EFI memory descriptor's type and attributes to a user-provided * character buffer, as per snprintf(), and return the buffer. */ -char * __init efi_md_typeattr_format(char *buf, size_t size, - const efi_memory_desc_t *md); +char * __efi_init_fixup efi_md_typeattr_format(char *buf, size_t size, + const efi_memory_desc_t *md); /** * efi_range_is_wc - check the WC bit on an address range -- 2.7.4