Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2591790lqp; Mon, 25 Mar 2024 03:52:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1pNTEacSvyWnentkW0GefupvDifnCruuShpxuuoIgGkMH6dpv9+Qun/jXHiE/RbGob1fNNcVMhPmOGJKXfuBjOjAC2lHrCM+BrGqlcQ== X-Google-Smtp-Source: AGHT+IHl75c37D9U5UVc4hSVD0YvhvdFky8JUbeCn1qBzH24o9KbhFpASocQwHN0Dm5nZFMDekba X-Received: by 2002:a05:6a00:63c1:b0:6ea:acbe:517a with SMTP id gi1-20020a056a0063c100b006eaacbe517amr1956123pfb.16.1711363928585; Mon, 25 Mar 2024 03:52:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711363928; cv=pass; d=google.com; s=arc-20160816; b=B/PCsy3RQ4tx436yFs/dPFvtF2aAGJk1KhKIBjSbn8N9FHrZ/sSmkr8wNhp+PhS1h7 C3PWyoHnNCE0tDg2l1+GdlPoRjqtsBbJ47psM70RnPMuSeOdfKk2OuiXKNjMimxpy9DF i5ZCEFW2wtibwOLzogPEBCdCDqXsUUTVKWL0C9vUHwrB14Y9kQzQAsp+siAb1aE6br8Y 9wxnhFaubu/ca1a4t3LpmItr3lhYKydKTbydv583f36XxE1odNGR5D8Zx9bZX/aj0wJb IA1Hhfv/fN6TJ8PS5h9lEEDKVLCegPg0PgW0RLHJFepGAvQjpRWJbxFAFSnx2fvVb0+9 RwNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xCEfjzzhzD/ShSiVj1LGZ84PMGP63o4rXrg2ZU0yDFU=; fh=i8hxKiRBehGt4ceU9qnZSbPc3Mr/0PkSlVdlWyTZyZA=; b=Z+UJQKt93HEqbN34VcD+bd8L2rVcafwTEibDnSiOnpQIqBfnnZR4LPeKpVHRqmc67Q A5hGsB6ttwD81F6aQZRaqAYrIVWAhDSqV1I4RpGQFeTXTf+PNoOuomdMmFC28oYA+Sa3 m8UlaBoXGiFPBBrrHAepBhrKBaLaAdv+F0TiJtj3hfH0o1eoRE5cRpf6eYgpTNl+IGzE h83vKY9yweZbOLYX96My8+Jng7gIPgDQzjDo8G/pg8oYhReX+fnO/giC18mnpfeMk9Hf LON9JsC/FqJEdGvr+i4hNyJGbeCTCxn/nkpfhyTSEgd+h9nwRl9wftMquNe5dm8/G3eF QYgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="QbR/x1kK"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m22-20020a056a00081600b006ea965d1629si4993923pfk.332.2024.03.25.03.52.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:52:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="QbR/x1kK"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7ADEFB3E1A7 for ; Mon, 25 Mar 2024 08:56:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 585BE39C200; Mon, 25 Mar 2024 03:06:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QbR/x1kK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D95015FD1A; Sun, 24 Mar 2024 23:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322367; cv=none; b=sMi21V34REgSf9z3KguQvgYHOYPGM5ndRFHPKQpzsOE0gZlNKxMPinf33cfoiZUTgm6lQWqg6wbZBQ/FJnTNNkHIcJYhpFBBrjcMVmj0nevFVjmsoriIYc1fXyVggEGOXLzegxvD7Q/ZHdVExNHm5wYRRtgTfn/4RPbb2SlEyOg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322367; c=relaxed/simple; bh=R27CTNliboiG9ez/iXBakzPHknya3eT60HpHVzU5DHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BmITuE/kxP9pCN4eBJ5/sT7ooDTlNd5OH+V8heqjuO6Tlkja9+mawMxopB70bzhdCpa323ZUWl0KbdyVlzLvUt3p9ktPjdSn4wSwUKRh48+EMDe2HNlmk5AgmQbqRiZQ1zuJqTblNz52B9tiFLOvUXDNG+Mm9sJfTS31py76yvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QbR/x1kK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44D08C43394; Sun, 24 Mar 2024 23:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322367; bh=R27CTNliboiG9ez/iXBakzPHknya3eT60HpHVzU5DHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QbR/x1kKOHAEgW057aN9Jxyqj/1UEPV9DGUDCreVqr+eAhJmyinrx36fr8JLF+07H aZPfIW3xbl3xjVVB7KsSGjI8d0NqZan8zTf9rXBYk+sHAvCgR/Ze4S7WkDMCCpjuGd y2yhPMSZq/qojzeEXDcOgJhKmp+WASMabPeTBMxMCs5VC65pBB0Gl7mtahPpol2wbu 3Bsbst4qBUKdEFot+LRjafIA63PnxvSo2JSDJjviIAC3H3+LFGTZhGAE6Rk/GrilVr vLgrRXXEcyyJ+kP7cOcUPcqqiBVJmhjmjJRHWVQPV1h33D49i5KH5OjTqwXKqcd+Eg WimPs74JhI5tg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ard Biesheuvel , stable@kernel.org, Radek Podgorny , Sasha Levin Subject: [PATCH 6.1 449/451] x86/efistub: Clear decompressor BSS in native EFI entrypoint Date: Sun, 24 Mar 2024 19:12:05 -0400 Message-ID: <20240324231207.1351418-450-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Ard Biesheuvel [ Upstream commit b3810c5a2cc4a6665f7a65bed5393c75ce3f3aa2 ] The EFI stub on x86 no longer invokes the decompressor as a subsequent boot stage, but calls into the decompression code directly while running in the context of the EFI boot services. This means that when using the native EFI entrypoint (as opposed to the EFI handover protocol, which clears BSS explicitly), the firmware PE image loader is being relied upon to ensure that BSS is zeroed before the EFI stub is entered from the firmware. As Radek's report proves, this is a bad idea. Not all loaders do this correctly, which means some global variables that should be statically initialized to 0x0 may have junk in them. So clear BSS explicitly when entering via efi_pe_entry(). Note that zeroing BSS from C code is not generally safe, but in this case, the following assignment and dereference of a global pointer variable ensures that the memset() cannot be deferred or reordered. Cc: # v6.1+ Reported-by: Radek Podgorny Closes: https://lore.kernel.org/all/a99a831a-8ad5-4cb0-bff9-be637311f771@podgorny.cz Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- drivers/firmware/efi/libstub/x86-stub.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 784e1b2ae5ccd..aa07051459f52 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -21,6 +21,8 @@ #include "efistub.h" #include "x86-stub.h" +extern char _bss[], _ebss[]; + const efi_system_table_t *efi_system_table; const efi_dxe_services_table_t *efi_dxe_table; static efi_loaded_image_t *image = NULL; @@ -432,6 +434,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, efi_status_t status; char *cmdline_ptr; + memset(_bss, 0, _ebss - _bss); + efi_system_table = sys_table_arg; /* Check if we were booted by the EFI firmware */ @@ -950,8 +954,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle, 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); } -- 2.43.0