From patchwork Mon Nov 2 17:06:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 314859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 029E6C4742C for ; Mon, 2 Nov 2020 17:06:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3192223B0 for ; Mon, 2 Nov 2020 17:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336817; bh=ejTlItCMWx4LMzuY2iTAsh9aBseFM7SLvGINqe/xaSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0Ftj9JgR08DB2WT83/g6t+j6kM1gYyLixmwXYSV3cHnM+yrpqo3SeztasgqUUj3XK 9kqgEWseddx3AJnhUe4kIG6SjSYu49unAF1IbAHgLGiR/fDJggkJUweUXXEjhzUAka 0atG+u4DIJEyQQ74VNNQfc9rOhDj+K8xuKScWxcM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727483AbgKBRG4 (ORCPT ); Mon, 2 Nov 2020 12:06:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:59078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727473AbgKBRGy (ORCPT ); Mon, 2 Nov 2020 12:06:54 -0500 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB7A422277; Mon, 2 Nov 2020 17:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336813; bh=ejTlItCMWx4LMzuY2iTAsh9aBseFM7SLvGINqe/xaSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TFWd43h9XulSjQKfZtUwI4VYQ0A5pR4zQ8iR5Y3etO0BOq8HZQFIlw8oUfg8n7RY6 aAlcwvq8R1Mv8qWbKXMl4bL1eAhv7mYJ2l/+HUgMxhau07cs5mUzwad2l5GNMBaai3 QmSh9r6Cfdmxv21Vn52FFKktr5rLgaFEHq58gjwo= From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Peter Jones , Leif Lindholm , Arvind Sankar , Matthew Garrett , Daniel Kiper , Ilias Apalodimas Subject: [RFC PATCH 2/7] efi/libstub: fix prototype of efi_tcg2_protocol::get_event_log() Date: Mon, 2 Nov 2020 18:06:29 +0100 Message-Id: <20201102170634.20575-3-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102170634.20575-1-ardb@kernel.org> References: <20201102170634.20575-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org efi_tcg2_protocol::get_event_log() takes a protocol pointer as the first argument, not a EFI handle. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 2d7abcd99de9..2bc389ec7fcd 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -672,7 +672,7 @@ typedef union efi_tcg2_protocol efi_tcg2_protocol_t; union efi_tcg2_protocol { struct { void *get_capability; - efi_status_t (__efiapi *get_event_log)(efi_handle_t, + efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *, efi_tcg2_event_log_format, efi_physical_addr_t *, efi_physical_addr_t *, From patchwork Mon Nov 2 17:06:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 314858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63BB5C4742C for ; Mon, 2 Nov 2020 17:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE8B8222EC for ; Mon, 2 Nov 2020 17:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336820; bh=Z+RP+I44S2g5tcr50Du7zPQ+M31RcfMbP2e5NvR3de4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EP9A1+ooAIC1CFJUqRWtEav9v4KA+YSf6/d517lved0iiCt+zIHOXB23yhOiAKP7j jON/m7k03D/pBUcKFy8s/KCk4u8loNjC+uE+0yElR+W9y9Edw+xywVSOYdOtAuuihf 7bXJgh6+wR9fCmSYCbqFlSFfodE7lPpG/iqqRsy8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727229AbgKBRG7 (ORCPT ); Mon, 2 Nov 2020 12:06:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:59164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727484AbgKBRG7 (ORCPT ); Mon, 2 Nov 2020 12:06:59 -0500 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95C71223AC; Mon, 2 Nov 2020 17:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336818; bh=Z+RP+I44S2g5tcr50Du7zPQ+M31RcfMbP2e5NvR3de4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYgpGFPVjzMoTVq7TFhNP8YkulfkEWvZKKqX1taKvm9kszPXFjcreM4b+7PCz8GnH Wf+SNjVaVxvj31IOrZNEi0Mn0kNGTwenJcDchvQRkT0QUDtzMjx/vTHDFvWszQYru3 FUiZyTvqHSP8kCedYDUVxB/3RUGPACY4qOv6IRAk= From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Peter Jones , Leif Lindholm , Arvind Sankar , Matthew Garrett , Daniel Kiper , Ilias Apalodimas Subject: [RFC PATCH 4/7] efi/libstub: move TPM related prototypes into efistub.h Date: Mon, 2 Nov 2020 18:06:31 +0100 Message-Id: <20201102170634.20575-5-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102170634.20575-1-ardb@kernel.org> References: <20201102170634.20575-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Move TPM related definitions that are only used in the EFI stub into efistub.h, which is a local header. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 9 +++++++++ include/linux/efi.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 2bc389ec7fcd..2c621bf4760f 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -848,4 +848,13 @@ asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint, void efi_handle_post_ebs_state(void); +#ifdef CONFIG_RESET_ATTACK_MITIGATION +void efi_enable_reset_attack_mitigation(void); +#else +static inline void +efi_enable_reset_attack_mitigation(void) { } +#endif + +void efi_retrieve_tpm2_eventlog(void); + #endif diff --git a/include/linux/efi.h b/include/linux/efi.h index 0ac54295ec0b..1160e0c6d779 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1091,13 +1091,6 @@ enum efi_secureboot_mode { }; enum efi_secureboot_mode efi_get_secureboot(void); -#ifdef CONFIG_RESET_ATTACK_MITIGATION -void efi_enable_reset_attack_mitigation(void); -#else -static inline void -efi_enable_reset_attack_mitigation(void) { } -#endif - #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE void efi_check_for_embedded_firmwares(void); #else @@ -1106,8 +1099,6 @@ static inline void efi_check_for_embedded_firmwares(void) { } efi_status_t efi_random_get_seed(void); -void efi_retrieve_tpm2_eventlog(void); - /* * Arch code can implement the following three template macros, avoiding * reptition for the void/non-void return cases of {__,}efi_call_virt(): From patchwork Mon Nov 2 17:06:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 314857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED943C00A89 for ; Mon, 2 Nov 2020 17:07:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4717222EC for ; Mon, 2 Nov 2020 17:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336825; bh=s+iJ6y9MdKA72ntr91x9rtfCZuHxY1/uKKB+tbv+MCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KnksZOfMVy7234xq5zPyf/Y495bmLtuyLyXA26aveWlaGbwYXE82NNcR4Lha1wK/z 77Q4u5/JVMbzEvBbRnw1N/nuQLKyLxbUItqLMiO11yIufQiM0iC/0nKrgmJkfaZ5im 78HJ3a+sH5PeUOmforBLJW6TF3yJgjjHC7Jw1Alw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727489AbgKBRHF (ORCPT ); Mon, 2 Nov 2020 12:07:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:59312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgKBRHE (ORCPT ); Mon, 2 Nov 2020 12:07:04 -0500 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 848CC223B0; Mon, 2 Nov 2020 17:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604336823; bh=s+iJ6y9MdKA72ntr91x9rtfCZuHxY1/uKKB+tbv+MCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fOs8KS08qOI0YzxHFdm/h8QHRlaDA9H7p/YaIgPrP8a1tKf7nrFRvzpISO6FHg1Xe ud3QamHcT9dpELCbwJD5cg+DgAu1bZEbaQfclOZscM8dXn0O+0unzP6vCrY/7b8Fl0 owA/ClOdD8EcqQDI9pss4cb4f0EZf3HulAuiIVUk= From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Peter Jones , Leif Lindholm , Arvind Sankar , Matthew Garrett , Daniel Kiper , Ilias Apalodimas Subject: [RFC PATCH 6/7] efi/libstub: consolidate initrd handling across architectures Date: Mon, 2 Nov 2020 18:06:33 +0100 Message-Id: <20201102170634.20575-7-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102170634.20575-1-ardb@kernel.org> References: <20201102170634.20575-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Before adding TPM measurement of the initrd contents, refactor the initrd handling slightly to be more self-contained and consistent. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 13 +++++++--- drivers/firmware/efi/libstub/efi-stub.c | 10 ++------ drivers/firmware/efi/libstub/efistub.h | 1 - drivers/firmware/efi/libstub/x86-stub.c | 26 ++++++++------------ 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index aa8da0a49829..72a7e7c4d403 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -20,10 +20,10 @@ bool efi_nochunk; bool efi_nokaslr = !IS_ENABLED(CONFIG_RANDOMIZE_BASE); -bool efi_noinitrd; int efi_loglevel = CONSOLE_LOGLEVEL_DEFAULT; bool efi_novamap; +static bool efi_noinitrd; static bool efi_nosoftreserve; static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA); @@ -643,8 +643,10 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image, { efi_status_t status; - if (!load_addr || !load_size) - return EFI_INVALID_PARAMETER; + if (efi_noinitrd) { + *load_addr = *load_size = 0; + return EFI_SUCCESS; + } status = efi_load_initrd_dev_path(load_addr, load_size, hard_limit); if (status == EFI_SUCCESS) { @@ -655,7 +657,10 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image, if (status == EFI_SUCCESS && *load_size > 0) efi_info("Loaded initrd from command line option\n"); } - + if (status != EFI_SUCCESS) { + efi_err("Failed to load initrd: 0x%lx\n", status); + *load_addr = *load_size = 0; + } return status; } diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 914a343c7785..ccc4e6f10ae6 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -122,7 +122,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, enum efi_secureboot_mode secure_boot; struct screen_info *si; efi_properties_table_t *prop_tbl; - unsigned long max_addr; efi_system_table = sys_table_arg; @@ -228,13 +227,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, if (!fdt_addr) efi_info("Generating empty DTB\n"); - if (!efi_noinitrd) { - max_addr = efi_get_max_initrd_addr(image_addr); - status = efi_load_initrd(image, &initrd_addr, &initrd_size, - ULONG_MAX, max_addr); - if (status != EFI_SUCCESS) - efi_err("Failed to load initrd!\n"); - } + efi_load_initrd(image, &initrd_addr, &initrd_size, ULONG_MAX, + efi_get_max_initrd_addr(image_addr)); efi_random_get_seed(); diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index c96085133648..a8f08bf2cbb5 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -31,7 +31,6 @@ extern bool efi_nochunk; extern bool efi_nokaslr; -extern bool efi_noinitrd; extern int efi_loglevel; extern bool efi_novamap; diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 3672539cb96e..1b4c15489bd6 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -673,6 +673,7 @@ unsigned long efi_main(efi_handle_t handle, unsigned long bzimage_addr = (unsigned long)startup_32; unsigned long buffer_start, buffer_end; struct setup_header *hdr = &boot_params->hdr; + unsigned long addr, size; efi_status_t status; efi_system_table = sys_table_arg; @@ -758,22 +759,15 @@ unsigned long efi_main(efi_handle_t handle, * arguments will be processed only if image is not NULL, which will be * the case only if we were loaded via the PE entry point. */ - if (!efi_noinitrd) { - unsigned long addr, size; - - status = efi_load_initrd(image, &addr, &size, - hdr->initrd_addr_max, ULONG_MAX); - - if (status != EFI_SUCCESS) { - efi_err("Failed to load initrd!\n"); - goto fail; - } - if (size > 0) { - efi_set_u64_split(addr, &hdr->ramdisk_image, - &boot_params->ext_ramdisk_image); - efi_set_u64_split(size, &hdr->ramdisk_size, - &boot_params->ext_ramdisk_size); - } + status = efi_load_initrd(image, &addr, &size, hdr->initrd_addr_max, + ULONG_MAX); + if (status != EFI_SUCCESS) + goto fail; + if (size > 0) { + efi_set_u64_split(addr, &hdr->ramdisk_image, + &boot_params->ext_ramdisk_image); + efi_set_u64_split(size, &hdr->ramdisk_size, + &boot_params->ext_ramdisk_size); } /*