Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2406282lqp; Sun, 24 Mar 2024 18:12:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXmlxWa5VklJD2HfIaZyzRaEHpMPZ/HBIG3RbEt3+8cruK1N8ZUKzRp35dZfQkswwmTsMPswaLBQvM3Ct37nvRg+hHL0fj2dUarqH3qg== X-Google-Smtp-Source: AGHT+IFORWnjPIlvwaKlF0VyLeA/X8s/SJHYk9L5P+S6tkVakyef6Si1yy8Xjjt25S7WGRH7w6Hx X-Received: by 2002:a19:e05d:0:b0:515:9789:a704 with SMTP id g29-20020a19e05d000000b005159789a704mr3071976lfj.66.1711329179030; Sun, 24 Mar 2024 18:12:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711329179; cv=pass; d=google.com; s=arc-20160816; b=ulK/LjpatMw4a5zozGTXEJ166LWWivp+t6cux4QGFfALeeX8vE79fjoXqKbmOppUVh BssAN4WwdZElESbCRFcG2r6MRBwQ0ZNWMwjVayXfOdj62us2P4Es3mQrz47Hc3NS/Dmu YQBSpnbWdTghvkqRZea9/RaxJSNX5qdCv3BOuwtXineGbw//qZrOCJoICdp6p6zi/aFt TFgUvhCD/taStAEbR56MzPpXUUbBsXyruC2Q1VtoZJYE9P/XCNPgLdhE0hARkL5S/9DM En5EykOsZpLPgVYRFSs+YKVakzrSaBgAZQbk5uiZpFf6c/WoGW0oIfFSefK0wcZn7UI/ 4k4g== 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=m82X2WyyolsMZtjFweZ5f7/fGJn0Tza8FgwvAB5up/w=; fh=i8hxKiRBehGt4ceU9qnZSbPc3Mr/0PkSlVdlWyTZyZA=; b=pdxPN3CALa/hfNYnpN+/QqYVvElF3v5HuPIbw1UMXSsfo+dQBaaYimn5HSkPkF4CQt fUG4R5rXMmGKb07s1VMAqxn6iYi+7XUpU+oaQlTIt96uSY9ZKCfyy6MPj/s//mgUnaRA K5lHsfXJs3f+Mn5aLHlEd16QfAejXM0+Ek8+nueUKKIJ33+bKIJkMcK3yuKsjcXp5Zve 6OpWPCZsSjyQU7WPBncyHwHF4xc32MDsxX9rU4wv4o7MWbMbwJjIPmuKB7/Ed+1ZM5EB fhm5Li96agQYFkxwKrZt+FTCzK40f/0+n2vEI663Y4qhfxhrkroW8z6txIooR6OXfJTL AnSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=THELPMRL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lc26-20020a170906f91a00b00a474f8278f2si1180414ejb.34.2024.03.24.18.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:12:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=THELPMRL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113603-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113603-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BD6D51F236EF for ; Mon, 25 Mar 2024 01:12:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C99A1CE6A5; Sun, 24 Mar 2024 22:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="THELPMRL" 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 9A8D51CE96C; Sun, 24 Mar 2024 22:46:47 +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=1711320407; cv=none; b=gsL5B+QI7kbLxxwsjSdgnOlSp0Yn+EWWUXkOmzpNxTt2ZGCyv2JQcHEBT+OspKXJNWLdhEUASVxwgciPcYsETSP1k77ts3HmY8bBGcH9tE2Ynh7t+bvNOra6HURoVvSL/tT3RwIcB1riyWHRMKm4ADxIy0CfCWyshu5IyIUuXM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320407; c=relaxed/simple; bh=zYRJyHjGPDedyr/ShRm7a7j5upuj+Z24YOyQgC2F6oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=firNOIrw8C4Ryn6dp5JIjOqxemyu3ITuun4ZC9FFUW5kJKwrlyMsxZY5xQrqeuauxEDR5pQtRK1KgLjUo43EoY23V+nwBBCOHwQF6u5jm32GNFOu93oJR+5bGxAtpl+p/qZL1hzUF4P97IhuTlLAOuAQO0ZMs9Bj5HJdtxCFK9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=THELPMRL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63854C43394; Sun, 24 Mar 2024 22:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320407; bh=zYRJyHjGPDedyr/ShRm7a7j5upuj+Z24YOyQgC2F6oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THELPMRLdBCKZReZn0Fo7XwojQ5ASFASrwU/65hrbWbU4r8qJhb1ktUOz6MoWzGT4 ECS9HBbniIhHb8Db1UllVEdIO//ru9JkM9ymGZtx1pZLEU5EjuK4Ia0/cxScZz+7UJ cxvpx3mCffTZre1uGJcTUL6CHePOnv2MncnqN9XWSwYfKjr+yOKfdprZVI1YUqOiFz gPPra/pKMeSihdXHagfy7FbSuZdgj7FCyvDlEcCXTWQc5s0cQhw1Ys0apn8EmsJ4QS SOH7eQ5/14pTODu7I+YN/WfKKj4LlmGbaFDbBkENkT/N3WRszXgfHSjFeEsIS9huih V7/LkeYspuZqA== 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.8 713/715] x86/efistub: Clear decompressor BSS in native EFI entrypoint Date: Sun, 24 Mar 2024 18:34:52 -0400 Message-ID: <20240324223455.1342824-714-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 99429bc4b0c7e..681f576ec02a0 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; @@ -465,6 +467,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 */ @@ -958,8 +962,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