From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.26509.1678727931289257805 for ; Mon, 13 Mar 2023 10:18:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NJ56QKPe; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) 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 CD69D61365; Mon, 13 Mar 2023 17:18:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D0C4C4339B; Mon, 13 Mar 2023 17:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678727930; bh=qAaDJnRgug6sWDfmDSA/Hw0vAgVcW3Zwm8s5ok0w4Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJ56QKPe6bWp/vQaLWrYd04reJMTiUM6nFdfc30gmEK/mwInSgdYLXvAfftwNXypI ClCVIz4jErDJsggrvnKMK+c3A8PAXHC04A2tBD/kG+yEmrta56H5oVUZmAwvqChr3I Nz2ekjloZ7NB5gg8ezqRMfHBCl+meO3u5UyuAGpvPgIwWMXnhUUUHcpuJtx4DHcevh rlww0BMdSyymf5DuFW4UOjtERyoGRnLF/zXrXZHAgoH9fUgMqJuWk0VksV5FjG7IsV Eb1l4407YeaJV6tBSaBA/eCSZ873Juh2XL9xjsJH+0dLxziOXPlSlyai9AAU89DZQa SZlK4NKmLqCvA== 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 Subject: [PATCH v5 29/38] MdePkg/PeCoffLib: Capture DLL characteristics field in image context Date: Mon, 13 Mar 2023 18:17:05 +0100 Message-Id: <20230313171714.3866151-30-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable When loading a PE/COFF image, capture the DLL characteristics field of the header into our image context structure so we can refer to it when mapping the image. Signed-off-by: Ard Biesheuvel --- MdePkg/Include/Library/PeCoffLib.h | 4 ++++ MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 23 +++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/MdePkg/Include/Library/PeCoffLib.h b/MdePkg/Include/Library/Pe= CoffLib.h index df2f7f5e5961..cb48b4a8f85c 100644 --- a/MdePkg/Include/Library/PeCoffLib.h +++ b/MdePkg/Include/Library/PeCoffLib.h @@ -171,6 +171,10 @@ typedef struct { ///=0D UINT16 ImageType;=0D ///=0D + /// Set by PeCoffLoaderGetImageInfo() to the DLL flags stored in the PE/= COFF header.=0D + ///=0D + UINT16 DllCharacteristics;=0D + ///=0D /// Set by PeCoffLoaderGetImageInfo() to TRUE if the PE/COFF image does = not contain=0D /// relocation information.=0D ///=0D diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/Bas= ePeCoffLib/BasePeCoff.c index 31e1f2035963..fb6847e62a8d 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -308,10 +308,11 @@ PeCoffLoaderGetPeHeader ( //=0D // Use PE32 offset=0D //=0D - ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsyste= m;=0D - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeader.= SizeOfImage;=0D - ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.SectionA= lignment;=0D - ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOfHe= aders;=0D + ImageContext->ImageType =3D Hdr.Pe32->OptionalHeader.Subsys= tem;=0D + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32->OptionalHeade= r.SizeOfImage;=0D + ImageContext->SectionAlignment =3D Hdr.Pe32->OptionalHeader.Sectio= nAlignment;=0D + ImageContext->SizeOfHeaders =3D Hdr.Pe32->OptionalHeader.SizeOf= Headers;=0D + ImageContext->DllCharacteristics =3D Hdr.Pe32->OptionalHeader.DllCha= racteristics;=0D } else if (Hdr.Pe32->OptionalHeader.Magic =3D=3D EFI_IMAGE_NT_OPTIONAL= _HDR64_MAGIC) {=0D //=0D // 1. Check FileHeader.NumberOfRvaAndSizes filed.=0D @@ -429,10 +430,11 @@ PeCoffLoaderGetPeHeader ( //=0D // Use PE32+ offset=0D //=0D - ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Subs= ystem;=0D - ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalHea= der.SizeOfImage;=0D - ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Sect= ionAlignment;=0D - ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Size= OfHeaders;=0D + ImageContext->ImageType =3D Hdr.Pe32Plus->OptionalHeader.Su= bsystem;=0D + ImageContext->ImageSize =3D (UINT64)Hdr.Pe32Plus->OptionalH= eader.SizeOfImage;=0D + ImageContext->SectionAlignment =3D Hdr.Pe32Plus->OptionalHeader.Se= ctionAlignment;=0D + ImageContext->SizeOfHeaders =3D Hdr.Pe32Plus->OptionalHeader.Si= zeOfHeaders;=0D + ImageContext->DllCharacteristics =3D Hdr.Pe32Plus->OptionalHeader.Dl= lCharacteristics;=0D } else {=0D ImageContext->ImageError =3D IMAGE_ERROR_INVALID_MACHINE_TYPE;=0D return RETURN_UNSUPPORTED;=0D @@ -545,8 +547,9 @@ PeCoffLoaderGetPeHeader ( Retrieves information about a PE/COFF image.=0D =0D Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, Ima= geSize,=0D - DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders= , and=0D - DebugDirectoryEntryRva fields of the ImageContext structure.=0D + DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders= ,=0D + DllCharacteristics, and DebugDirectoryEntryRva fields of the ImageContex= t=0D + structure.=0D If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.=0D If the PE/COFF image accessed through the ImageRead service in the Image= Context=0D structure is not a supported PE/COFF image type, then return RETURN_UNSU= PPORTED.=0D --=20 2.39.2