From patchwork Wed Oct 8 14:11:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 38480 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0183F202E7 for ; Wed, 8 Oct 2014 14:14:30 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id m15sf5268069wgh.11 for ; Wed, 08 Oct 2014 07:14:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=Dak9yxi6cPMmjQWWvLIoSo5h2SJHAOR+o/9x4G6u5wY=; b=lLDkF7Jvq3JF7ZzGOd0rBZG94na9seuLJcp+d+VLISItQoKW6YO6metLU9uc27KZM+ eUqtDWM5DQOJJpBUH1j1Dd/DuT2CXlmXu1M4IjqePOOqieGHWEK5O3a9BiHYyJFmWS+/ C4Q8gE9Axrmtl+fAp/7YHJ1RDRRu5adSvtz1WvfNM3IIFq7hJpyz9DjSPC9TlTKR5qJs 4AJ/bFrJk4umlQb34Qcpykp1y5W6H/V2Jd/+nVOVRcdm58O47aIAG2/lx0T9AVDa4G/k FcANXDoNgNJ8riC0OTmkgjV5VyT7EixzQARjx0g8r1Z5OpLivGOIqnFPCA+DFToyLPhk Gp7w== X-Gm-Message-State: ALoCoQnO5QKipGoLn3LmSb+WVfJsl9zm53zJn5VcHaXZGenQW+xr5f6Ncf0wkd3BEukj5xUJRzXY X-Received: by 10.152.6.9 with SMTP id w9mr444077law.7.1412777670133; Wed, 08 Oct 2014 07:14:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.171 with SMTP id p11ls52945lal.68.gmail; Wed, 08 Oct 2014 07:14:30 -0700 (PDT) X-Received: by 10.152.88.43 with SMTP id bd11mr11910327lab.62.1412777669990; Wed, 08 Oct 2014 07:14:29 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by mx.google.com with ESMTPS id x7si126708lax.124.2014.10.08.07.14.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Oct 2014 07:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so8229622lbg.0 for ; Wed, 08 Oct 2014 07:14:29 -0700 (PDT) X-Received: by 10.153.7.73 with SMTP id da9mr11822829lad.56.1412777669884; Wed, 08 Oct 2014 07:14:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp70162lbz; Wed, 8 Oct 2014 07:14:29 -0700 (PDT) X-Received: by 10.70.40.229 with SMTP id a5mr7308601pdl.17.1412777668325; Wed, 08 Oct 2014 07:14:28 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id pj2si1996004pbb.222.2014.10.08.07.14.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Oct 2014 07:14:28 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xbryc-0002BM-8o; Wed, 08 Oct 2014 14:12:26 +0000 Received: from mail-wg0-f47.google.com ([74.125.82.47]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XbryB-000260-BQ for linux-arm-kernel@lists.infradead.org; Wed, 08 Oct 2014 14:12:00 +0000 Received: by mail-wg0-f47.google.com with SMTP id x13so11533445wgg.6 for ; Wed, 08 Oct 2014 07:11:34 -0700 (PDT) X-Received: by 10.180.90.50 with SMTP id bt18mr10431219wib.60.1412777493967; Wed, 08 Oct 2014 07:11:33 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id h4sm247703wjb.9.2014.10.08.07.11.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Oct 2014 07:11:32 -0700 (PDT) From: Ard Biesheuvel To: pjones@redhat.com, msalter@redhat.com, leif.lindholm@linaro.org, mark.rutland@arm.com, matt.fleming@intel.com, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, roy.franz@linaro.org, Catalin.Marinas@arm.com Subject: [PATCH v3] arm64/efi: efistub: jump to 'stext' directly, not through the header Date: Wed, 8 Oct 2014 16:11:27 +0200 Message-Id: <1412777487-13636-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141008_071159_563725_B400ADA5 X-CRM114-Status: GOOD ( 13.14 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.47 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.47 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 After the EFI stub has done its business, it jumps into the kernel by branching to offset #0 of the loaded Image, which is where it expects to find the header containing a 'branch to stext' instruction. However, the UEFI spec 2.1.1 states the following regarding PE/COFF image loading: "A UEFI image is loaded into memory through the LoadImage() Boot Service. This service loads an image with a PE32+ format into memory. This PE32+ loader is required to load all sections of the PE32+ image into memory." In other words, it is /not/ required to load parts of the image that are not covered by a PE/COFF section, so it may not have loaded the header at the expected offset, as it is not covered by any PE/COFF section. So instead, jump to 'stext' directly, which is at the base of the PE/COFF .text section, by supplying a symbol 'stext_offset' to efi-entry.o which contains the relative offset of stext into the Image. Also replace other open coded calculations of the same value with a reference to 'stext_offset' Signed-off-by: Ard Biesheuvel --- Changes since v2: - rebased onto 3.17+ - added spec reference to commit message Changes since v1: - drop :lo12: relocation against stext_offset in favor of using a literal '=stext_offset' which is safer arch/arm64/kernel/efi-entry.S | 3 ++- arch/arm64/kernel/head.S | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 619b1dd7bcde..a0016d3a17da 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -61,7 +61,8 @@ ENTRY(efi_stub_entry) */ mov x20, x0 // DTB address ldr x0, [sp, #16] // relocated _text address - mov x21, x0 + ldr x21, =stext_offset + add x21, x0, x21 /* * Flush dcache covering current runtime addresses diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 0a6e4f924df8..8c06c9d269d2 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -132,6 +132,8 @@ efi_head: #endif #ifdef CONFIG_EFI + .globl stext_offset + .set stext_offset, stext - efi_head .align 3 pe_header: .ascii "PE" @@ -155,7 +157,7 @@ optional_header: .long 0 // SizeOfInitializedData .long 0 // SizeOfUninitializedData .long efi_stub_entry - efi_head // AddressOfEntryPoint - .long stext - efi_head // BaseOfCode + .long stext_offset // BaseOfCode extra_header_fields: .quad 0 // ImageBase @@ -172,7 +174,7 @@ extra_header_fields: .long _end - efi_head // SizeOfImage // Everything before the kernel image is considered part of the header - .long stext - efi_head // SizeOfHeaders + .long stext_offset // SizeOfHeaders .long 0 // CheckSum .short 0xa // Subsystem (EFI application) .short 0 // DllCharacteristics @@ -217,9 +219,9 @@ section_table: .byte 0 .byte 0 // end of 0 padding of section name .long _end - stext // VirtualSize - .long stext - efi_head // VirtualAddress + .long stext_offset // VirtualAddress .long _edata - stext // SizeOfRawData - .long stext - efi_head // PointerToRawData + .long stext_offset // PointerToRawData .long 0 // PointerToRelocations (0 for executables) .long 0 // PointerToLineNumbers (0 for executables)