From nobody Sun Feb 8 19:02:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+102494+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102494+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1680622849; cv=none; d=zohomail.com; s=zohoarc; b=AuoaQr5HK4xNq19lUcSHf4ZeFGSN6ePguLp6/ec5YZ0wvzSWSec8r1dXWwy8GDqiqFIZmRewEBMKFAjbU/FEbEy+Ug9Ud726SpZOZ+GT3k0CjiWpAEzW6GKAbCTIxBCqv7UTn+6SBWf2slnZtGjb5U0ArBWdNqSSfz1cwbZVies= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680622849; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=esc1iY7OlqTvJJ7bWAINgjiY5tKGp81hOh2iBvzYjfE=; b=iF+uVXfS1LcicZrHuhMYqzRQ1p4VsLxtstgTKPkZSD5JVGtZXjq8aBKYNJVdCmCnHir/CVLqWSyo01SjOLl8zPkLS37OBuQZh7f7goglb+rHm3xVHLmY8SdhU6MrUTURTqQTWVaxfIpfzSiFtI/UYLutvulsL8wnLaUZ+TH61ds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102494+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1680622849232300.07589318787495; Tue, 4 Apr 2023 08:40:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MA75YY1788612xUiUQpQeD66; Tue, 04 Apr 2023 08:40:44 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.105360.1680622843548907559 for ; Tue, 04 Apr 2023 08:40:43 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0772F6361D; Tue, 4 Apr 2023 15:40:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8BFEC433D2; Tue, 4 Apr 2023 15:40:39 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bob Feng , Oliver Smith-Denny Subject: [edk2-devel] [PATCH v3 3/4] MdePkg/PeCoffLib: Capture DLL characteristics fields in image context Date: Tue, 4 Apr 2023 17:40:21 +0200 Message-Id: <20230404154022.2776035-4-ardb@kernel.org> In-Reply-To: <20230404154022.2776035-1-ardb@kernel.org> References: <20230404154022.2776035-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: RwQXO7SNDXgECWVywaK3mfTCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680622844; bh=TieSuqXN8pnHxWNgWVfSS01RgGZsy9uXUyIwv3atEfc=; h=Cc:Date:From:Reply-To:Subject:To; b=mfwr831YG+8VJD5BrFZSlmZKP3XwkazprV5CTZVgb5V1EhpYx4SI0cwKbT53dnp0COR wbm4mjPlJkDmXAAlMMCdmwW2ZnhR59mgc22l6L3lvcZ4JS/J2kFiIUhJBEY5VPdlstVhf P56z4WRLm2YvPusmSR0yDJo9gS6N0tupHZc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680622851838100003 Content-Type: text/plain; charset="utf-8" When loading a PE/COFF image, capture the DLL characteristics fields of the header into our image context structure so we can refer to them when mapping the image. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael Kubacki --- MdePkg/Include/IndustryStandard/PeImage.h | 13 +++++- MdePkg/Include/Library/PeCoffLib.h | 6 +++ MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 46 +++++++++++++++----- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/Ind= ustryStandard/PeImage.h index dd4cc25483bc4bcf..8646ff22b55faff0 100644 --- a/MdePkg/Include/IndustryStandard/PeImage.h +++ b/MdePkg/Include/IndustryStandard/PeImage.h @@ -625,7 +625,8 @@ typedef struct { UINT32 FileOffset; ///< The file pointer to the debug data. } EFI_IMAGE_DEBUG_DIRECTORY_ENTRY; =20 -#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C++ debug info= rmation. +#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C= ++ debug information. +#define EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20 =20 /// /// Debug Data Structure defined in Microsoft C++. @@ -669,6 +670,16 @@ typedef struct { // } EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY; =20 +/// +/// Extended DLL Characteristics +/// +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001 +#define EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040 + +typedef struct { + UINT32 DllCharacteristicsEx; +} EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENTRY; + /// /// Resource format. /// diff --git a/MdePkg/Include/Library/PeCoffLib.h b/MdePkg/Include/Library/Pe= CoffLib.h index b45879453785c77d..74cceb37bf39ffc6 100644 --- a/MdePkg/Include/Library/PeCoffLib.h +++ b/MdePkg/Include/Library/PeCoffLib.h @@ -171,6 +171,12 @@ typedef struct { /// UINT16 ImageType; /// + /// Set by PeCoffLoaderGetImageInfo() to the DLL flags stored in the PE/= COFF header and + /// in the DllCharacteristicsEx debug table. + /// + UINT16 DllCharacteristics; + UINT32 DllCharacteristicsEx; + /// /// Set by PeCoffLoaderGetImageInfo() to TRUE if the PE/COFF image does = not contain /// relocation information. /// diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/Bas= ePeCoffLib/BasePeCoff.c index 97a8aaf8c73d3e3c..4b71176a0c7c2ed0 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -308,10 +308,11 @@ PeCoffLoaderGetPeHeader ( // // Use PE32 offset // - ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsyste= m; - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeader.= SizeOfImage; - ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionA= lignment; - ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOfHe= aders; + ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsys= tem; + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeade= r.SizeOfImage; + ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.Sectio= nAlignment; + ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOf= Headers; + ImageContext->DllCharacteristics =3D Hdr.Pe32->OptionalHeader.DllCha= racteristics; } else if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL= _HDR64_MAGIC) { // // 1. Check FileHeader.NumberOfRvaAndSizes filed. @@ -429,10 +430,11 @@ PeCoffLoaderGetPeHeader ( // // Use PE32+ offset // - ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Subs= ystem; - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalHea= der.SizeOfImage; - ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Sect= ionAlignment; - ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Size= OfHeaders; + ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Su= bsystem; + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalH= eader.SizeOfImage; + ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Se= ctionAlignment; + ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Si= zeOfHeaders; + ImageContext->DllCharacteristics =3D Hdr.Pe32Plus->OptionalHeader.Dl= lCharacteristics; } else { ImageContext->ImageError =3D IMAGE_ERROR_INVALID_MACHINE_TYPE; return RETURN_UNSUPPORTED; @@ -545,8 +547,9 @@ PeCoffLoaderGetPeHeader ( Retrieves information about a PE/COFF image. =20 Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, Ima= geSize, - DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders= , and - DebugDirectoryEntryRva fields of the ImageContext structure. + DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, + DllCharacteristics, DllCharacteristicsEx and DebugDirectoryEntryRva fiel= ds of + the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. If the PE/COFF image accessed through the ImageRead service in the Image= Context structure is not a supported PE/COFF image type, then return RETURN_UNSU= PPORTED. @@ -752,7 +755,28 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize +=3D DebugEntry.SizeOfData; } =20 - return RETURN_SUCCESS; + continue; + } + + if (DebugEntry.Type =3D=3D EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERI= STICS) { + Size =3D sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENT= RY); + ReadSize =3D sizeof (EFI_IMAGE_DEBUG_EX_DLLCHARACTERISTICS_ENT= RY); + Status =3D ImageContext->ImageRead ( + ImageContext->Handle, + DebugEntry.FileOffset, + &Size, + &ImageContext->DllCharacteristicsEx + ); + if (RETURN_ERROR (Status) || (Size !=3D ReadSize)) { + ImageContext->ImageError =3D IMAGE_ERROR_IMAGE_READ; + if (Size !=3D ReadSize) { + Status =3D RETURN_UNSUPPORTED; + } + + return Status; + } + + continue; } } } --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#102494): https://edk2.groups.io/g/devel/message/102494 Mute This Topic: https://groups.io/mt/98062739/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-