From nobody Thu May 2 12:42:49 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1499279654090376.51273604209575; Wed, 5 Jul 2017 11:34:14 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8EA6920958977; Wed, 5 Jul 2017 11:32:30 -0700 (PDT) Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C06A42095896A for ; Wed, 5 Jul 2017 11:32:28 -0700 (PDT) Received: by mail-wm0-x231.google.com with SMTP id f67so121805986wmh.1 for ; Wed, 05 Jul 2017 11:34:08 -0700 (PDT) Received: from localhost.localdomain ([154.145.144.206]) by smtp.gmail.com with ESMTPSA id m73sm14592127wmi.25.2017.07.05.11.34.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 11:34:05 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=EsKgmXiWHu4L4NZetv/7f+RmB+5GukJfBdusJZB1jjc=; b=Pvjngh0sNjR2M0SpXJ2rbpvb0d5VrldiQ7YaPlDR9+UJuLtNS73q4ZId8HFTsvuR5R UOJ0CKvE68y6j0Qz1AoegZ+FI0CtB/tn8+mGFZ6c7dVSgI97f4Uia3NUb8fDGdutbG6/ xrRzWeqFQN9nXoJh10kv60NuqiRKvgRmyIz+g= 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; bh=EsKgmXiWHu4L4NZetv/7f+RmB+5GukJfBdusJZB1jjc=; b=dSuiYcMOyMWH/Oi2eGjWjy5NyBBd/x86n+xD7etg9XbdFyXoKLJ55v3gAOQh6JL6s8 K8/mGaQ2GRH6Xj0rnFdsSR1XC4cmhjDyKnalerSvYd8btKDX9SDYznlBgoeY0CI/MbUs ulMfjjTXEipeLCaIbyejTpg3ZPZpDucYzXt8hAwv6wAMz98Tk5tp4kqeuKow51dddgrF in4Pb9Lgh99BKp+wRphWsSggnnSBu2E9yC3ezuwFu3WBn/WHNRCEtVzbwmR2oCFEKFGb r7ugq6dHMlXr+hjrdWxj/z70bOgj2JVNnCCG3Cv/ou0k6zZzNRRg/hKLquYYfejFryAU orqg== X-Gm-Message-State: AIVw112B3K/7ZVKLByh9EpkHT/Z97AFjIKTBmvvD24cObAmrxR1Yi7T/ o8zpEsCe/9zUrAYZ6aZ9hA== X-Received: by 10.28.174.66 with SMTP id x63mr8879745wme.12.1499279646648; Wed, 05 Jul 2017 11:34:06 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 5 Jul 2017 19:33:59 +0100 Message-Id: <20170705183359.11970-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [edk2] [PATCH] BaseTools/GenFw: disregard payload in PE debug directory entry size X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , liming.gao@intel.com, leif.lindholm@linaro.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, the PE/COFF conversion routines in GenFw add a so-called NB10 CodeView debug record to the image, and update the associated directory entry in the PE/COFF optional header to contain its relative virtual address (RVA) and size. However, there are two levels of indirection at work here: the actual NB10 CodeView record (which is simply a magic number and some unused data fields followed by the NUL terminated filename) is emitted separately, and a separate descriptor is emitted that identifies the NB10 CodeView record as type EFI_IMAGE_DEBUG_TYPE_CODEVIEW, and records its size. The directory entry in the PE/COFF optional header should refer to this intermediate descriptor's address and size only, but the WriteDebug## () routines in GenFw erroneously record the size of both the descriptor and the NB10 CodeView record. This problem was exposed by commit e4129b0e5897 ("BaseTools: Update GenFw to clear unused debug entry generated by VS tool chain", 2017-06-19), and GenFw now crashes when it attempts to iterate over what it thinks are multiple intermediate descriptors for different kinds of debug data embedded in the image. The error is understandable, given that both are carved out of the same file space allocation, but this is really an implementation detail of GenFw, and is not required. (Note that the intermediate descriptor does not require a RVA and so it does not even need to be inside a section) So omit the size of the NB10 CodeView record from the size recorded in the optional header. Link: https://lists.01.org/pipermail/edk2-devel/2017-July/012181.html Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Co-debugged-or-whatever-by: Laszlo Ersek Reviewed-by: Laszlo Ersek Reviewed-by: Liming Gao Tested-by: Laszlo Ersek --- BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +- BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/G= enFw/Elf32Convert.c index f7b084dc9b84..14fe4a285857 100644 --- a/BaseTools/Source/C/GenFw/Elf32Convert.c +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c @@ -1142,7 +1142,7 @@ WriteDebug32 ( NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); DataDir =3D &NtHdr->Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTOR= Y_ENTRY_DEBUG]; DataDir->VirtualAddress =3D mDebugOffset; - DataDir->Size =3D Dir->SizeOfData + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENT= RY); + DataDir->Size =3D sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); } =20 STATIC diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 7eed7b92d30f..c39bdff063ab 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -1095,7 +1095,7 @@ WriteDebug64 ( NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); DataDir =3D &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRE= CTORY_ENTRY_DEBUG]; DataDir->VirtualAddress =3D mDebugOffset; - DataDir->Size =3D Dir->SizeOfData + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENT= RY); + DataDir->Size =3D sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); } =20 STATIC --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel