summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith-Denny <osde@linux.microsoft.com>2024-03-29 13:21:27 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-03-29 23:56:16 +0000
commit1fb6462c67912aa287a6f431475cece2659383b7 (patch)
treef7380ae893949a708f27775518fcfbf61d91e9f8
parent7fde22823d64cb7b9f2a65bb87ffb7581f5ff84e (diff)
downloadedk2-1fb6462c67912aa287a6f431475cece2659383b7.tar.gz
edk2-1fb6462c67912aa287a6f431475cece2659383b7.tar.bz2
edk2-1fb6462c67912aa287a6f431475cece2659383b7.zip
MdeModulePkg: ImagePropertiesRecordLib: Use SectionAlignment for CodeSize
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 <gaoliming@byosoft.com.cn> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Taylor Beebe <taylor.d.beebe@gmail.com> Acked-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Marvin H?user <mhaeuser@posteo.de> Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
-rw-r--r--MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
index e53ce086c5..763a8d65d5 100644
--- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
+++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c
@@ -1090,7 +1090,9 @@ CreateImagePropertiesRecord (
ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE;
ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageBase + Section[Index].VirtualAddress;
- ImageRecordCodeSection->CodeSegmentSize = Section[Index].SizeOfRawData;
+ // 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 = ALIGN_VALUE (Section[Index].Misc.VirtualSize, SectionAlignment);
InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSection->Link);
ImageRecord->CodeSegmentCount++;