From patchwork Thu Oct 11 11:11:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 148619 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1979850lji; Thu, 11 Oct 2018 04:10:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV62ROLP6rlY4oEuCcoJiyUBRbsDUm4jBKD6OJwOizB0a5/Ie347cPR9DZNHeZ/D3bNnCOXzA X-Received: by 2002:a50:ac76:: with SMTP id w51-v6mr2043324edc.211.1539256210864; Thu, 11 Oct 2018 04:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539256210; cv=none; d=google.com; s=arc-20160816; b=XrAYFLx7547OipTLt0+79NW2PagDl+numwIOhw75Vc1S5L75M69bbuqT3iHll3+xTS DMfWCK4u2P7ovlE1VMaYvE8mJXifsMpMNrSsqA/R6Z0ifx9CRh///SuxKE8kMYKiOCeG U1qewDqHpUgcjimIsJzlHdxf8G1BwS75S9yzpl8uL38FA62RU5UGC5wGkjfemOfWUq+x KxNtVhEH+CugrDEjjtwqfGeqgsw1Ly0ZUrJn3UBf0TG0AHeF82Xb1gJ56aUaEQkhuI6y OnLr8BsMs3owyVmFngbOPlC7v3/U0CkPBOwSAwtks8ZYU5WjXm+oQIIf+49C/EyymtbF DSXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:message-id:date:to:from:dkim-signature; bh=z+0cvF6EB/YP+ukIsdkkdvziBoeb/kk8VL4WQOekMMI=; b=vND5bAJGKFcN15MTgiZyBAqPDi3uPg64iAOZJE3BcsJwjD83OLbABR9xAUSXRw6ec5 comqS4CbkZteQxkCLDkQx7DvkDedZfNlGxTl3YdC+ppuo8uZdyBTnxwQLUg4j71ofhCo K6mN7xD0cGftyIiqCBtkhLAWH3BE4hYrCDR+YVVPQwHisoTg8krB1m/dnBxDcBG08yTT dYD5VDHnV/elzfodiNMMmuurYMLJPncQAmHThtb56Sjjmh7fYWafCtkGE8c6X1On5mhI PG2a7wY5xpvbh16bSr5UPIfv/djqSTIZ79n+CUqJjV8iFZaFE0MyDIYIWh3lKmebEKsx xfZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XQ3mdcsi; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id m12-v6si12331678edi.384.2018.10.11.04.10.10; Thu, 11 Oct 2018 04:10:10 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XQ3mdcsi; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id E403FC21E16; Thu, 11 Oct 2018 11:10:05 +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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID 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 D81BBC21C27; Thu, 11 Oct 2018 11:10:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B4B79C21C27; Thu, 11 Oct 2018 11:10:01 +0000 (UTC) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by lists.denx.de (Postfix) with ESMTPS id 10131C21BE5 for ; Thu, 11 Oct 2018 11:10:01 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id q19-v6so987379pll.5 for ; Thu, 11 Oct 2018 04:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=74akyQI/uZb6uCUSFu0DflfeZFOf/+3TE15i10Rp7Rg=; b=XQ3mdcsizr194RTdNVrW4RU/8yyJiIHxVIjqLZMOwFmtPei23V7DdjsLHEB6ypegg7 RjAOMOEVKYZMS0B0w2Frq18cqPYqNUV3kLe5id4qP1AYML8BLltqDDOgPTjl9HbJEMcV rWs0VLPvHqRQNAcyWe9mkAgChsLfbtrB/YWzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=74akyQI/uZb6uCUSFu0DflfeZFOf/+3TE15i10Rp7Rg=; b=kAQv+8jNNZsejXRg/QgVaZnNGGDQkkbi+5DkQuBkCuj1Badxm2wYSVrryd8tz1FBqK otBgDBIJ26sAJoR4xP2vr4Y5OiNzyXYQAJgUNnGEi2H3TSCCm42msq4MhTo58loWrjVh XzJHDHOWoLgGiuurR43vNyNFnmZZ+hzsQD55F/wdABRyXqVaHSfMETt9CiGWb24xgAnC FFghv8a4Ag0XrOPFLY5sZu9N99d2EX2S4mHhjMfR46c9Sem17KMGiJTTOWhMSdmXz09T tANDL7q09dJmimdLyUVgF0i+4MgmZH4snUoi8ATa8lAGJ9RS4tmeC2hCU0Yim3NE1ipz IloA== X-Gm-Message-State: ABuFfoiHJnKpCuYk8t0Uv6KndNdtQeaaxhPVIkVKjg5A6NywHvmD8Fv4 8dAdiazodfIfnL95NLG4riF+Ug== X-Received: by 2002:a17:902:48:: with SMTP id 66-v6mr1130176pla.7.1539256199476; Thu, 11 Oct 2018 04:09:59 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s85-v6sm42224321pfi.15.2018.10.11.04.09.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 04:09:58 -0700 (PDT) From: AKASHI Takahiro To: agraf@suse.de Date: Thu, 11 Oct 2018 20:11:40 +0900 Message-Id: <20181011111140.29665-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2] efi_loader: set image_base and image_size to correct values 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, image's image_base points to an address where the image was temporarily uploaded for further loading. Since efi_loader relocates the image to final destination, image_base and image_size should reflect that. This bug was detected in UEFI SCT, "Loaded Image Protocol Test - test 2," which shows that 'Unload' function doesn't fit into a range suggested by image_base and image_size. TestCase/UEFI/EFI/Protocol/LoadedImage/BlackBoxTest/ LoadedImageBBTestMain.c:1002 Changes in this patch also includes: * reverts a patch, "efi_loader: save image relocation address and size" since newly added fields are no longer needed. * copy PE headers as well since those information will be needed for module loading, in particular, at gurb. (This bug was reported by Heinrich.) Signed-off-by: AKASHI Takahiro Reported-by: Heinrich Schuchardt --- lib/efi_loader/efi_image_loader.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index a18ce0a5705e..d1b6c0d3cdf2 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -59,10 +59,10 @@ static efi_status_t efi_print_image_info(struct efi_loaded_image_obj *obj, { printf("UEFI image"); printf(" [0x%p:0x%p]", - obj->reloc_base, obj->reloc_base + obj->reloc_size - 1); - if (pc && pc >= obj->reloc_base && - pc < obj->reloc_base + obj->reloc_size) - printf(" pc=0x%zx", pc - obj->reloc_base); + image->image_base, image->image_base + image->image_size - 1); + if (pc && pc >= image->image_base && + pc < image->image_base + image->image_size) + printf(" pc=0x%zx", pc - image->image_base); if (image->file_path) printf(" '%pD'", image->file_path); printf("\n"); @@ -212,7 +212,6 @@ void *efi_load_pe(struct efi_loaded_image_obj *handle, void *efi, int rel_idx = IMAGE_DIRECTORY_ENTRY_BASERELOC; void *entry; uint64_t image_base; - uint64_t image_size; unsigned long virt_size = 0; int supported = 0; @@ -256,7 +255,6 @@ void *efi_load_pe(struct efi_loaded_image_obj *handle, void *efi, IMAGE_NT_HEADERS64 *nt64 = (void *)nt; IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader; image_base = opt->ImageBase; - image_size = opt->SizeOfImage; efi_set_code_and_data_type(loaded_image_info, opt->Subsystem); efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); @@ -272,7 +270,6 @@ void *efi_load_pe(struct efi_loaded_image_obj *handle, void *efi, } else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader; image_base = opt->ImageBase; - image_size = opt->SizeOfImage; efi_set_code_and_data_type(loaded_image_info, opt->Subsystem); efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); @@ -291,6 +288,11 @@ void *efi_load_pe(struct efi_loaded_image_obj *handle, void *efi, return NULL; } + /* Copy PE headers */ + memcpy(efi_reloc, efi, sizeof(*dos) + sizeof(*nt) + + nt->FileHeader.SizeOfOptionalHeader + + num_sections * sizeof(IMAGE_SECTION_HEADER)); + /* Load sections into RAM */ for (i = num_sections - 1; i >= 0; i--) { IMAGE_SECTION_HEADER *sec = §ions[i]; @@ -315,10 +317,8 @@ void *efi_load_pe(struct efi_loaded_image_obj *handle, void *efi, invalidate_icache_all(); /* Populate the loaded image interface bits */ - loaded_image_info->image_base = efi; - loaded_image_info->image_size = image_size; - handle->reloc_base = efi_reloc; - handle->reloc_size = virt_size; + loaded_image_info->image_base = efi_reloc; + loaded_image_info->image_size = virt_size; return entry; }