Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3083600imm; Tue, 4 Sep 2018 15:17:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbvTieArtmxRYGUj8dW4jmxZAEDUjtxz11LhWSY2wWOpEyNoJfP/oRK4EXLS9ROOt7nLJo4 X-Received: by 2002:a17:902:5a87:: with SMTP id r7-v6mr35381713pli.247.1536099436223; Tue, 04 Sep 2018 15:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536099436; cv=none; d=google.com; s=arc-20160816; b=KeMVc5KtVHNQhrBIe9BLeILSccOIG1ScUY09IslnW5SHQqhAEm86DlcKSq67ACaV3q UqdQXvgb+tgR3n0QYdVLVWhBErwErRPv7gBz54eR5d6gGCm6Jro34JxbIr6+rhAhwr3b 2UToapSrPGuZ/pImBh72HdieIHqQaFPNCdIoTBsGgBhnjxb5pvgWfPXGmfQb5k4DMTSA QbsR2EUpVU6WLnzTmKGpjosqT5sPSZ7XMvG3V5OUL02dXdf3xQjMADvkBTvR7eEFWYQk bjKp/50xPmI0rKNvxHNqzMljYVtKqFzUIuFnmQEKCUSnuMRkAWt1/RBdMxL7HYBnxdHS vYug== 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; bh=weeWj3PX1Nv35VlR38KKCYGzj5AD5qwhcgre0r5dEow=; b=kHZxhckqnuZM97KfC1DcItq4K3tIhfTUJoXwxkT+jyKtsfesgA8wVym+MXT09Oa097 lHMLxgJEQXz53iVixAJ/EwWB9BXPf1b+xTV9CYmVJHaAw52JRhwbzkSeghkwFiKVN42j NfEQKgRUevmg+YjAgITK4seRtOvkaNtlagQ1UDb2fQ7W0va1r1vuCmbjsTIMSspQf0+B OC/GsHFB4n4gRCD7ogjN4KH8TX9FxyeU0pt4YxNQf3srjv72q00UKauMvjvErauElC5d tQ4E4vwf8/44O67p9W07m7qv1TjOIuc9ey6Bbb8zifsU+3Qc17syJQA4rCP7FJhzXrZE eUNw== 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 b5-v6si40049pgd.54.2018.09.04.15.17.00; Tue, 04 Sep 2018 15:17:16 -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 S1727587AbeIEClj (ORCPT + 99 others); Tue, 4 Sep 2018 22:41:39 -0400 Received: from mga09.intel.com ([134.134.136.24]:33782 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727455AbeIEClS (ORCPT ); Tue, 4 Sep 2018 22:41:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2018 15:14:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,330,1531810800"; d="scan'208";a="70343602" Received: from sai-dev-mach.sc.intel.com ([143.183.140.52]) by orsmga007.jf.intel.com with ESMTP; 04 Sep 2018 15:14:11 -0700 From: Sai Praneeth Prakhya To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: ricardo.neri@intel.com, matt@codeblueprint.co.uk, Sai Praneeth , Al Stone , Borislav Petkov , Ingo Molnar , Andy Lutomirski , Bhupesh Sharma , Thomas Gleixner , Peter Zijlstra , Ard Biesheuvel Subject: [PATCH V3 2/5] efi: Introduce __efi_init attribute Date: Tue, 4 Sep 2018 15:12:26 -0700 Message-Id: <1536099149-12564-3-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536099149-12564-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1536099149-12564-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 some efi regions even after the kernel has assumed control of the platform. When "CONFIG_EFI_WARN_ON_ILLEGAL_ACCESS" is enabled, the efi page fault handler will detect and recover from these illegal accesses. efi_md_typeattr_format() and memory_type_name are used by the efi page fault handler to print information about memory descriptor that was illegally accessed. As the page fault handler is present during/after kernel boot it doesn't have an __init attribute, but efi_md_typeattr_format() has it and thus during kernel build, "WARNING: modpost: Found * section mismatch(es)" build warning is observed. To fix it, remove __init attribute for efi_md_typeattr_format(). In order to not keep efi_md_typeattr_format() and memory_type_name needlessly when "CONFIG_EFI_WARN_ON_ILLEGAL_ACCESS" is not selected, add a new __efi_init 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: Al Stone Cc: Borislav Petkov Cc: Ingo Molnar Cc: Andy Lutomirski Cc: Bhupesh Sharma Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 4 ++-- include/linux/efi.h | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index d8a33a781a57..16571429b19c 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 char memory_type_name[][20] = { "Reserved", "Loader Code", "Loader Data", @@ -786,7 +786,7 @@ static __initdata char memory_type_name[][20] = { "Persistent Memory", }; -char * __init efi_md_typeattr_format(char *buf, size_t size, +char * __efi_init efi_md_typeattr_format(char *buf, size_t size, const efi_memory_desc_t *md) { char *pos; diff --git a/include/linux/efi.h b/include/linux/efi.h index 855992b15269..6a07e3166fd1 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1107,10 +1107,22 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm, for_each_efi_memory_desc_in_map(&efi.memmap, md) /* + * __efi_init - if CONFIG_EFI_WARN_ON_ILLEGAL_ACCESS is enabled, remove __init + * modifier. + */ +#ifdef CONFIG_EFI_WARN_ON_ILLEGAL_ACCESS +#define __efi_init +#define __efi_initdata +#else +#define __efi_init __init +#define __efi_initdata __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, +char * __efi_init efi_md_typeattr_format(char *buf, size_t size, const efi_memory_desc_t *md); /** -- 2.7.4