From patchwork Tue Jul 15 09:10:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33649 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D291201F1 for ; Tue, 15 Jul 2014 09:12:40 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id j7sf17683156qaq.9 for ; Tue, 15 Jul 2014 02:12:40 -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=8IUMJFYMLEbxt1vzGWs0XDadbukxvS5DJcktUxiU3Q4=; b=HJh/rE79IItRPvTIWNhp33gDeWuikvR5TDRow3ZLQcMkhTRAnpK8D2RM+pFUr7Bt4p XGhEbG3A22IQVT6imTwL9c7oujSbRkM2Tm5DGfEUv4QE5ojMivYSh+yJueP0UOxRYKW8 SATTpFvtOKB6dVdGxV9vuJfO8RSwVZ48AhmuFQBZPEnDaMA/Lw36qTfbkiGWRH97SxKp KRzxy3KIGvwoC5/kAPLP0YcpuBi1ZuQxcvSeiPN1fGvPtX+H4fSchbMfKFci1mU0WVlt mwe6hznhIRAM0pKfHwaTcpqOMS76o/tF37mNwHVamal9zaqQbSNFp8ikNwQqpzEfm5Ls wvdA== X-Gm-Message-State: ALoCoQlbS8+VWH6ohhriidQgbRMUx5BkSXU92Ika6KQnYQsHSPC/SZn6tidTDqrfH6W5h9PddNTB X-Received: by 10.52.165.227 with SMTP id zb3mr9115280vdb.1.1405415560201; Tue, 15 Jul 2014 02:12:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.236 with SMTP id g99ls34302qge.17.gmail; Tue, 15 Jul 2014 02:12:40 -0700 (PDT) X-Received: by 10.58.12.73 with SMTP id w9mr21613498veb.13.1405415560110; Tue, 15 Jul 2014 02:12:40 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id wt9si6422002vdc.20.2014.07.15.02.12.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 02:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so9765475vcb.30 for ; Tue, 15 Jul 2014 02:12:39 -0700 (PDT) X-Received: by 10.52.17.129 with SMTP id o1mr18083525vdd.0.1405415559892; Tue, 15 Jul 2014 02:12:39 -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 tc5csp198883vcb; Tue, 15 Jul 2014 02:12:39 -0700 (PDT) X-Received: by 10.66.141.165 with SMTP id rp5mr21908179pab.90.1405415558454; Tue, 15 Jul 2014 02:12:38 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id j6si5630272pdk.460.2014.07.15.02.12.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jul 2014 02:12:38 -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 1X6ylJ-0007nE-8z; Tue, 15 Jul 2014 09:11:01 +0000 Received: from mail-wi0-f174.google.com ([209.85.212.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X6ylH-0007bv-0f for linux-arm-kernel@lists.infradead.org; Tue, 15 Jul 2014 09:10:59 +0000 Received: by mail-wi0-f174.google.com with SMTP id d1so3974568wiv.1 for ; Tue, 15 Jul 2014 02:10:36 -0700 (PDT) X-Received: by 10.194.60.240 with SMTP id k16mr26483476wjr.0.1405415433427; Tue, 15 Jul 2014 02:10:33 -0700 (PDT) Received: from ards-macbook-pro.local ([77.237.116.228]) by mx.google.com with ESMTPSA id cz4sm41348283wib.23.2014.07.15.02.10.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 02:10:32 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, mark.rutland@arm.com Subject: [PATCH] arm64/efi: efistub: jump to 'stext' directly, not through the header Date: Tue, 15 Jul 2014 11:10:02 +0200 Message-Id: <1405415402-3427-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_021059_210749_AA4EBCC0 X-CRM114-Status: GOOD ( 10.91 ) 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 [209.85.212.174 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.174 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.171 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. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-entry.S | 2 +- arch/arm64/kernel/head.S | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 619b1dd7bcde..6ef541731d9e 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -61,7 +61,7 @@ ENTRY(efi_stub_entry) */ mov x20, x0 // DTB address ldr x0, [sp, #16] // relocated _text address - mov x21, x0 + add x21, x0, #:lo12:stext_offset /* * 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)