From nobody Mon Sep 16 19:05:28 2024 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+101133+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+101133+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1678727932; cv=none; d=zohomail.com; s=zohoarc; b=ZExQrBtlB3Dviq287HtBG6ZDOSVFgA1Tgu/BW9vSGliowj3kJza2kD+QHwPlHgpufCKchJOKntD50cUT8yLBxDbReExOn7rhXArIUwho4Tgnto9UpZ+WWr/X8T8bo8uswuOEyaK57WFX+TyPvZ29gM5jZVelUat1k6FZ19M8soA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678727932; 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=oWXhRDu8Pi7FFjkhtq0gI9DJ6G4Yh+zh8IM2z1Agtu0=; b=RZGRaJrvZ+zdniEW4CcETqgT2+CwUM/a5BTR4gv67j165wX/nA0RziNoxA3kOqSD+vNFqlUG6yuC7JwkILKxvG6tNJ3zP62WoHaHLyJLEnq/AaP+LXZBzdtDxIQ9ODoQmGjUDtFf/lmo1i1enDDPACMGChCfOZ9ri5H1xrW4DcM= 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+101133+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 16787279322023.9855745670611213; Mon, 13 Mar 2023 10:18:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vNF6YY1788612xyKwQa9x2YU; Mon, 13 Mar 2023 10:18:51 -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.26509.1678727931289257805 for ; Mon, 13 Mar 2023 10:18:51 -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 CD69D61365; Mon, 13 Mar 2023 17:18:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D0C4C4339B; Mon, 13 Mar 2023 17:18:47 +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 Subject: [edk2-devel] [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> In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-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: le3wzFRP8V5bMowzzzMqtwRbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678727931; bh=gvxd86qxAP6IoxB2orbgAV+Qc+2jiwIquUgtV0ewy8E=; h=Cc:Date:From:Reply-To:Subject:To; b=ppIbkjoNITpLR589eZUtmckNwaOPFLDiHm6UDWVHmtoqkjTZ/eXcXNkFSCfuZMAHKaX lGJ7tPw4HapJTHyBB7FgugOQkX17MsvsHChqj8sVtXPkCnq7hMlJuS9JxRhtgH0A52Llg KZTFpRiPqfb2aGW78m1/ukJg4apE2pSM/xk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678727934457100002 Content-Type: text/plain; charset="utf-8" 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 { /// UINT16 ImageType; /// + /// Set by PeCoffLoaderGetImageInfo() to the DLL flags stored in the PE/= COFF header. + /// + UINT16 DllCharacteristics; + /// /// 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 31e1f2035963..fb6847e62a8d 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, and DebugDirectoryEntryRva fields 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. --=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 (#101133): https://edk2.groups.io/g/devel/message/101133 Mute This Topic: https://groups.io/mt/97586040/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-