From patchwork Tue Jul 15 10:58:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33651 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7E49E201F1 for ; Tue, 15 Jul 2014 11:00:09 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf32413590pab.0 for ; Tue, 15 Jul 2014 04:00:08 -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=t8fwbgbTAUfQMqZ85ubpKmYbzD+AzbsvUTIH8LdPFco=; b=Wfgrg44R0MMqEzTIGIb0zDSM/aOqhb41MbEZiFHM9/PTarHsA3FmlrLhsVRH8CM+BU LvUJO/Bnj6dC7pgdDKS8+DCpGkDUFYVOP5db/OVehmhA1o4FOw3KRHPMNkIQxxug0m8M 1elKax07GTmwv3yFOpTBOsk25nh9luJ6ERya5HRY+oHpO2Z36SWeCzMjBkpCki7pJt0w sAy6R8bV25oo0c/a763TI3aBpeswdkzYWyT6Q5hCFJnf2UUFssoG80DoOof6J8dz1Onc 4PhV3/atfgHSkL4HI5ktih+4pPrbe/n3iuzXe6lgvvN/8mUp/YaDHiTOaDP2ggMPKCeN XBGQ== X-Gm-Message-State: ALoCoQmkeF7kI0hro7z3uP6M2OPDD4jyOTX9cxcm0alciB/xbc0P3OZLxI8pl06pnwchlWAwzCKu X-Received: by 10.66.228.162 with SMTP id sj2mr11071026pac.11.1405422008716; Tue, 15 Jul 2014 04:00:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.134 with SMTP id e6ls56107qgf.34.gmail; Tue, 15 Jul 2014 04:00:08 -0700 (PDT) X-Received: by 10.220.2.136 with SMTP id 8mr21444992vcj.17.1405422008608; Tue, 15 Jul 2014 04:00:08 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id vg7si2299673vec.56.2014.07.15.04.00.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 04:00:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id hq11so9859476vcb.13 for ; Tue, 15 Jul 2014 04:00:08 -0700 (PDT) X-Received: by 10.52.252.4 with SMTP id zo4mr18333004vdc.20.1405422008520; Tue, 15 Jul 2014 04:00:08 -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.221.37.5 with SMTP id tc5csp204890vcb; Tue, 15 Jul 2014 04:00:07 -0700 (PDT) X-Received: by 10.66.150.228 with SMTP id ul4mr22316616pab.16.1405422006188; Tue, 15 Jul 2014 04:00:06 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id nn8si885923pdb.354.2014.07.15.04.00.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jul 2014 04:00:06 -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 1X70RU-0006or-4p; Tue, 15 Jul 2014 10:58:40 +0000 Received: from mail-we0-f169.google.com ([74.125.82.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X70RR-0006gZ-2o for linux-arm-kernel@lists.infradead.org; Tue, 15 Jul 2014 10:58:37 +0000 Received: by mail-we0-f169.google.com with SMTP id u56so456196wes.0 for ; Tue, 15 Jul 2014 03:58:13 -0700 (PDT) X-Received: by 10.180.182.131 with SMTP id ee3mr4505768wic.37.1405421893608; Tue, 15 Jul 2014 03:58:13 -0700 (PDT) Received: from ards-macbook-pro.local ([77.237.116.228]) by mx.google.com with ESMTPSA id lb3sm31842114wjc.30.2014.07.15.03.58.10 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 03:58:12 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, mark.rutland@arm.com Subject: [PATCH v2] arm64/efi: efistub: jump to 'stext' directly, not through the header Date: Tue, 15 Jul 2014 12:58:06 +0200 Message-Id: <1405421886-11692-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-20140715_035837_277313_E84306E1 X-CRM114-Status: GOOD ( 11.27 ) 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.169 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.169 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , catalin.marinas@arm.com, leif.lindholm@linaro.org, roy.franz@linaro.org, msalter@redhat.com, linux-arm-kernel@lists.infradead.org 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.220.182 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 header is not covered by any PE/COFF section, so the header may not actually be loaded at the expected offset. 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 --- 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 a2c1195abb7f..78ddae28b090 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -137,6 +137,8 @@ efi_head: #endif #ifdef CONFIG_EFI + .globl stext_offset + .set stext_offset, stext - efi_head .align 3 pe_header: .ascii "PE" @@ -160,7 +162,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 @@ -177,7 +179,7 @@ extra_header_fields: .long _edata - 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 @@ -222,9 +224,9 @@ section_table: .byte 0 .byte 0 // end of 0 padding of section name .long _edata - 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)