From patchwork Sun Dec 9 22:06:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 153242 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2917696ljp; Sun, 9 Dec 2018 14:07:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/VvA9R9Tm9zyeKIMAtXBs+mhoWY+YrpmBaGEJC0+m1X1ZzPGTKdl5ktyUTvCvUUjB5NNDXQ X-Received: by 2002:a17:906:92d1:: with SMTP id d17-v6mr7921316ejx.96.1544393224703; Sun, 09 Dec 2018 14:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393224; cv=none; d=google.com; s=arc-20160816; b=gqIMl9BiXYyBmeeIhRhm2bfSIoup3o7rHyAYBiVjdLDLSovPtXtWQ7+sMq4ORFoKbR vyQgcqTeO6GFsIMoDXIzsxl0ZDaAj+JFO5AVTBgLfIQKN30qPhUVtgFvkmAPaEIiE2w0 byt9njK77pdjPayd8bQJ+w4kJ4oGlnEra5TfmpBL6EisELN/TV8sfbzY0UPx29mPX/oT YL5cP+g4BAce3I1/DbJ7+5IX2OZiewZXN8Y/Br3iPH4EXiSWgDymXnYE7ICJoRRIvinY BHD//8zZo/QiDd04w9wJDIK/AYGQ4XpifwzLazq57WOEXc7zmGDjSCAnLrXdCNzRaSyD iFYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from; bh=f9lyqHL++if9+Uj7W92g3PfCn/0xVcUsq3aq97/McKc=; b=OWC/vcgvz13LQmHbjNRzGwOlUEX4NVnNf5SP9ODx+Z3AK543vWZmJMW2SDlygoqN1B +5948rh6QMY4nFd7a5C1yjC4u9R68S+IevG7lB+F2w8csv4xBLZ/lkDiBYY6th9RBZot kYg1YjHYl2E1f6S6hqQoyDOsrNOXlb8pm+n4GUDN3uJcj/pjMKBLf6ZdY6dHoRT7YyRw lLLbDswc/9yF3NSvI/nZOUyJsMOL/8S/haXABApqCoc8Q4Jo1LoQDl5KmauK6OUPE2ks Gfr9zQjFVP2eGcJLfr8cU81eh1g4xzi+j1vLjCesiIKbUjc7E37soAcJRl26+uzzwV6j song== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id v9-v6si3240348eje.240.2018.12.09.14.07.04; Sun, 09 Dec 2018 14:07:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 03ABFC223DD; Sun, 9 Dec 2018 22:06:56 +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=RCVD_IN_DNSWL_BLOCKED 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 8F028C2216B; Sun, 9 Dec 2018 22:06:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ECFACC2216B; Sun, 9 Dec 2018 22:06:52 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 60492C21F7E for ; Sun, 9 Dec 2018 22:06:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B7E00AE5D; Sun, 9 Dec 2018 22:06:51 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Sun, 9 Dec 2018 23:06:50 +0100 Message-Id: <20181209220650.75329-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt , Guillaume GARDET , Loic Devulder Subject: [U-Boot] [PATCH] efi_loader: Make RTS relocation more robust 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" While changing the RTS alignment to 64KB in commit 7a82c3051c8f ("efi_loader: Align runtime section to 64kb") the relocation code started to break. The reason for that is that we didn't actually look at the real relocation data. We merely took the RUNTIME_CODE section as a hint and started to relocate based on self calculated data from that point on. That calculation was now out of sync though. To ensure we're not running into such a situation again, this patch makes the runtime relocation code a bit more robust. We can just trust the phys/virt hints from the payload. We also should check that we really only have a single section, as the code doesn't handle multiple code relocations yet. Fixes: 7a82c3051c8f ("efi_loader: Align runtime section to 64kb") Reported-by: Heinrich Schuchardt Reported-by: Loic Devulder Signed-off-by: Alexander Graf Tested-by: Heinrich Schuchardt --- lib/efi_loader/efi_runtime.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 95844efdb0..a9e94f78c3 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -436,14 +436,30 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( uint32_t descriptor_version, struct efi_mem_desc *virtmap) { - ulong runtime_start = (ulong)&__efi_runtime_start & - ~(ulong)EFI_PAGE_MASK; int n = memory_map_size / descriptor_size; int i; + int rt_code_sections = 0; EFI_ENTRY("%lx %lx %x %p", memory_map_size, descriptor_size, descriptor_version, virtmap); + /* Ensure we see exactly one single runtime section */ + for (i = 0; i < n; i++) { + struct efi_mem_desc *map = (void*)virtmap + + (descriptor_size * i); + + if (map->type == EFI_RUNTIME_SERVICES_CODE) + rt_code_sections++; + } + + if (rt_code_sections != 1) { + /* + * We expose exactly one single runtime code section, so + * something is definitely going wrong. + */ + return EFI_EXIT(EFI_INVALID_PARAMETER); + } + /* Rebind mmio pointers */ for (i = 0; i < n; i++) { struct efi_mem_desc *map = (void*)virtmap + @@ -483,7 +499,7 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( map = (void*)virtmap + (descriptor_size * i); if (map->type == EFI_RUNTIME_SERVICES_CODE) { ulong new_offset = map->virtual_start - - (runtime_start - gd->relocaddr); + map->physical_start + gd->relocaddr; efi_runtime_relocate(new_offset, map); /* Once we're virtual, we can no longer handle