From patchwork Mon Jul 3 22:12:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 783663 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3x1hGp0FPtz9sNv for ; Tue, 4 Jul 2017 08:13:22 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 28DDEC21DF3; Mon, 3 Jul 2017 22:13:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3DD83C21C54; Mon, 3 Jul 2017 22:13:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C33C0C21C54; Mon, 3 Jul 2017 22:13:13 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lists.denx.de (Postfix) with ESMTPS id 687E1C21C4F for ; Mon, 3 Jul 2017 22:13:13 +0000 (UTC) Received: from workstation4.fritz.box ([88.152.145.149]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LoE4f-1duulS35VR-00gGwV; Tue, 04 Jul 2017 00:13:11 +0200 From: Heinrich Schuchardt To: Alexander Graf , Tom Rini Date: Tue, 4 Jul 2017 00:12:58 +0200 Message-Id: <20170703221258.3354-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170703211125.GU9889@bill-the-cat> References: <20170703211125.GU9889@b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A/uNAmDAAka5WY= Cc: u-boot@lists.denx.de, "xypron.glpk@gmx.de" Subject: [U-Boot] [PATCH v2 1/1] efi_loader: abort on unsupported relocation type X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: "xypron.glpk@gmx.de" If a relocation type is not supported loading the EFI binary should be aborted. Writing a message only is insufficient. Signed-off-by: Heinrich Schuchardt --- v2 Use (uintptr_t) to convert a pointer to an integer. This avoids 'warning: cast from pointer to integer of different size' on 32bit systems. --- lib/efi_loader/efi_image_loader.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 3262d76bca..607feff4e9 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -26,7 +26,7 @@ efi_status_t EFIAPI efi_return_handle(void *handle, efi_guid_t *protocol, return EFI_SUCCESS; } -static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, +static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, unsigned long rel_size, void *efi_reloc) { const IMAGE_BASE_RELOCATION *end; @@ -63,11 +63,13 @@ static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, default: printf("Unknown Relocation off %x type %x\n", offset, type); + return EFI_LOAD_ERROR; } relocs++; } rel = (const IMAGE_BASE_RELOCATION *)relocs; } + return EFI_SUCCESS; } void __weak invalidate_icache_all(void) @@ -171,7 +173,11 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info) } /* Run through relocations */ - efi_loader_relocate(rel, rel_size, efi_reloc); + if (EFI_SUCCESS != efi_loader_relocate(rel, rel_size, efi_reloc)) { + efi_free_pages((uintptr_t) efi_reloc, + (virt_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT); + return NULL; + } /* Flush cache */ flush_cache((ulong)efi_reloc,