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 8E1B6740035 for ; Fri, 1 Mar 2024 11:58:57 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=31C5Vw9J9u/wwfYDChykUu1ctCTOnUsmrAyZwIELrvs=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1709294336; v=1; b=urvuTRt3LTvHWFXpyljxV0L5WEwwoAhMvhqijVIHUqx4JZr0DBLkooqydcUNjS49QgyhbqDG 1ObtHyYrS+E8UCOHVDPBSSrRmbtgr3wJ0TTae4f/9CCxSVpf5j74zm+ExrDZ/A2A5FsRQKzK1k0 7zYy2Y56BM0xHZ7E+eVjV+eo= X-Received: by 127.0.0.2 with SMTP id kftAYY7687511xGHxGwOWVHm; Fri, 01 Mar 2024 03:58:56 -0800 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.20845.1709294335377395848 for ; Fri, 01 Mar 2024 03:58:55 -0800 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BB1196100F for ; Fri, 1 Mar 2024 11:58:54 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D75DC43390 for ; Fri, 1 Mar 2024 11:58:54 +0000 (UTC) X-Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d29aad15a5so23094061fa.3 for ; Fri, 01 Mar 2024 03:58:54 -0800 (PST) X-Gm-Message-State: ns3Gcinz3bcNLEuyXoCN4xadx7686176AA= X-Google-Smtp-Source: AGHT+IHa5ee1T/wkNiSVp2GAyEaQMWK8BCVhjov+YYXO4x52LhmLTqK3oZVN9yHZAlLpUuXrcK5MVuPQ9B1lzmn2CS0= X-Received: by 2002:a2e:a409:0:b0:2d3:4bef:45fd with SMTP id p9-20020a2ea409000000b002d34bef45fdmr416697ljn.33.1709294332667; Fri, 01 Mar 2024 03:58:52 -0800 (PST) MIME-Version: 1.0 References: <20240227202721.30070-1-osde@linux.microsoft.com> <20240227202721.30070-2-osde@linux.microsoft.com> In-Reply-To: <20240227202721.30070-2-osde@linux.microsoft.com> From: "Ard Biesheuvel" Date: Fri, 1 Mar 2024 12:58:40 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel][PATCH v1 1/3] MdeModulePkg: ImagePropertiesRecordLib: Use SectionAlignment for CodeSize To: Oliver Smith-Denny Cc: devel@edk2.groups.io, Liming Gao , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Taylor Beebe 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 Reply-To: devel@edk2.groups.io,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=urvuTRt3; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Hi Oliver, On Tue, 27 Feb 2024 at 21:27, Oliver Smith-Denny wrote: > > 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. > Can you explain how these can differ in the first place? Our flaky ELF-to-PE/COFF converter should never generate such images to begin with (which is probably how we ended up with this problem in the first place), so I suppose this is native PE/COFF tooling emitting sections either using a non-1:1 file:memory mapping, or with unallocated holes in the file representation? > 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 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > index e53ce086c54c..07ced0e54e38 100644 > --- a/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > +++ b/MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.c > @@ -1090,7 +1090,7 @@ CreateImagePropertiesRecord ( > ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE; > > ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageBase + Section[Index].VirtualAddress; > - ImageRecordCodeSection->CodeSegmentSize = Section[Index].SizeOfRawData; > + ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE (Section[Index].SizeOfRawData, SectionAlignment); > This should be the virtual size, not the file size, right? > InsertTailList (&ImageRecord->CodeSegmentList, &ImageRecordCodeSection->Link); > ImageRecord->CodeSegmentCount++; > -- > 2.40.1 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116237): https://edk2.groups.io/g/devel/message/116237 Mute This Topic: https://groups.io/mt/104610770/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-