From patchwork Fri Sep 7 05:42:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146168 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp750286ljw; Thu, 6 Sep 2018 22:42:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZUMsJRnyhPEKkHxPpIsFIYgdIpwZ1S3oXL/72zoUCYQ07URBOzw+5HPuGd3lpvheBHSwes X-Received: by 2002:a62:c288:: with SMTP id w8-v6mr6709996pfk.92.1536298931920; Thu, 06 Sep 2018 22:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536298931; cv=none; d=google.com; s=arc-20160816; b=l/zDEfJHqGUXbBJabsbop6/ER8LTH3hzIciFMEuJ00lReIw6FYe3Ctfmz7z233LKLG NPVHygQ0QHkbkXcxMh9d4VAoCmKoZGF8tOqxO6dweGwPcnGDddSmHpbO1YUaDzU8ug+F TZUgOaRSSBxOr88INJ36VftC/LxM4FVAg0G+7C4O6QBFf9GOQ4m7h5NNYofbBbLsKEd9 QY953/eKzNv44XZKseZjFjldJAdObP9si6C0iGeVfM+R2WTfJisuiy+Xt12Xe4nYB7+l YPL8/47IAH72zIWI7PrtnRsCZBcdDr+uGSmiL8TYEDUp4rhVtg+YTn0bzoC54UBNGniU 5UUg== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=vGKblAmWG4iRDr/9uPP9KKrBom1oGXrPdV9dtFtzuss=; b=PnCBphcT8g60gEoh8yDVIXIO4NFdn3dMpf3S08NRII6QQvCx/P/mJMs57hzl067JcK /5eKyvzu2oYnSQIaUwW0EjH/ehNZVXTub3VSG7FVxYFvqigAUx1LWffAUnVWANtEcUoM RbDAavmFWPo/+/mX0gpugf3z8Kf3nayjyHdfFchciBrFh8K+Dk9IgYETahO0X+uW6SSi FK4+Foe9OokwDQrUevYatitXUqOvyfC8kQ8XiXC8zm4gAIDuKSlGnRyAp8Kjjip2GmC4 3WyE4EfGv1H7TfGjIrh0e7/L2shLL1QDDax7/u80bDl7L1ewcDlDsTZqeAW3zTTmdfeW 1nLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="dQ/+2scK"; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id n3-v6si7309817pld.146.2018.09.06.22.42.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:11 -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 header.s=google header.b="dQ/+2scK"; 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 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 14E6821124AEC; Thu, 6 Sep 2018 22:42:11 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::529; helo=mail-ed1-x529.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (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 7C71821124AE1 for ; Thu, 6 Sep 2018 22:42:09 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id y20-v6so10665349edq.2 for ; Thu, 06 Sep 2018 22:42:09 -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:in-reply-to:references; bh=k1uXDYFD+ZQJUHCoToIetFQf4509RktlP+LG8Y1Eycs=; b=dQ/+2scK8WFiWNMiIrzIigjMWqg6xxsmcL/r29XhCfMfLVLt4uyNrAPcE0ESt7bUlB kUi6uDZn1lE7zERK1bqoF4JG/TP5A+8KvbmlZeiE5juGLNBr/qxI1p9h0NcvfQnPXpPT 80nIEiHoDwU3OJeD2ekjtEFK2nA6M6ra8efb0= 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:in-reply-to :references; bh=k1uXDYFD+ZQJUHCoToIetFQf4509RktlP+LG8Y1Eycs=; b=YwPlXjspYy19dUYBlYq1AV3PepU89i9y2aHGF2Hzy6wP8+8M5pA6xjLaZ4k5pVhFLI RpVPL00ryTNDrwyCITmnft1PMt/VuqDR/FKSfk1JXhgLk0Ca1WW0i8S4K8/owJrplGtx gcsmhT3K/BL1dwocIYKS7ltzkwXPJ5ABC0YodCnfwFAnItICvuKcuePGAiik9POOX3Tv tpt2cZ/bIR6Ms3QhSFXyRAWx0GKIvccUXWNSQ2aeDWFghDdGsFJ5TrsaUCX4Yay+yuxX 1+BN0AAMj0bOJW6ZHa7THCOBFlr9cHYcGdpJPJE2GiTYXcWywxGafsUYFmv9XD7j5wnj zsDg== X-Gm-Message-State: APzg51BF/784kyKu/1RDOLu6pM9+1s1qbzTd/DXYGVmHc6zytbYvNsm6 fMrctbLr/IJi9xurSEkpuxV6cCD17OyWm2ZP X-Received: by 2002:a50:f5ae:: with SMTP id u43-v6mr7073674edm.75.1536298927631; Thu, 06 Sep 2018 22:42:07 -0700 (PDT) Received: from mba13.debuut.local ([2a02:a212:9283:9800:154c:2f23:f4db:9e4b]) by smtp.gmail.com with ESMTPSA id i19-v6sm3460195edg.64.2018.09.06.22.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:06 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 7 Sep 2018 07:42:00 +0200 Message-Id: <20180907054202.24798-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907054202.24798-1-ard.biesheuvel@linaro.org> References: <20180907054202.24798-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 1/3] MdeModulePkg: remove PE/COFF header workaround for ELILO on IPF X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Jiewen Yao , Star Zeng , Michael D Kinney , Laszlo Ersek , Chao Zhang MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Laszlo Ersek Reviewed-by: Star Zeng --- MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c | 31 +------------------- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 17 +---------- MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 17 +---------- MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 17 +---------- MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c | 31 +------------------- 5 files changed, 5 insertions(+), 108 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c index 83ed43a16e95..ff1940431c2f 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c @@ -254,35 +254,6 @@ GetMemoryProfileContext ( return mMemoryProfileContextPtr; } -/** - Retrieves the magic value from the PE/COFF header. - - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. - - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ - -**/ -UINT16 -InternalPeCoffGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; -} - /** Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory. If Pe32Data is NULL, then ASSERT(). @@ -319,7 +290,7 @@ InternalPeCoffGetSubsystem ( if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { return Hdr.Te->Subsystem; } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { - Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr); + Magic = Hdr.Pe32->OptionalHeader.Magic; if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { return Hdr.Pe32->OptionalHeader.Subsystem; } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 4cd219c88efc..fa8f8fe91ac7 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -406,7 +406,6 @@ ProtectUefiImage ( IMAGE_PROPERTIES_RECORD *ImageRecord; CHAR8 *PdbPointer; IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - UINT16 Magic; BOOLEAN IsAligned; UINT32 ProtectionPolicy; @@ -466,21 +465,7 @@ ProtectUefiImage ( // // Get SectionAlignment // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; } else { SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment; diff --git a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c index a96d442fbc64..05eb4f422b2f 100644 --- a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c @@ -1076,7 +1076,6 @@ InsertImageRecord ( IMAGE_PROPERTIES_RECORD *ImageRecord; CHAR8 *PdbPointer; IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - UINT16 Magic; DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%x\n", RuntimeImage)); DEBUG ((EFI_D_VERBOSE, "InsertImageRecord - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase, RuntimeImage->ImageSize)); @@ -1126,21 +1125,7 @@ InsertImageRecord ( // // Get SectionAlignment // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; } else { SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment; diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c index 1682d0f9e404..157beb1e67ff 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -1032,7 +1032,6 @@ SmmInsertImageRecord ( IMAGE_PROPERTIES_RECORD *ImageRecord; CHAR8 *PdbPointer; IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection; - UINT16 Magic; DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%x\n", DriverEntry)); DEBUG ((DEBUG_VERBOSE, "SMM InsertImageRecord - 0x%016lx - 0x%08x\n", DriverEntry->ImageBuffer, DriverEntry->NumberOfPage)); @@ -1076,21 +1075,7 @@ SmmInsertImageRecord ( // // Get SectionAlignment // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; } else { SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment; diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index b586afa7948e..e8d60c2d2357 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -255,35 +255,6 @@ GetSmramProfileContext ( return mSmramProfileContextPtr; } -/** - Retrieves the magic value from the PE/COFF header. - - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. - - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ - -**/ -UINT16 -InternalPeCoffGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; -} - /** Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory. If Pe32Data is NULL, then ASSERT(). @@ -320,7 +291,7 @@ InternalPeCoffGetSubsystem ( if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { return Hdr.Te->Subsystem; } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { - Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr); + Magic = Hdr.Pe32->OptionalHeader.Magic; if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { return Hdr.Pe32->OptionalHeader.Subsystem; } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { From patchwork Fri Sep 7 05:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146169 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp750327ljw; Thu, 6 Sep 2018 22:42:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZgHtSbvkYCZIfPRKVJMDAP4nDOSfwMYCEw8SWYgZLKUWR+Rg0elFHTYZKmFZfWe8Mot4zG X-Received: by 2002:a17:902:102c:: with SMTP id b41-v6mr6288821pla.257.1536298934955; Thu, 06 Sep 2018 22:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536298934; cv=none; d=google.com; s=arc-20160816; b=xjciXa+srShSlMWpBYVbGe/M4zkfQABwtHlLRJWwA4p3GnfhRCMdjl43IrxxjZ5yVL RYAgkGlKgH9MpWhE2I+EhnDQLQyVGNhapUWYtV0IsCaDjCmHv0LI7rCmF28sqlCkdBI3 EfrxQDHKR6OXajM4V+ihTgpSsp8jaKM4c62LxQyXrVKWVh685OB0CwiAyROmKLFjfRHY yunUrTqaOeYXphw8/49enOTmQaRtXFBlUm3hrK7T+KK/L8GD3WSmbxQgOb77GiJ9ptgz /o/H2elvL/GopfHud4kXyB4NGiokqq34sC+LfciIR/s0NpOolo5TwIXtmEkv3789orm9 O1xA== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=fbRS7dO8S+EdXesUuwLr+Qd4f/3BfzSEFsKZaVds9Ys=; b=NNvIA+x/uRv/MWVsEvh7vtxPfd1gtOEmhFcCDyAHJ/KU3rshpAPC1lrXy4UhAuGBO9 v1CFiVzsJcxkzPjmLeiWwFInjyyLZSW/EB8pYIbIg70yF/6AuVfVkJMJCce4gJwPPeBh uxckyayx58ZM+v0dbku0WUARqOd2e9Zghnqz5j5VDJF/iROIiBfBWwyJ6q5WiELJu7sh xrA+RYhELC6mn0aC2OKSPM0aSNfew3WEeb1e1UsAnGFa5uS2XzXcktoBdPaNnYcagDZX ws1h7SjQ8JPHwcBX88KA1tB1fD4MYWLqzrgGkWlOEriWHUf5nT/OOw0HbRmPoCAKY7MH YxVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FQHJdUdg; 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 m13-v6si6955032pgh.360.2018.09.06.22.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:14 -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.s=google header.b=FQHJdUdg; 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 411E921124AF2; Thu, 6 Sep 2018 22:42:13 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::543; helo=mail-ed1-x543.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) (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 18D9B21124AEE for ; Thu, 6 Sep 2018 22:42:10 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id f4-v6so10651774edq.3 for ; Thu, 06 Sep 2018 22:42:10 -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:in-reply-to:references; bh=q3W8o++5y4P8uJ4PI+3ZWU4e+d2BEUoEBYVvKfDzops=; b=FQHJdUdgnSSTx8Zq2CE272OPxgTKiztbUoFJdjUmMkd5v83vqSTDYtO+/AtTy4m9a3 YfJlz5xPaMqvYF6HH1YmmRv/bthEKQ86Rg2WZtdL410XP9kOQZK+dwHG71SP2XL4T1Cq 03SrnDtTVqD/Af5I65/6efDZYXgQMEo+FJnys= 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:in-reply-to :references; bh=q3W8o++5y4P8uJ4PI+3ZWU4e+d2BEUoEBYVvKfDzops=; b=Ma6tXnQ1noWzCfZMrEjhX5cp+k4iXXG5tBol8U7VAv5YFMgyPnF9gYPv1owtQLRx8u Ohku3CKedMNHzwVRfOC5YyXH4x49xjGlvwpBXNEey/7I9yz9uT+u2k9IdpypHbhjBaRX 8zM230QqacszPffV2N9LzRDPmDK1nS1xnkdKAnkGi6aEjm24E+lg6GSA9EOdzZZk4UJX pwjLxy23CUrCTNat8O48U+mpmGlUzWRtULaISRZA+dkCLUyaTDPLzIWYg+pCEXHNvoIX gzs5ySKJSKKaUSvths2DByVHBPMM4aAH/wnigoO5ZiuhXKQSGENpdKO0oMYYIBxLvktN YV9w== X-Gm-Message-State: APzg51BT/c3qTXg+YZuyZ5Bemu3E9zJu5OcQVWTEsd2stJXOLwwpbC9E eqGXNnrHy/rhOphWZG3s7R8UDp8h8ze5xEUu X-Received: by 2002:aa7:c152:: with SMTP id r18-v6mr6928944edp.109.1536298929220; Thu, 06 Sep 2018 22:42:09 -0700 (PDT) Received: from mba13.debuut.local ([2a02:a212:9283:9800:154c:2f23:f4db:9e4b]) by smtp.gmail.com with ESMTPSA id i19-v6sm3460195edg.64.2018.09.06.22.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:08 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 7 Sep 2018 07:42:01 +0200 Message-Id: <20180907054202.24798-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907054202.24798-1-ard.biesheuvel@linaro.org> References: <20180907054202.24798-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 2/3] MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPF X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Jiewen Yao , Star Zeng , Michael D Kinney , Laszlo Ersek , Chao Zhang MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Laszlo Ersek Reviewed-by: Star Zeng Reviewed-by: Liming Gao --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 61 +++----------------- 1 file changed, 9 insertions(+), 52 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 32eca0ad2ef4..c57816a80887 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -46,36 +46,6 @@ PeCoffLoaderAdjustOffsetForTeImage ( SectionHeader->PointerToRawData -= TeStrippedOffset; } -/** - Retrieves the magic value from the PE/COFF header. - - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. - - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ - -**/ -UINT16 -PeCoffLoaderGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr - ) -{ - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; -} - - /** Retrieves the PE or TE Header from a PE/COFF or TE image. @@ -101,7 +71,6 @@ PeCoffLoaderGetPeHeader ( EFI_IMAGE_DOS_HEADER DosHdr; UINTN Size; UINTN ReadSize; - UINT16 Magic; UINT32 SectionHeaderOffset; UINT32 Index; UINT32 HeaderWithoutDataDir; @@ -222,9 +191,7 @@ PeCoffLoaderGetPeHeader ( ImageContext->IsTeImage = FALSE; ImageContext->Machine = Hdr.Pe32->FileHeader.Machine; - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // 1. Check OptionalHeader.NumberOfRvaAndSizes filed. // @@ -339,7 +306,7 @@ PeCoffLoaderGetPeHeader ( ImageContext->SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; ImageContext->SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders; - } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { // // 1. Check FileHeader.NumberOfRvaAndSizes filed. // @@ -605,7 +572,6 @@ PeCoffLoaderGetImageInfo ( EFI_IMAGE_SECTION_HEADER SectionHeader; EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; UINT32 TeStrippedOffset; if (ImageContext == NULL) { @@ -622,14 +588,12 @@ PeCoffLoaderGetImageInfo ( return Status; } - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - // // Retrieve the base address of the image // if (!(ImageContext->IsTeImage)) { TeStrippedOffset = 0; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -678,7 +642,7 @@ PeCoffLoaderGetImageInfo ( } if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -952,7 +916,6 @@ PeCoffLoaderRelocateImage ( CHAR8 *FixupData; PHYSICAL_ADDRESS BaseAddress; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; UINT32 TeStrippedOffset; ASSERT (ImageContext != NULL); @@ -985,9 +948,8 @@ PeCoffLoaderRelocateImage ( if (!(ImageContext->IsTeImage)) { Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset); TeStrippedOffset = 0; - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1230,7 +1192,6 @@ PeCoffLoaderLoadImage ( UINTN Size; UINT32 TempDebugEntryRva; UINT32 NumberOfRvaAndSizes; - UINT16 Magic; EFI_IMAGE_RESOURCE_DIRECTORY *ResourceDirectory; EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceDirectoryEntry; EFI_IMAGE_RESOURCE_DIRECTORY_STRING *ResourceDirectoryString; @@ -1404,12 +1365,11 @@ PeCoffLoaderLoadImage ( // // Get image's entry point // - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (!(ImageContext->IsTeImage)) { // // Sizes of AddressOfEntryPoint are different so we need to do this safely // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1444,7 +1404,7 @@ PeCoffLoaderLoadImage ( // the optional header to verify a desired directory entry is there. // if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1565,7 +1525,7 @@ PeCoffLoaderLoadImage ( // ImageContext->HiiResourceData = 0; if (!(ImageContext->IsTeImage)) { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1721,7 +1681,6 @@ PeCoffLoaderRelocateImageForRuntime ( CHAR8 *FixupData; UINTN Adjust; RETURN_STATUS Status; - UINT16 Magic; OldBase = (CHAR8 *)((UINTN)ImageBase); NewBase = (CHAR8 *)((UINTN)VirtImageBase); @@ -1750,9 +1709,7 @@ PeCoffLoaderRelocateImageForRuntime ( return ; } - Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); - - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // From patchwork Fri Sep 7 05:42:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146170 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp750391ljw; Thu, 6 Sep 2018 22:42:18 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+VHgVY9pZDjusQgZIct6kwnLk4r4/cVpylc4TlzDoR0/JwPFuXQBbM/hOytnuhFoHrY54 X-Received: by 2002:a63:f26:: with SMTP id e38-v6mr6289715pgl.354.1536298938448; Thu, 06 Sep 2018 22:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536298938; cv=none; d=google.com; s=arc-20160816; b=oR8+7VdE+G5/eZ6Lq9A9KibE2qUUAJwCz/X8yEddxi/iLgzF9CEu7c5kGDPyO5y85k X7fKuI2w6BVpobkIjQwP0l0mSyfpenEAs8aQ+1HoiOVChQWOwRHEjkDV9YmAm3hlzA5o 8cGSu8iD9dq+XmJwvL1W8KFDCaCqzxJd8QXrtYI9C9Ay0svkyNrZNqWzRmXpl0F81epL JRrOC/ugVvbfuP1sc7mgyJp+kxM3eou+Mgx1SYLJcZtYv0GUVq8Hd37fIcnxTj1Wvh0c CtfAbZmaNiKhQjFJ+rndVkSqVmNYwgzomjPz0YgYCI5/Z8uCa0G7cqJJnp8JkWkziISw PIPg== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=9yoMUH+nAGTo+d77WkLtMz9UOw6Oa0qFszKeAIMyiJs=; b=KSNqFyYhzeFsxGHoSaTXbmUbFl9OBhJoG+n23M0yP+M1q4sHvWrYdKQQ82hYdDnz+W 0VcXfhXbslwp3Bu2XY14Liv7lIu6Onz7E1m0+erNgi8YfY/7kTsZFd/Juio5VXi8W/7x s8a9jrw78LcnpJAwyrSohJWFnwayIcwJhnJxwpSj1Q6IRkXuEeAIxSp8jFgSDkzliOhZ f0BmER9uFU/XlSGxINX4MOwwjFV8i0L/rnujfKKMF/7LlxWWDIf0uQkNgUPs+69pGes+ ox1hn8FxgnLudPCRUNqLTs71mML5rK8aggn2koodxm0YIi9o4I1n/Q3m4BA0qrEH3bnY yNoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ibpDyMei; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id l12-v6si6953737plc.332.2018.09.06.22.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:18 -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 header.s=google header.b=ibpDyMei; 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 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 6D09A21124AF7; Thu, 6 Sep 2018 22:42:14 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::542; helo=mail-ed1-x542.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (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 4DD5E21124AEE for ; Thu, 6 Sep 2018 22:42:12 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id a20-v6so10644919edd.4 for ; Thu, 06 Sep 2018 22:42:12 -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:in-reply-to:references; bh=TPtTORo0f/nY5jUxmY0qAqynyGKjW+9DsuR+ZQT49Qw=; b=ibpDyMeiq1ZTwzwqwfW/yjZ9dOCMQu2fXSSeTdStkRnWmwhcgHrxEg/HWKKfshsxo6 XRh0nJiXL8MJ4CqUwmqTm6dssL2kTtT560alJuFGZhHtKacX+xNwrj3knEa8wY5hywxe 33maSOIyTKsJAXK1uznNzgfP+PWfOmeVtdETI= 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:in-reply-to :references; bh=TPtTORo0f/nY5jUxmY0qAqynyGKjW+9DsuR+ZQT49Qw=; b=hW6h8XUoblFgR5lRUXzH1KJw6MvtORh9DcWfJKL9C3LaaRhvAYU1fRdILftDOlDS98 vwfi+ksUGYcubyMvtoAb3W0cP8TVPyoEYxoTyW2Py0KEj0oCpFK0EZfuw38C6y6U8hET uCmkEhG8vYbVJUOhHEpfJ0BReSnRFD/5YUe3h3vUomUn+PxNs7NRDTyFD3GIySanHDo5 oR/EKjeM1MsguWZxlXHvIX4zYhK69uk/UmzugA5v3nOvVlxPt6Efe6q2dGvMC2gcgRp0 RszeTQ5Rap6rnTP7+FA2DssNwUKpJn6a6VMYKUMBBNEGKqpMEzcsQY0zX+0QU/eh8gGo /dUw== X-Gm-Message-State: APzg51Ct0XzfTM5KalQYIimMKqxoqKudmuRD0AfglSTFulkJ+9t6UgHK vwbfEIWzHq8AvzB9t3MizCLJ5A/d4h/hxwUm X-Received: by 2002:a50:96c4:: with SMTP id z4-v6mr7161914eda.14.1536298930522; Thu, 06 Sep 2018 22:42:10 -0700 (PDT) Received: from mba13.debuut.local ([2a02:a212:9283:9800:154c:2f23:f4db:9e4b]) by smtp.gmail.com with ESMTPSA id i19-v6sm3460195edg.64.2018.09.06.22.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 22:42:09 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 7 Sep 2018 07:42:02 +0200 Message-Id: <20180907054202.24798-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907054202.24798-1-ard.biesheuvel@linaro.org> References: <20180907054202.24798-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 3/3] SecurityPkg: remove PE/COFF header workaround for ELILO on IPF X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Jiewen Yao , Star Zeng , Michael D Kinney , Laszlo Ersek , Chao Zhang MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c | 47 ++++---------------- SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c | 27 +++-------- SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c | 27 +++-------- SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c | 25 +++-------- 4 files changed, 25 insertions(+), 101 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c index 0f795c0af125..66d96a9396b9 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -295,7 +295,6 @@ HashPeImage ( ) { BOOLEAN Status; - UINT16 Magic; EFI_IMAGE_SECTION_HEADER *Section; VOID *HashCtx; UINTN CtxSize; @@ -367,33 +366,19 @@ HashPeImage ( // Measuring PE/COFF Image Header; // But CheckSum field and SECURITY data directory (certificate) are excluded // - if (mNtHeader.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = mNtHeader.Pe32->OptionalHeader.Magic; - } // // 3. Calculate the distance from the base of the image header to the image checksum address. // 4. Hash the image header from its base to beginning of the image checksum. // HashBase = mImageBase; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // HashSize = (UINTN) (&mNtHeader.Pe32->OptionalHeader.CheckSum) - (UINTN) HashBase; NumberOfRvaAndSizes = mNtHeader.Pe32->OptionalHeader.NumberOfRvaAndSizes; - } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { // // Use PE32+ offset. // @@ -420,7 +405,7 @@ HashPeImage ( // 6. Since there is no Cert Directory in optional header, hash everything // from the end of the checksum to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -444,7 +429,7 @@ HashPeImage ( // // 7. Hash everything from the end of the checksum to the start of the Cert Directory. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -469,7 +454,7 @@ HashPeImage ( // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.) // 9. Hash everything from the end of the Cert Directory to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -494,7 +479,7 @@ HashPeImage ( // // 10. Set the SUM_OF_BYTES_HASHED to the size of the header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -577,7 +562,7 @@ HashPeImage ( if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) { CertSize = 0; } else { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -1583,7 +1568,6 @@ DxeImageVerificationHandler ( ) { EFI_STATUS Status; - UINT16 Magic; EFI_IMAGE_DOS_HEADER *DosHdr; EFI_STATUS VerifyStatus; EFI_SIGNATURE_LIST *SignatureList; @@ -1723,22 +1707,7 @@ DxeImageVerificationHandler ( goto Done; } - if (mNtHeader.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = mNtHeader.Pe32->OptionalHeader.Magic; - } - - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c index c54ab62e2745..4e4a90f9da62 100644 --- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c @@ -320,7 +320,6 @@ TcgMeasurePeImage ( EFI_IMAGE_SECTION_HEADER *SectionHeader; UINTN Index; UINTN Pos; - UINT16 Magic; UINT32 EventSize; UINT32 EventNumber; EFI_PHYSICAL_ADDRESS EventLogLastEntry; @@ -418,27 +417,13 @@ TcgMeasurePeImage ( // Measuring PE/COFF Image Header; // But CheckSum field and SECURITY data directory (certificate) are excluded // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } // // 3. Calculate the distance from the base of the image header to the image checksum address. // 4. Hash the image header from its base to beginning of the image checksum. // HashBase = (UINT8 *) (UINTN) ImageAddress; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -465,7 +450,7 @@ TcgMeasurePeImage ( // 6. Since there is no Cert Directory in optional header, hash everything // from the end of the checksum to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -489,7 +474,7 @@ TcgMeasurePeImage ( // // 7. Hash everything from the end of the checksum to the start of the Cert Directory. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -514,7 +499,7 @@ TcgMeasurePeImage ( // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.) // 9. Hash everything from the end of the Cert Directory to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -539,7 +524,7 @@ TcgMeasurePeImage ( // // 10. Set the SUM_OF_BYTES_HASHED to the size of the header // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -621,7 +606,7 @@ TcgMeasurePeImage ( if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) { CertSize = 0; } else { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // diff --git a/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c b/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c index 29da2d70e699..e114d672f9d9 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/MeasureBootPeCoff.c @@ -116,7 +116,6 @@ MeasurePeImageAndExtend ( EFI_IMAGE_SECTION_HEADER *SectionHeader; UINTN Index; UINTN Pos; - UINT16 Magic; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; UINT32 NumberOfRvaAndSizes; UINT32 CertSize; @@ -181,27 +180,13 @@ MeasurePeImageAndExtend ( // Measuring PE/COFF Image Header; // But CheckSum field and SECURITY data directory (certificate) are excluded // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = Hdr.Pe32->OptionalHeader.Magic; - } // // 3. Calculate the distance from the base of the image header to the image checksum address. // 4. Hash the image header from its base to beginning of the image checksum. // HashBase = (UINT8 *) (UINTN) ImageAddress; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -228,7 +213,7 @@ MeasurePeImageAndExtend ( // 6. Since there is no Cert Directory in optional header, hash everything // from the end of the checksum to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -252,7 +237,7 @@ MeasurePeImageAndExtend ( // // 7. Hash everything from the end of the checksum to the start of the Cert Directory. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -277,7 +262,7 @@ MeasurePeImageAndExtend ( // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.) // 9. Hash everything from the end of the Cert Directory to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -302,7 +287,7 @@ MeasurePeImageAndExtend ( // // 10. Set the SUM_OF_BYTES_HASHED to the size of the header // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -384,7 +369,7 @@ MeasurePeImageAndExtend ( if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) { CertSize = 0; } else { - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index 9acaa7b97507..f96325e978a5 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -1831,7 +1831,6 @@ HashPeImage ( ) { BOOLEAN Status; - UINT16 Magic; EFI_IMAGE_SECTION_HEADER *Section; VOID *HashCtx; UINTN CtxSize; @@ -1874,27 +1873,13 @@ HashPeImage ( // Measuring PE/COFF Image Header; // But CheckSum field and SECURITY data directory (certificate) are excluded // - if (mNtHeader.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } else { - // - // Get the magic value from the PE/COFF Optional Header - // - Magic = mNtHeader.Pe32->OptionalHeader.Magic; - } // // 3. Calculate the distance from the base of the image header to the image checksum address. // 4. Hash the image header from its base to beginning of the image checksum. // HashBase = mImageBase; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -1915,7 +1900,7 @@ HashPeImage ( // 6. Get the address of the beginning of the Cert Directory. // 7. Hash everything from the end of the checksum to the start of the Cert Directory. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -1937,7 +1922,7 @@ HashPeImage ( // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.) // 9. Hash everything from the end of the Cert Directory to the end of image header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // @@ -1958,7 +1943,7 @@ HashPeImage ( // // 10. Set the SUM_OF_BYTES_HASHED to the size of the header. // - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. // @@ -2032,7 +2017,7 @@ HashPeImage ( // if (mImageSize > SumOfBytesHashed) { HashBase = mImageBase + SumOfBytesHashed; - if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset. //