From patchwork Mon Jul 14 16:17:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33612 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 19D4A20CAD for ; Mon, 14 Jul 2014 16:20:43 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id v10sf28939602pde.3 for ; Mon, 14 Jul 2014 09:20:43 -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 :in-reply-to:references: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=EaXXO2wITc1xU6Prtb9U4cG9U+OedDhod8+fbDOCCxM=; b=BdH0JMIEf4pyUc976XoZdIN+j9mtIBpwDg6sHOTYFciS0rUVinsFEkhYURvlCLphSk YTKFBFCGpo4kvfxWG5yMTpzzO5CyTIjIFiu6X4RrNZSG00D0h0jCY3TcRQxNf5q9l6Uh AX1tPKPtGaevdaYCHonSg1Mor/z0VKBeXAfKTxC7J9hXDW/3dIC+KvEuw5XiLb46saxd 5QuZpkbYATPmJVYSB6FIJvoZVeFMTbF3vHRsqjEaS4/EUSaAaX/gRlDheBPleNt+6+EN djCuS1fNvB0uv2ncQMIoDzX80me0PMgznuxpZFFepkkogvgUTknap5y5Tjcivv8vDhgp m8gQ== X-Gm-Message-State: ALoCoQlW0fwVANcOQ/TGKCthRu6nw2sFMH625sHSLhlEM4OUHPv9ZFglH/Sf2Nb5X4iaSYYqGGz+ X-Received: by 10.68.137.99 with SMTP id qh3mr5290756pbb.2.1405354843317; Mon, 14 Jul 2014 09:20:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.239 with SMTP id l102ls1070371qgd.81.gmail; Mon, 14 Jul 2014 09:20:43 -0700 (PDT) X-Received: by 10.52.0.177 with SMTP id 17mr14301697vdf.12.1405354843211; Mon, 14 Jul 2014 09:20:43 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id q19si5547027vea.10.2014.07.14.09.20.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 09:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hq11so6520949vcb.17 for ; Mon, 14 Jul 2014 09:20:43 -0700 (PDT) X-Received: by 10.58.207.84 with SMTP id lu20mr16642254vec.9.1405354843120; Mon, 14 Jul 2014 09:20:43 -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 tc5csp147302vcb; Mon, 14 Jul 2014 09:20:42 -0700 (PDT) X-Received: by 10.70.130.12 with SMTP id oa12mr3745348pdb.123.1405354841710; Mon, 14 Jul 2014 09:20:41 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ie10si9545476pad.64.2014.07.14.09.20.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jul 2014 09:20:41 -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 1X6iyA-00054L-Vq; Mon, 14 Jul 2014 16:19:14 +0000 Received: from mail-wi0-f180.google.com ([209.85.212.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X6iy7-0004s5-V9 for linux-arm-kernel@lists.infradead.org; Mon, 14 Jul 2014 16:19:12 +0000 Received: by mail-wi0-f180.google.com with SMTP id n3so2857651wiv.13 for ; Mon, 14 Jul 2014 09:18:49 -0700 (PDT) X-Received: by 10.194.222.5 with SMTP id qi5mr20143834wjc.62.1405354729916; Mon, 14 Jul 2014 09:18:49 -0700 (PDT) Received: from ards-macbook-pro.local ([109.227.8.83]) by mx.google.com with ESMTPSA id ut2sm19022807wjc.49.2014.07.14.09.18.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 09:18:49 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, geoff@infradead.org, mark.rutland@arm.com Subject: [PATCH 2/2] arm64/efi: efistub: get text offset and image size from the Image header Date: Mon, 14 Jul 2014 18:17:51 +0200 Message-Id: <1405354671-14031-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405354671-14031-1-git-send-email-ard.biesheuvel@linaro.org> References: <1405354671-14031-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140714_091912_152070_423A98B0 X-CRM114-Status: GOOD ( 16.79 ) 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.180 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.180 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.172 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 The EFI stub for arm64 needs to behave like an ordinary bootloader in the sense that it needs to use the EFI environment and the Image header at runtime and not rely on the linker or preprocessor to produce values for text offset, image size and kernel size. This patch also fixes the corner case where Image happens to be loaded at exactly the right offset, but the allocation is actually too small to satisfy the requirement imposed by image_size as set in the header. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/Makefile | 2 -- arch/arm64/kernel/efi-stub.c | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index cdaedad3afe5..99b676eeeb0f 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -4,8 +4,6 @@ CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) -CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) \ - -I$(src)/../../../scripts/dtc/libfdt CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index 9b61d66e2d20..4ba90b2ef677 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -11,8 +11,7 @@ */ #include #include -#include - +#include efi_status_t handle_kernel_image(efi_system_table_t *sys_table, unsigned long *image_addr, @@ -23,24 +22,28 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, efi_loaded_image_t *image) { efi_status_t status; - unsigned long kernel_size, kernel_memsize = 0; + struct arm64_image_hdr *hdr = (struct arm64_image_hdr *)*image_addr; + + /* make sure image_addr points to an arm64 kernel Image */ + if (!arm64_image_hdr_check(hdr)) { + pr_efi_err(sys_table, "Kernel Image header check failed\n"); + return EFI_LOAD_ERROR; + } /* Relocate the image, if required. */ - kernel_size = _edata - _text; - if (*image_addr != (dram_base + TEXT_OFFSET)) { - kernel_memsize = kernel_size + (_end - _edata) + TEXT_OFFSET; - status = efi_low_alloc(sys_table, kernel_memsize, SZ_2M, + if (*image_addr != (dram_base + hdr->text_offset) || + image->image_size < hdr->image_size) { + *reserve_size = hdr->text_offset + hdr->image_size; + status = efi_low_alloc(sys_table, *reserve_size, SZ_2M, reserve_addr); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel\n"); + *reserve_size = 0; return status; } - memcpy((void *)*reserve_addr + TEXT_OFFSET, (void *)*image_addr, - kernel_size); - *image_addr = *reserve_addr + TEXT_OFFSET; - *reserve_size = kernel_memsize; + memcpy((void *)*reserve_addr + hdr->text_offset, + (void *)*image_addr, image->image_size); + *image_addr = *reserve_addr + hdr->text_offset; } - - return EFI_SUCCESS; }