From patchwork Wed Jul 5 18:33:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 107089 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1112842qge; Wed, 5 Jul 2017 11:34:11 -0700 (PDT) X-Received: by 10.98.200.27 with SMTP id z27mr21620628pff.136.1499279651249; Wed, 05 Jul 2017 11:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499279651; cv=none; d=google.com; s=arc-20160816; b=iPnmgSHyP1Mln7CVRh6XSn0lqs3y4T/db1GxeszEIREnteCwWvftabyttuz6Kl6nQs 6wcDgNGjJ0YFU2Fw5wQdaPZsDk5fYRkf6jmvLKakE5lQAZR8+y551gQ/vMjQ1F47WFAE Khw1xAL6lTxk7Qv2aUE0cECjeL8US9yadz6NjyDFyhqoCfPcXFZKAg4Hn0u77GXsafsg Qw+yVJSRs7V84tf48LnAuIMHAjpHx6B/iN6hjnxXdTFjMLKvWGaL3DFAeJtNJShgt5NK t/+1MCGcmke24fZWn2aKuQy5wRHbyLCe1HdlUTtKtUaVXV39HcE8NBwEz/yZfRFrX+92 2feA== 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:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=Noa1pYtlBIe7eTfLbX0sWrpBXL2cSA2GXnNF5R//Eo4=; b=qIWTL/IMcz7lvyQTeyw7pblZbEAaDnPB7oPqSZjQ2ZcgG79AxdPBhrRX6wteIwhOPM GlrZaR9Egw+quaxKI3wGp9SUvpumAI2sfgVlkvVX3f5ooVP9N3rsEi9kq6kGfrUfwK/o 5bJJtzjbJsrh4FfsH3hd/5p2UA6kJxKk6Y9wfXhwFHj4ZY9EBVhDbJTse6CQ40wFKuSt o8TnAlurUOtYP7uEYZ+9DtaUye6k4ea0NEr5GO9UzcW3WZiREhMH8EnModXgiIAFrWio h9x7n5CQdrBPQiNUsWPiVX9A/ezNHvrsUKuycVZ0njBEdvDDNUoI/CJ16fehuhx4irLM RT1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=Pvjngh0s; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id 3si777910plx.138.2017.07.05.11.34.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 11:34:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=Pvjngh0s; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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) 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) 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) 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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +- BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek Tested-by: Laszlo Ersek Reviewed-by: Liming Gao diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/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 = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); DataDir = &NtHdr->Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]; DataDir->VirtualAddress = mDebugOffset; - DataDir->Size = Dir->SizeOfData + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + DataDir->Size = sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); } STATIC diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/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 = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); DataDir = &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]; DataDir->VirtualAddress = mDebugOffset; - DataDir->Size = Dir->SizeOfData + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + DataDir->Size = sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); } STATIC