From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 77123D806D5 for ; Mon, 11 Mar 2024 21:29:30 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=hNVA+A9VAFg4leLtdkFenqbxRhWn9yQkmkdsApNSLCk=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1710192569; v=1; b=nOVWGCK2PeB35HqDwHdPQJM+ueuuDWfGAH8JknYLOAqotG3msiqJfvceGOsy6ThIUn6Ev8l3 nRz+iIm9wuZjKpkwQaYZdRoYU6o7lslbWtt5hyqd8JDH0oGBKUUNs+7/LVB8e5jMpmnZRhcIiOb 2Ft6n3gidnKJ7mGDFSDesHIumjyxRPFokpuqBfs8KMDu3O9Os3/3eb2qNTmQlutGrGUwKo7Qy9x YBwowu5jdCS4GWBi3QCkH4KXa4VZ5eRCJB8oCSoECh7CDMKMGnUi2uAk4Fo4PW/kCahTeM3a4SB OR5lBjO1g85fUcl27JBuFX4moOZOYXO4uML0Y/JJYzNAA== X-Received: by 127.0.0.2 with SMTP id D5EUYY7687511xpYYd8428qY; Mon, 11 Mar 2024 14:29:29 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.5296.1710192567111608073 for ; Mon, 11 Mar 2024 14:29:27 -0700 X-Received: from OSD-Desktop.redmond.corp.microsoft.com (unknown [131.107.160.171]) by linux.microsoft.com (Postfix) with ESMTPSA id 64F3020B74C2; Mon, 11 Mar 2024 14:29:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 64F3020B74C2 From: "Oliver Smith-Denny" To: devel@edk2.groups.io Cc: Liming Gao , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Taylor Beebe Subject: [edk2-devel] [PATCH v2 1/3] MdeModulePkg: ImagePropertiesRecordLib: Use SectionAlignment for CodeSize Date: Mon, 11 Mar 2024 14:29:22 -0700 Message-Id: <20240311212924.11633-2-osde@linux.microsoft.com> In-Reply-To: <20240311212924.11633-1-osde@linux.microsoft.com> References: <20240311212924.11633-1-osde@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Mon, 11 Mar 2024 14:29:27 -0700 Reply-To: devel@edk2.groups.io,osde@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: RiYXELFPEievb4QhrLz4LgvHx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=nOVWGCK2; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.com (policy=none) When an ImageRecord is stored by ImagePropertiesRecordLib, it reports the CodeSegmentSize as the SizeOfRawData from the image. However, the image as loaded into memory is aligned to the SectionAlignment, so SizeOfRawData is under the actual size in memory. This is important, because the memory attributes table uses these image records to create its entries and it will report that the alignment of an image is incorrect, even though the actual image is correct. This was discovered on ARM64, which has a 64k runtime page granularity alignment, which is backed by a 64k section alignment for DXE_RUNTIME_DRIVERs. The runtime code and data was correctly being loaded into memory, however the memory attribute table was incorrectly reporting misaligned ranges to the OS, causing attributes to be ignored for these sections for OSes using greater than 4k pages. This patch correctly aligns the CodeSegmentSize to the SectionAlignment and the corresponding memory attribute table entries are now correctly aligned and pointing to the right places in memory. Cc: Liming Gao Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Taylor Beebe Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c= | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertie= sRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropert= iesRecordLib.c index e53ce086c54c..763a8d65d565 100644 --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecord= Lib.c +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecord= Lib.c @@ -1090,7 +1090,9 @@ CreateImagePropertiesRecord ( ImageRecordCodeSection->Signature =3D IMAGE_PROPERTIES_RECORD_CODE= _SECTION_SIGNATURE; =20 ImageRecordCodeSection->CodeSegmentBase =3D (UINTN)ImageBase + Sec= tion[Index].VirtualAddress; - ImageRecordCodeSection->CodeSegmentSize =3D Section[Index].SizeOfR= awData; + // We still need to align the VirtualSize to the SectionAlignment = because MSVC does not do + // this when creating a PE image. It expects the loader to do this= . + ImageRecordCodeSection->CodeSegmentSize =3D ALIGN_VALUE (Section[I= ndex].Misc.VirtualSize, SectionAlignment); =20 InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSec= tion->Link); ImageRecord->CodeSegmentCount++; --=20 2.40.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116659): https://edk2.groups.io/g/devel/message/116659 Mute This Topic: https://groups.io/mt/104873193/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-