Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4605181rwb; Tue, 8 Aug 2023 10:50:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV+Y3Dkr5/Ijd4oYsiYn+i+0oGmrR3LngvyOX25gam53p1pBiHwgfLJmiwLBIBtZ9xqG5p X-Received: by 2002:a17:903:44a:b0:1b9:e23b:bb6a with SMTP id iw10-20020a170903044a00b001b9e23bbb6amr10900940plb.11.1691517057694; Tue, 08 Aug 2023 10:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517057; cv=none; d=google.com; s=arc-20160816; b=mBUV4BdYawKP8BbpS/xCEjon8/A0yCA+v8o5naQl5i3xLF8fFTKE1VkFpdZWLA3BPn MXmCRcPAiB80pAm0X2amvCL+PnOzl87Hk3JiYWrogLCN1y6b6Np9KksAqTpb99BQMwQZ sKY73P8qSu+HdEc/DpL8rfzHDnXmAmV6CW5KO9jdv3uBl3Y9sTSmJ8EEhQmwqxDK+4O2 J7vRxiOjXRUCqgzG8ETA9uE3HL34KhsflNztIBzIPPTrbY66bYd5XrHIUv0/0vP3XajQ 6Vo9+5fQIYMCxsJtzdipUEtt6ktulw/LDHf0hW6oxU2Xsn/Vr1aG/7nFispC0LT1pQ0c lnJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=7UKoshY9dL4+4BhYKrhvJNIuP8h9w/AW++PipRWo5EY=; fh=upm4t26Ojn/J6N+Q9k8Qqzx52VymNDAlYlARzLeNh5s=; b=UwZ8ZXbR5qGk3OFi7CXh+v5Wq2wXMuQ/UX16dfE2MVUOuQrAHA+5B0K+7dPy4SRHOi 55Og2gPIfT8L9dZEfUTZm25YfKB4JyP/Ta0v36gxyA+upJgsFvWs5xVlZV4TuEpWfvVn xN9UKblN8Ko6u4lr9i/3fSIVybIvDmXuo+Pz39eqfUfcHaWNbP+2V6zQ4gWt9esN6eay kBMeskpEzKqVlUi2c00VySpg5FrCHvvbpGvW2E/7o4zfKlQ0YqkPKlM7KIdmWNviWlZ6 ne1byCz0Y92GRn53uuj1eEjxXZlZTVy8PVU41p80Z+s+VzQ6yG+YDvLZKXRQB7RVFms9 0CXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XzKst5C9; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl12-20020a170903074c00b001b8a6bf59cfsi7483924plb.378.2023.08.08.10.50.44; Tue, 08 Aug 2023 10:50:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XzKst5C9; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233080AbjHHQez (ORCPT + 99 others); Tue, 8 Aug 2023 12:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjHHQeB (ORCPT ); Tue, 8 Aug 2023 12:34:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF60E9089; Tue, 8 Aug 2023 08:52:21 -0700 (PDT) Date: Tue, 08 Aug 2023 08:44:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691484245; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7UKoshY9dL4+4BhYKrhvJNIuP8h9w/AW++PipRWo5EY=; b=XzKst5C9MTT8YKvHvEXbL9vq4HYDQVjvYSZ19L38i3Q+wSMyUaAkXIeXGpMnTgz1cDODrA /DAil87m9M98LRKB5uteoRG9dBDDYtlBuOXCL38ttaQQBhhUZ7q4fi3PXYwbpy5Z347q5D k8hs7Zedmdeujy6ekbzttpxhCTHSHxpRUCKnGNLpLjOVshS9nGE4wTsy+0VX5pZhc0FVDH ObPthDx8VckRH9XGjeWRlmlxZIu7hrLVryAmJvMzAGAEek/RNr03soYx/6mf6vbtyIGlmj 4ZcH5d4POh4QtqvDm3QKPt5BYHuTBjHUZJ1u2KzN1T86kc+f0VF4erlNe5r+EA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691484245; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7UKoshY9dL4+4BhYKrhvJNIuP8h9w/AW++PipRWo5EY=; b=zzftaqtuuxaMBIHcGs+r4ugKP3dT5xabbSMARhitvkJeIj+acCSbpglFgygAYB/nSpKTrR RzxPPJZk+szhWXAw== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/efistub: Clear BSS in EFI handover protocol entrypoint Cc: Ard Biesheuvel , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230807162720.545787-7-ardb@kernel.org> References: <20230807162720.545787-7-ardb@kernel.org> MIME-Version: 1.0 Message-ID: <169148424483.27769.12149416146478802186.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/boot branch of tip: Commit-ID: d7156b986d4cc0657fa6dc05c9fcf51c3d55a0fe Gitweb: https://git.kernel.org/tip/d7156b986d4cc0657fa6dc05c9fcf51c3d55a0fe Author: Ard Biesheuvel AuthorDate: Mon, 07 Aug 2023 18:27:03 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 07 Aug 2023 20:40:36 +02:00 x86/efistub: Clear BSS in EFI handover protocol entrypoint The so-called EFI handover protocol is value-add from the distros that permits a loader to simply copy a PE kernel image into memory and call an alternative entrypoint that is described by an embedded boot_params structure. Most implementations of this protocol do not bother to check the PE header for minimum alignment, section placement, etc, and therefore also don't clear the image's BSS, or even allocate enough memory for it. Allocating more memory on the fly is rather difficult, but at least clear the BSS region explicitly when entering in this manner, so that the EFI stub code does not get confused by global variables that were not zero-initialized correctly. When booting in mixed mode, this BSS clearing must occur before any global state is created, so clear it in the 32-bit asm entry point. Signed-off-by: Ard Biesheuvel Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230807162720.545787-7-ardb@kernel.org --- arch/x86/boot/compressed/efi_mixed.S | 14 +++++++++++++- drivers/firmware/efi/libstub/x86-stub.c | 13 +++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 9308b59..8a02a15 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -142,6 +142,18 @@ SYM_FUNC_END(__efi64_thunk) .code32 #ifdef CONFIG_EFI_HANDOVER_PROTOCOL SYM_FUNC_START(efi32_stub_entry) + call 1f +1: popl %ecx + + /* Clear BSS */ + xorl %eax, %eax + leal (_bss - 1b)(%ecx), %edi + leal (_ebss - 1b)(%ecx), %ecx + subl %edi, %ecx + shrl $2, %ecx + cld + rep stosl + add $0x4, %esp /* Discard return address */ popl %ecx popl %edx @@ -334,7 +346,7 @@ SYM_FUNC_END(efi32_pe_entry) .org efi32_stub_entry + 0x200 .code64 SYM_FUNC_START_NOALIGN(efi64_stub_entry) - jmp efi_stub_entry + jmp efi_handover_entry SYM_FUNC_END(efi64_stub_entry) #endif diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 3f3b3ed..9247dbc 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -970,12 +970,21 @@ fail: } #ifdef CONFIG_EFI_HANDOVER_PROTOCOL +void efi_handover_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg, + struct boot_params *boot_params) +{ + extern char _bss[], _ebss[]; + + memset(_bss, 0, _ebss - _bss); + efi_stub_entry(handle, sys_table_arg, boot_params); +} + #ifndef CONFIG_EFI_MIXED -extern __alias(efi_stub_entry) +extern __alias(efi_handover_entry) void efi32_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg, struct boot_params *boot_params); -extern __alias(efi_stub_entry) +extern __alias(efi_handover_entry) void efi64_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg, struct boot_params *boot_params); #endif