Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3084695ybt; Mon, 29 Jun 2020 14:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrVEO1lyIh04v5kw4K8o7cxmCGiIWIzL93e2yCDRK4EVuYuh/h6H3Qa4X4owoTx12oXVSa X-Received: by 2002:a17:906:958f:: with SMTP id r15mr2354744ejx.77.1593467897182; Mon, 29 Jun 2020 14:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593467897; cv=none; d=google.com; s=arc-20160816; b=HE6NBxoLNbKMV/xk8EJl4nIkTV/qlQWwWRqzwUTtUtVUAY7o5YugMgZPS7XMkgqHaC 2g5/wrY5V/qyU2OiCFd69kuGASg04593kKhptdlIDP7itZqUuKE6Q5rW9aYK9CmIH8LR 6jvk67P4jj4tjEEi7Eo896/cZVGt25EhkzPmD+6y2zjZW4itXwsjsIWpV0YxZz6cXxl1 th+/LXNTjMvzHXHBZr0y8efOcGHyWLeQ6Ts2UXj2PJ3wAub+tmrrikWqUITY1KCxKJ1t YEOGZ8G6Q3jpZFFFzPzla09s2CLfoFFXdzXPDlAbyVd+UcXFMumS1WaT7NY0Eoj4zoyB V0mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rB/kOZHPtiUnqEPy5dAqxwhg9IaXzG3BPGe4Z+JtSHk=; b=drbPMAqTG0GxGavyhyB2glWbdoqey82BIhOlr5Gt8Zkx2vn+ZKdNzX83kfn6oZNiFl jM54Up9/fNSJxZsRnh3U5pcdutuXBad0zTfXF61dw8zg8OwcHgoJ33wEVlhRubjc9qO/ MgXpF0C8oVVrvHMXDbInWiIrChFaT8YjwD5pmxL317mQlMd2rl+GEsU+7e7KuUhc45ke q2IT7u2K/83FQeBvaroXihgDUbyzcYZY6QsX9dmSe7r3grx11DBv05W3n1u1kmSVmHrN C1vi2RNdbR/VhFAd146d+5yM0rguWlwNCWU1UV+vut8g9ll/aI2TTHaiDKeQNQQgRnQE usHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oVcHRrjh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j31si504618edc.371.2020.06.29.14.57.54; Mon, 29 Jun 2020 14:58:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oVcHRrjh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731656AbgF2V4a (ORCPT + 99 others); Mon, 29 Jun 2020 17:56:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726532AbgF2Sfb (ORCPT ); Mon, 29 Jun 2020 14:35:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 52A3D246C7; Mon, 29 Jun 2020 15:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444018; bh=mRm22jjjhmYNa0dWj85l2ScqLQVog5bM7J59aF+g4kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oVcHRrjhF9V0N1URwbarN/5SIti0FlcWx6sC6GnZ/kdKcFiW/gmCNX9Js2TrsaLIi Gece93Dhxq/R7N5Eez+rJXDNeHjEEGrWa2x8j03pcoxe7dtowi0vo4J1Doxrb+kLe+ CXwn5jHxsea1ym6zRL8EJ0+1CgQ5a0io7Px10De4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arvind Sankar , Ard Biesheuvel , Sasha Levin Subject: [PATCH 5.7 125/265] efi/x86: Setup stack correctly for efi_pe_entry Date: Mon, 29 Jun 2020 11:15:58 -0400 Message-Id: <20200629151818.2493727-126-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629151818.2493727-1-sashal@kernel.org> References: <20200629151818.2493727-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.7-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.7.7-rc1 X-KernelTest-Deadline: 2020-07-01T15:14+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar [ Upstream commit 41d90b0c1108d1e46c48cf79964636c553844f4c ] Commit 17054f492dfd ("efi/x86: Implement mixed mode boot without the handover protocol") introduced a new entry point for the EFI stub to be booted in mixed mode on 32-bit firmware. When entered via efi32_pe_entry, control is first transferred to startup_32 to setup for the switch to long mode, and then the EFI stub proper is entered via efi_pe_entry. efi_pe_entry is an MS ABI function, and the ABI requires 32 bytes of shadow stack space to be allocated by the caller, as well as the stack being aligned to 8 mod 16 on entry. Allocate 40 bytes on the stack before switching to 64-bit mode when calling efi_pe_entry to account for this. For robustness, explicitly align boot_stack_end to 16 bytes. It is currently implicitly aligned since .bss is cacheline-size aligned, head_64.o is the first object file with a .bss section, and the heap and boot sizes are aligned. Fixes: 17054f492dfd ("efi/x86: Implement mixed mode boot without the handover protocol") Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200617131957.2507632-1-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- arch/x86/boot/compressed/head_64.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 76d1d64d51e38..41f7922086220 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -213,7 +213,6 @@ SYM_FUNC_START(startup_32) * We place all of the values on our mini stack so lret can * used to perform that far jump. */ - pushl $__KERNEL_CS leal startup_64(%ebp), %eax #ifdef CONFIG_EFI_MIXED movl efi32_boot_args(%ebp), %edi @@ -224,11 +223,20 @@ SYM_FUNC_START(startup_32) movl efi32_boot_args+8(%ebp), %edx // saved bootparams pointer cmpl $0, %edx jnz 1f + /* + * efi_pe_entry uses MS calling convention, which requires 32 bytes of + * shadow space on the stack even if all arguments are passed in + * registers. We also need an additional 8 bytes for the space that + * would be occupied by the return address, and this also results in + * the correct stack alignment for entry. + */ + subl $40, %esp leal efi_pe_entry(%ebp), %eax movl %edi, %ecx // MS calling convention movl %esi, %edx 1: #endif + pushl $__KERNEL_CS pushl %eax /* Enter paged protected Mode, activating Long Mode */ @@ -776,6 +784,7 @@ SYM_DATA_LOCAL(boot_heap, .fill BOOT_HEAP_SIZE, 1, 0) SYM_DATA_START_LOCAL(boot_stack) .fill BOOT_STACK_SIZE, 1, 0 + .balign 16 SYM_DATA_END_LABEL(boot_stack, SYM_L_LOCAL, boot_stack_end) /* -- 2.25.1