From patchwork Thu Mar 31 07:36:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 64740 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2106lbc; Thu, 31 Mar 2016 00:36:53 -0700 (PDT) X-Received: by 10.66.220.66 with SMTP id pu2mr19871832pac.115.1459409813834; Thu, 31 Mar 2016 00:36:53 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id a70si12305585pfj.109.2016.03.31.00.36.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Mar 2016 00:36:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9E6F11A1E69; Thu, 31 Mar 2016 00:37:23 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com [IPv6:2a00:1450:400c:c09::22e]) (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 E8E491A1FD5 for ; Thu, 31 Mar 2016 00:37:21 -0700 (PDT) Received: by mail-wm0-x22e.google.com with SMTP id p65so212641143wmp.1 for ; Thu, 31 Mar 2016 00:36:51 -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=BD6Fltt3/FN3fHlmi3zpTYFI0s8vAJL1uhjzOAX4sHc=; b=F7tV8W/KBuQ3Gg5Y8vmksNrNN8H0Lgo+mG14JQi++FosnZydYjeadmY24yPIjlxPpf N2wcqnUGmx8BZOXLYdczfdz+9YioW2Iak/6RYcX0zH5Wte2PCiz1Jdm6TfhfpvfQr0Jn jCuYGiAN2uu8h1znkQ8eHmdRUqM2v/22LhYN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BD6Fltt3/FN3fHlmi3zpTYFI0s8vAJL1uhjzOAX4sHc=; b=GecA7F4gDi7808CFFOa4nJsGlJkkqLrlZeERD1cundyDW7xYFFqXNhlK7Ppg4m/ATc TkGq4YTHn4IGaBVlCV58BlBoY1e0Tjn6NJfAAgYC/LSa5rF3A27Thi2TqIbDUJiZ9le4 JRDgPgbEk6OkCzaqGgtCye2jH3/taRgaFzcTMsDY/SNuW3sWf3wcLwBpXppKKPfQR1UJ b/xs4Aqr4jO+oImfFzQCg2fVyze3dmKg4o8KalAQQVSn3bd0MQKAomvzpuLqPZ+M+WN6 LAu7op2UNmJtn/2SZsXJUUY9r/9J8SaaUOSEOJZ7twYnZHMRXs4WF418gy/qyrSY3Z+p zxuw== X-Gm-Message-State: AD7BkJKKlc4qTN9jrApatVDzrf9di4Sguc0LnmDFvj4xFa2UK60S8DcyCE0Y01U7BvRVVW7o X-Received: by 10.194.190.6 with SMTP id gm6mr2742732wjc.115.1459409809763; Thu, 31 Mar 2016 00:36:49 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id i5sm7571736wja.23.2016.03.31.00.36.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Mar 2016 00:36:48 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Thu, 31 Mar 2016 09:36:43 +0200 Message-Id: <1459409803-15099-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 Subject: [edk2] [PATCH] ArmPlatformPkg/DS-5: fix 64-bit PE/COFF header parsing bug X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The 64-bit version of the DS-5 debug script that retrieves the debug file path from the PE/COFF image in memory assumes that the PE/COFF header is packed, and that the debug directory entry in the optional header appears at a fixed offset into file. This is no longer true, now that we pad between the file header and the PE header if the section alignment exceeds the size of the header (which may be the case when the module contains a vector table or small model code, which requires 2 KB or 4 KB section alignment, respectively), to allow this padding to be emitted if the image is subsequently converted to TE format. So replace the fixed offset with a dereference of the appropriate header field. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reported-by: Vladimir Olovyannikov --- ArmPlatformPkg/Scripts/Ds5/firmware_volume.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py index c434e3de19da..9a76ae066d9a 100644 --- a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py +++ b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py @@ -138,11 +138,10 @@ class EfiSectionPE64: def get_debug_filepath(self): # Offset from dos hdr to PE file hdr (EFI_IMAGE_NT_HEADERS64) - #file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C) - file_header_offset = 0x0 + file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C) # Offset to debug dir in PE hdrs - debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + file_header_offset + 0x138) + debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + file_header_offset + 0xB8) if debug_dir_entry_rva == 0: raise Exception("EfiFileSectionPE64","No Debug Directory")