Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp258025lqe; Wed, 27 Mar 2024 05:07:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZnWx+5Lb97LsUClZjQdmfFPTgZdYKux01OqorfLN4tUR1eUimA2p/07sQp/+vyFaZ1JtQgwj5ece2oWQ/EY5tRPz4A5rISGnY8Weqrg== X-Google-Smtp-Source: AGHT+IFTbAs36xLXmu4WBGodJnd2GS1I2k4xVLStGdR7IArdNY9osGChgklFouunyEOfDImIY42G X-Received: by 2002:a05:6358:4818:b0:17f:8812:5029 with SMTP id k24-20020a056358481800b0017f88125029mr1424957rwn.12.1711541269747; Wed, 27 Mar 2024 05:07:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711541269; cv=pass; d=google.com; s=arc-20160816; b=Gg2fA7kAGL0vdSSnvAy8oq9s70VTLz0cU+PmSX/wMWuq/NMVBnJOCdyIX8XSD8JDJQ kY0pdnQ68FXs/cN7zTEATyrKhysxP4cmVV3pSD5CfcsQkj/BEONwDXFuKlaDpG3x6l/j pra/dDlS6eK+g6rzFDtFqOBWJ14ZgQ24iaGwWpZrl2ba0v4ERLtiFgLgs4SdwjEwm/Mu BNuBPa8DWsNlfG9jx3SchjjX3VT4QAZYekAkGSnQEOSopGv3czl22jPzROLLPa4gp6sa J017PKq3idOIgsLWJO/loilO++Eqj4jF6FvNaXDJKIAaI64q+ll5mIx3XALgE/CCjmKs qjXg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=nnj7YRURE4QD/YOjSl48uSsVbzoDaH/GD6tW0g6U1GQ=; fh=ILYudmmRSVv27uDO4UvNHm7AhLcKkaTkHXF5hfjH5AA=; b=Lp6kbnI5AznKlIWXWKQGkFJmcW3hkMocTXsOkQHzQpAG3Q3USXS+qBksRiUBnyrpTe qYBbIkiJrBcp6atpPaJ3tnFSDIoqTuiL2k0RSOPRjF1MdckZwIqKxPVrtyJOSH+j8iUs DgOSnnqzZyWL/xYXYGqLmf+U12xVOWQx1Cf1yXnm/AfbmJhlLS3zaut5EbqvnA1yf7h3 bxPBps0pIj4cNVAK4bTAYduZRUPHW1cqONorsseBohEiT5kBZXE2wuLlzNC8VUQY9828 f1Gw2lys0LEmuCa9mTu00g7vQR3zk8Rhp4sJjjfVqKamaAATy+lCYG/JAyj5mrqpOBdF jgrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KbDVjegV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120788-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d12-20020a63f24c000000b005dc36761adcsi12031314pgk.175.2024.03.27.05.07.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 05:07:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120788-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KbDVjegV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120788-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120788-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A9B7295C15 for ; Wed, 27 Mar 2024 12:07:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 725EE12EBEE; Wed, 27 Mar 2024 12:06:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KbDVjegV" 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 9BA0012D750; Wed, 27 Mar 2024 12:06:44 +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=1711541204; cv=none; b=MdY+6wx/wfkg4AwES/C4Q7t9iPkRBp7v5qHScFaCznJXKRAMFJf3ho9+SMC1uMHc4JqW5PqT0aabBpK1AXC/TDsFaTER2GdtaHLbX051QZbFwfx9lKb10b30zAgtM6/ZSCy9p6juLnQGbPFOUmtJaBmJwRuM5/FIVgBgrhz3+5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711541204; c=relaxed/simple; bh=67pWlMHnTIzMM6BCgS6lJkEdPJSjtmWrZMzJIY09MQw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=B9YFgvPHSEjF/ZsIrlxODgeOd20NMepTPaIqagmRb/VD6MZZa3NpdFHQbdTNNTo1hlmikVg1Oio5uMmrJD+otaveWBWsoId2TH8Qrf+TkJgS9pZrGXM0BDdp6gaquHbQ2aK6tU/Y6e/6JSI8Sxez8zU9UiIu5kWCwlv8R7jzRBw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KbDVjegV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3888C433F1; Wed, 27 Mar 2024 12:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711541204; bh=67pWlMHnTIzMM6BCgS6lJkEdPJSjtmWrZMzJIY09MQw=; h=From:To:Cc:Subject:Date:From; b=KbDVjegVNvNba189XAxwZ3MHbtTUYLFwYGoTonxyBOMHR1W2HRQluvhLbZzeWJxzP wxFFvNfA9Hi2AvoN59Uy91MGNypeidYNvn4+8j8lXowEZEVgCMAESpDKQhCZRvZjYM zif+lC4kEI7rtb+8sIR7RojvVG23kRMio0Q7Jpp6XzLL4796g+ekd8ZSRYv7ZxCRnW AnZGhhpH5gPz5w5fqCLfqmwfSmkJorWuC2vcj2Xe0ztWBRkXpzXL5bNSfIHSPsVXhr aobmOPQ2hxwCmnsW+Q0/keR3hJhdiXBVcYW3UTbfP+GWx1fD7umeH0A3vvjPAQlxNP hGNIHZjrTcT1w== From: Sasha Levin To: stable@vger.kernel.org, ardb@kernel.org Cc: stable@kernel.org, linux-kernel@vger.kernel.org Subject: FAILED: Patch "x86/efistub: Call mixed mode boot services on the firmware's stack" failed to apply to 6.8-stable tree Date: Wed, 27 Mar 2024 08:06:42 -0400 Message-ID: <20240327120643.2824712-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Hint: ignore X-stable: review Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.8-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Thanks, Sasha ------------------ original commit in Linus's tree ------------------ From cefcd4fe2e3aaf792c14c9e56dab89e3d7a65d02 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Fri, 22 Mar 2024 17:03:58 +0200 Subject: [PATCH] x86/efistub: Call mixed mode boot services on the firmware's stack Normally, the EFI stub calls into the EFI boot services using the stack that was live when the stub was entered. According to the UEFI spec, this stack needs to be at least 128k in size - this might seem large but all asynchronous processing and event handling in EFI runs from the same stack and so quite a lot of space may be used in practice. In mixed mode, the situation is a bit different: the bootloader calls the 32-bit EFI stub entry point, which calls the decompressor's 32-bit entry point, where the boot stack is set up, using a fixed allocation of 16k. This stack is still in use when the EFI stub is started in 64-bit mode, and so all calls back into the EFI firmware will be using the decompressor's limited boot stack. Due to the placement of the boot stack right after the boot heap, any stack overruns have gone unnoticed. However, commit 5c4feadb0011983b ("x86/decompressor: Move global symbol references to C code") moved the definition of the boot heap into C code, and now the boot stack is placed right at the base of BSS, where any overruns will corrupt the end of the .data section. While it would be possible to work around this by increasing the size of the boot stack, doing so would affect all x86 systems, and mixed mode systems are a tiny (and shrinking) fraction of the x86 installed base. So instead, record the firmware stack pointer value when entering from the 32-bit firmware, and switch to this stack every time a EFI boot service call is made. Cc: # v6.1+ Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index f4e22ef774ab6..719e939050cbf 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -49,6 +49,11 @@ SYM_FUNC_START(startup_64_mixed_mode) lea efi32_boot_args(%rip), %rdx mov 0(%rdx), %edi mov 4(%rdx), %esi + + /* Switch to the firmware's stack */ + movl efi32_boot_sp(%rip), %esp + andl $~7, %esp + #ifdef CONFIG_EFI_HANDOVER_PROTOCOL mov 8(%rdx), %edx // saved bootparams pointer test %edx, %edx @@ -254,6 +259,9 @@ SYM_FUNC_START_LOCAL(efi32_entry) /* Store firmware IDT descriptor */ sidtl (efi32_boot_idt - 1b)(%ebx) + /* Store firmware stack pointer */ + movl %esp, (efi32_boot_sp - 1b)(%ebx) + /* Store boot arguments */ leal (efi32_boot_args - 1b)(%ebx), %ebx movl %ecx, 0(%ebx) @@ -318,5 +326,6 @@ SYM_DATA_END(efi32_boot_idt) SYM_DATA_LOCAL(efi32_boot_cs, .word 0) SYM_DATA_LOCAL(efi32_boot_ds, .word 0) +SYM_DATA_LOCAL(efi32_boot_sp, .long 0) SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) SYM_DATA(efi_is64, .byte 1) -- 2.43.0