Discussion:
[edk2] BUG in properties table feature implementation
Ard Biesheuvel
2015-06-29 10:46:08 UTC
Permalink
Hello all,

I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate
but adjacent memory regions, only to be able to assign different
permissions to .text and .data sections. This is working fine at boot
time.

However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between
code and data regions (of which the OS does not know whether they
belong together or not), reapplying the relocations corrupts the
memory image and breaks the runtime services.

For example, this region

0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]

is mapped on AARCH64 as

EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000

which retains the relative alignment, but adds a 64 KB offset to the
second regions so that the regions can still be mapped with different
permissions when the OS is executing with a 64 KB page size.

As far as I can tell, this is in accordance with the spec, and was
working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one
single PE/COFF image in memory, and the 64 KB offset results in the
relocations to be applied incorrectly.

I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5

I would also like to point out again that this is another result of
the fact that this series was pushed through with any review or
testing outside of the Intel firmware team. For features of this
magnitude and complexity, more scrutiny and testing is obviously
required.

Kind regards,
Ard.
Laszlo Ersek
2015-06-29 11:33:01 UTC
Permalink
Post by Ard Biesheuvel
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate
but adjacent memory regions, only to be able to assign different
permissions to .text and .data sections. This is working fine at boot
time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between
code and data regions (of which the OS does not know whether they
belong together or not), reapplying the relocations corrupts the
memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the
second regions so that the regions can still be mapped with different
permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was
working fine until I tried to enable the properties table feature.
Where / how? Did you enable it in the guest kernel (if that question
makes sense), or in the ArmVirtPkg build?

In the latter, I can only see the PropertiesTableEnable PCD, but (a) it
defaults to TRUE, (b) does it actually control the splitting?

Thanks
Laszlo
Post by Ard Biesheuvel
With that enabled, the two above regions could actually describe one
single PE/COFF image in memory, and the 64 KB offset results in the
relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of
the fact that this series was pushed through with any review or
testing outside of the Intel firmware team. For features of this
magnitude and complexity, more scrutiny and testing is obviously
required.
Kind regards,
Ard.
Ard Biesheuvel
2015-06-29 11:37:48 UTC
Permalink
Post by Laszlo Ersek
Post by Ard Biesheuvel
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate
but adjacent memory regions, only to be able to assign different
permissions to .text and .data sections. This is working fine at boot
time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between
code and data regions (of which the OS does not know whether they
belong together or not), reapplying the relocations corrupts the
memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the
second regions so that the regions can still be mapped with different
permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was
working fine until I tried to enable the properties table feature.
Where / how? Did you enable it in the guest kernel (if that question
makes sense), or in the ArmVirtPkg build?
No, I enabled it in the ArmVirtPkg.
Post by Laszlo Ersek
In the latter, I can only see the PropertiesTableEnable PCD, but (a) it
defaults to TRUE, (b) does it actually control the splitting?
Yes, it does. But it only works if
a) you are using a linker script that aligns the data section at 4 KB.
Otherwise, you get the runtime error message that you yourself
inquired about a couple of weeks ago, about the section alignment
being != 4 KB
b) EndOfDxe is being signalled correctly

So after putting all the pieces in place, the Linux AARCH64 kernel
boots, remaps the EFI runtime regions, and then crashes when trying to
read the EFI rtc, since the RealTimeClockRuntimeDxe is corrupted due
to the fact that its code and data regions are no longer mapped
adjacently.
--
Ard.
Post by Laszlo Ersek
Post by Ard Biesheuvel
With that enabled, the two above regions could actually describe one
single PE/COFF image in memory, and the 64 KB offset results in the
relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of
the fact that this series was pushed through with any review or
testing outside of the Intel firmware team. For features of this
magnitude and complexity, more scrutiny and testing is obviously
required.
Kind regards,
Ard.
Yao, Jiewen
2015-06-29 12:34:52 UTC
Permalink
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
We also tested Win10, and Suse 11 GM. They are good.

Would you please share the information on which OS you are using?

All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.

Thank you
Yao Jiewen


-----Original Message-----
From: Ard Biesheuvel [mailto:***@linaro.org]
Sent: Monday, June 29, 2015 6:46 PM
To: edk2-***@lists.sourceforge.net; Yao, Jiewen; Gao, Liming; Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation

Hello all,

I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.

However, at runtime, after calling virtual address map, this breaks down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.

For example, this region

0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]

is mapped on AARCH64 as

EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000

which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.

As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.

I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is not very obvious how to solve this. Obviously, our PE/COFF implementation is not complete since it assumes file offset == memory offset for sections, but this does not hold anymore for UEFI 2.5

I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.

Kind regards,
Ard.
Ard Biesheuvel
2015-06-29 12:44:23 UTC
Permalink
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it
cannot be trivially broken by a well-behaving OS. Note that nothing in
the SetVirtualAddressMap () implementation suggests that the regions
should be adjacent.

Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)

So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in
memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is not very obvious how to solve this. Obviously, our PE/COFF implementation is not complete since it assumes file offset == memory offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Yao, Jiewen
2015-06-29 12:54:56 UTC
Permalink
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.

Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.

UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.

So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.

That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
So in other word, it is disabled by tool by default. A platform may also decide to not publish PropertiesTable by below PCD:
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# If PropertiesTable has BIT0 set, DxeCore uses below policy in UEFI memory map:
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
# @Prompt Publish UEFI PropertiesTable.
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x0000006e

Thank you
Yao Jiewen


-----Original Message-----
From: Ard Biesheuvel [mailto:***@linaro.org]
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Cc: edk2-***@lists.sourceforge.net; Gao, Liming; Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5 system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.

Perhaps it would have been better to introduce a new memory region type EfiRuntimeServicesPecoffData, so the OS at least knows which regions it should keep adjacent, (i.e., Code and PecoffData regions should be kept together)

So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.

--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Ard Biesheuvel
2015-06-29 13:42:18 UTC
Permalink
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.
Yes, but I don't think it is documented anywhere that the OS needs to
map all runtime regions adjacently even if it does not actually care
about the EFI_MEMORY_RO attributes. Essentially, the OS always need to
map adjacently to be compatible with UEFI 2.5, and the current AArch64
Linux kernel crashes badly on any UEFI 2,5 implementation that has
this feature enabled.
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.
Unfortunately, this makes it an opt-in setting, and system will ship
with it disabled by default, in order to prevent boot failures on
older OSes. That is not typically how you want to deploy a security
feature.

There is another issue I would like your opinion about:
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the following

#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)

and in CoreTerminateMemoryMap(), a final check is done that no Runtime
regions are aligned incorrectly.
Yet, with the Properties Table feature enabled, memory regions are
split without taking this into account. Strangely enough,
CoreTerminateMemoryMap () does not complain about this.

This is documented in the UEFI spec 2.3.6:
"""
All 4KiB memory pages allocated for use by runtime services (of types
EfiRuntimeServicesCode, EfiRuntimeServicesData and
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as described in
Table 8) within the same physical 64KiB page. Mixed attribute mappings
within a larger page
are not allowed.
"""

So I suppose the Properties table feature should use 64 KB not 4 KB
when executing on AArch64. However, the documentation for the
Properties Table feature mentions 4 KB explicitly, so that should go
into the errata as well.


Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x0000006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5 system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.
Perhaps it would have been better to introduce a new memory region type EfiRuntimeServicesPecoffData, so the OS at least knows which regions it should keep adjacent, (i.e., Code and PecoffData regions should be kept together)
So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Yao, Jiewen
2015-06-29 13:58:51 UTC
Permalink
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section alignment for AArch64.

I confess that I only validated IA32 and X64, and I did not take AArch64 into account.

BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot find the word. So I just want to double confirm.

Thank you
Yao Jiewen

-----Original Message-----
From: Ard Biesheuvel [mailto:***@linaro.org]
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Cc: edk2-***@lists.sourceforge.net; Gao, Liming; Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.
Yes, but I don't think it is documented anywhere that the OS needs to map all runtime regions adjacently even if it does not actually care about the EFI_MEMORY_RO attributes. Essentially, the OS always need to map adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux kernel crashes badly on any UEFI 2,5 implementation that has this feature enabled.
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.
Unfortunately, this makes it an opt-in setting, and system will ship with it disabled by default, in order to prevent boot failures on older OSes. That is not typically how you want to deploy a security feature.

There is another issue I would like your opinion about:
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the following

#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)

and in CoreTerminateMemoryMap(), a final check is done that no Runtime regions are aligned incorrectly.
Yet, with the Properties Table feature enabled, memory regions are split without taking this into account. Strangely enough, CoreTerminateMemoryMap () does not complain about this.

This is documented in the UEFI spec 2.3.6:
"""
All 4KiB memory pages allocated for use by runtime services (of types EfiRuntimeServicesCode, EfiRuntimeServicesData and
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as described in Table 8) within the same physical 64KiB page. Mixed attribute mappings within a larger page are not allowed.
"""

So I suppose the Properties table feature should use 64 KB not 4 KB when executing on AArch64. However, the documentation for the Properties Table feature mentions 4 KB explicitly, so that should go into the errata as well.


Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x00
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Ard Biesheuvel
2015-06-29 14:05:37 UTC
Permalink
Post by Yao, Jiewen
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section alignment for AArch64.
I confess that I only validated IA32 and X64, and I did not take AArch64 into account.
BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot find the word. So I just want to double confirm.
No there is not. Only 64-bit ARM can execute with 64 KB page size.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.
Yes, but I don't think it is documented anywhere that the OS needs to map all runtime regions adjacently even if it does not actually care about the EFI_MEMORY_RO attributes. Essentially, the OS always need to map adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux kernel crashes badly on any UEFI 2,5 implementation that has this feature enabled.
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.
Unfortunately, this makes it an opt-in setting, and system will ship with it disabled by default, in order to prevent boot failures on older OSes. That is not typically how you want to deploy a security feature.
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the following
#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)
and in CoreTerminateMemoryMap(), a final check is done that no Runtime regions are aligned incorrectly.
Yet, with the Properties Table feature enabled, memory regions are split without taking this into account. Strangely enough, CoreTerminateMemoryMap () does not complain about this.
"""
All 4KiB memory pages allocated for use by runtime services (of types EfiRuntimeServicesCode, EfiRuntimeServicesData and
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as described in Table 8) within the same physical 64KiB page. Mixed attribute mappings within a larger page are not allowed.
"""
So I suppose the Properties table feature should use 64 KB not 4 KB when executing on AArch64. However, the documentation for the Properties Table feature mentions 4 KB explicitly, so that should go into the errata as well.
Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x00
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Yao, Jiewen
2015-06-29 14:08:27 UTC
Permalink
Good to know. Thanks!

-----Original Message-----
From: Ard Biesheuvel [mailto:***@linaro.org]
Sent: Monday, June 29, 2015 10:06 PM
To: Yao, Jiewen
Cc: edk2-***@lists.sourceforge.net; Gao, Liming; Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section alignment for AArch64.
I confess that I only validated IA32 and X64, and I did not take AArch64 into account.
BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot find the word. So I just want to double confirm.
No there is not. Only 64-bit ARM can execute with 64 KB page size.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.
Yes, but I don't think it is documented anywhere that the OS needs to map all runtime regions adjacently even if it does not actually care about the EFI_MEMORY_RO attributes. Essentially, the OS always need to map adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux kernel crashes badly on any UEFI 2,5 implementation that has this feature enabled.
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.
Unfortunately, this makes it an opt-in setting, and system will ship with it disabled by default, in order to prevent boot failures on older OSes. That is not typically how you want to deploy a security feature.
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the following
#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)
and in CoreTerminateMemoryMap(), a final check is done that no Runtime regions are aligned incorrectly.
Yet, with the Properties Table feature enabled, memory regions are split without taking this into account. Strangely enough, CoreTerminateMemoryMap () does not complain about this.
"""
All 4KiB memory pages allocated for use by runtime services (of types EfiRuntimeServicesCode, EfiRuntimeServicesData and
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as described in Table 8) within the same physical 64KiB page. Mixed attribute mappings within a larger page are not allowed.
"""
So I suppose the Properties table feature should use 64 KB not 4 KB when executing on AArch64. However, the documentation for the Properties Table feature mentions 4 KB explicitly, so that should go into the errata as well.
Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x00
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Ard Biesheuvel
2015-06-29 15:34:35 UTC
Permalink
Post by Yao, Jiewen
Good to know. Thanks!
Another question from my side: is it guaranteed the the memory map
returned by GetMemoryMap() is sorted?
Otherwise, it becomes non-trivial for the OS to ensure that all
Runtime regions are mapped adjacently.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 10:06 PM
To: Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section alignment for AArch64.
I confess that I only validated IA32 and X64, and I did not take AArch64 into account.
BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot find the word. So I just want to double confirm.
No there is not. Only 64-bit ARM can execute with 64 KB page size.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward compatibility.
Right, I do not think we can boot Win7 or old Win8 with this feature enabled.
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table feature. I believe it is known by UEFI forum, when it is added to UEFI spec, and it is published.
Yes, but I don't think it is documented anywhere that the OS needs to map all runtime regions adjacently even if it does not actually care about the EFI_MEMORY_RO attributes. Essentially, the OS always need to map adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux kernel crashes badly on any UEFI 2,5 implementation that has this feature enabled.
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or disabled.
The benefit of this feature is that: a UEFI2.5 OS can do memory protection based on UEFI memory map.
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI 2.5 OS availability.
Unfortunately, this makes it an opt-in setting, and system will ship with it disabled by default, in order to prevent boot failures on older OSes. That is not typically how you want to deploy a security feature.
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the following
#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)
and in CoreTerminateMemoryMap(), a final check is done that no Runtime regions are aligned incorrectly.
Yet, with the Properties Table feature enabled, memory regions are split without taking this into account. Strangely enough, CoreTerminateMemoryMap () does not complain about this.
"""
All 4KiB memory pages allocated for use by runtime services (of types EfiRuntimeServicesCode, EfiRuntimeServicesData and
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as described in Table 8) within the same physical 64KiB page. Mixed attribute mappings within a larger page are not allowed.
"""
So I suppose the Properties table feature should use 64 KB not 4 KB when executing on AArch64. However, the documentation for the Properties Table feature mentions 4 KB explicitly, so that should go into the errata as well.
Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as standard configuration.
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code section and
# use EfiRuntimeServicesData for runtime driver PE image header and other section.
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to be EFI_MEMORY_XP.
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform should set
# this PCD to be TURE if and only if all runtime driver has seperated Code/Data
# section. If PE code/data sections are merged, the result is unpredictable.
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN|0x00
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a distribution.
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it cannot be trivially broken by a well-behaving OS. Note that nothing in the SetVirtualAddressMap () implementation suggests that the regions should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file image? If so, the correct way is to update the PE/COFF loader and the relocation logic can deal with sections being laid out differently in memory than they are in the file.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but adjacent memory regions, only to be able to assign different permissions to .text and .data sections. This is working fine at boot time.
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency between code and data regions (of which the OS does not know whether they belong together or not), reapplying the relocations corrupts the memory image and breaks the runtime services.
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the second regions so that the regions can still be mapped with different permissions when the OS is executing with a 64 KB page size.
As far as I can tell, this is in accordance with the spec, and was working fine until I tried to enable the properties table feature.
With that enabled, the two above regions could actually describe one single PE/COFF image in memory, and the 64 KB offset results in the relocations to be applied incorrectly.
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact that this series was pushed through with any review or testing outside of the Intel firmware team. For features of this magnitude and complexity, more scrutiny and testing is obviously required.
Kind regards,
Ard.
Carsey, Jaben
2015-06-29 16:21:34 UTC
Permalink
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:35 AM
To: Yao, Jiewen
Subject: Re: [edk2] BUG in properties table feature implementation
Post by Yao, Jiewen
Good to know. Thanks!
Another question from my side: is it guaranteed the the memory map
returned by GetMemoryMap() is sorted?
Otherwise, it becomes non-trivial for the OS to ensure that all
Runtime regions are mapped adjacently.
I have seen lots of odd maps with the memmap shell command. I think that the answer is no as a result, but I'd like to know if someone knows for sure.
Post by Yao, Jiewen
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 10:06 PM
To: Yao, Jiewen
Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Post by Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section
alignment for AArch64.
Post by Yao, Jiewen
Post by Yao, Jiewen
I confess that I only validated IA32 and X64, and I did not take AArch64 into
account.
Post by Yao, Jiewen
Post by Yao, Jiewen
BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot
find the word. So I just want to double confirm.
Post by Yao, Jiewen
No there is not. Only 64-bit ARM can execute with 64 KB page size.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Post by Yao, Jiewen
Post by Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward
compatibility.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Right, I do not think we can boot Win7 or old Win8 with this feature
enabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table
feature. I believe it is known by UEFI forum, when it is added to UEFI spec,
and it is published.
Post by Yao, Jiewen
Post by Yao, Jiewen
Yes, but I don't think it is documented anywhere that the OS needs to map
all runtime regions adjacently even if it does not actually care about the
EFI_MEMORY_RO attributes. Essentially, the OS always need to map
adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux
kernel crashes badly on any UEFI 2,5 implementation that has this feature
enabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or
disabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
The benefit of this feature is that: a UEFI2.5 OS can do memory protection
based on UEFI memory map.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI
2.5 OS availability.
Post by Yao, Jiewen
Post by Yao, Jiewen
Unfortunately, this makes it an opt-in setting, and system will ship with it
disabled by default, in order to prevent boot failures on older OSes. That is
not typically how you want to deploy a security feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the
following
Post by Yao, Jiewen
Post by Yao, Jiewen
#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT
(SIZE_64KB)
Post by Yao, Jiewen
Post by Yao, Jiewen
and in CoreTerminateMemoryMap(), a final check is done that no Runtime
regions are aligned incorrectly.
Post by Yao, Jiewen
Post by Yao, Jiewen
Yet, with the Properties Table feature enabled, memory regions are split
without taking this into account. Strangely enough,
CoreTerminateMemoryMap () does not complain about this.
Post by Yao, Jiewen
Post by Yao, Jiewen
"""
All 4KiB memory pages allocated for use by runtime services (of types
EfiRuntimeServicesCode, EfiRuntimeServicesData and
Post by Yao, Jiewen
Post by Yao, Jiewen
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as
described in Table 8) within the same physical 64KiB page. Mixed attribute
mappings within a larger page are not allowed.
Post by Yao, Jiewen
Post by Yao, Jiewen
"""
So I suppose the Properties table feature should use 64 KB not 4 KB when
executing on AArch64. However, the documentation for the Properties Table
feature mentions 4 KB explicitly, so that should go into the errata as well.
Post by Yao, Jiewen
Post by Yao, Jiewen
Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as
standard configuration.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
So in other word, it is disabled by tool by default. A platform may also
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# If PropertiesTable has BIT0 set, DxeCore uses below policy in UEFI
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code
section and
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# use EfiRuntimeServicesData for runtime driver PE image header and
other section.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to
be EFI_MEMORY_XP.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform
should set
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# this PCD to be TURE if and only if all runtime driver has seperated
Code/Data
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# section. If PE code/data sections are merged, the result is
unpredictable.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN
|0x00
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old
Win7/Win8/Win8.1, and we have to disable it.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to
resolve this issue.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we
have to disable this feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
This is backwards: the feature should be implemented such that it cannot
be trivially broken by a well-behaving OS. Note that nothing in the
SetVirtualAddressMap () implementation suggests that the regions should be
adjacent.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in memory
than they are in the file.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but
adjacent memory regions, only to be able to assign different permissions to
.text and .data sections. This is working fine at boot time.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency
between code and data regions (of which the OS does not know whether
they belong together or not), reapplying the relocations corrupts the memory
image and breaks the runtime services.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the
second regions so that the regions can still be mapped with different
permissions when the OS is executing with a 64 KB page size.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
As far as I can tell, this is in accordance with the spec, and was working
fine until I tried to enable the properties table feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
With that enabled, the two above regions could actually describe one
single PE/COFF image in memory, and the 64 KB offset results in the
relocations to be applied incorrectly.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact
that this series was pushed through with any review or testing outside of the
Intel firmware team. For features of this magnitude and complexity, more
scrutiny and testing is obviously required.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Kind regards,
Ard.
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Ard Biesheuvel
2015-06-29 16:25:04 UTC
Permalink
Post by Carsey, Jaben
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:35 AM
To: Yao, Jiewen
Subject: Re: [edk2] BUG in properties table feature implementation
Post by Yao, Jiewen
Good to know. Thanks!
Another question from my side: is it guaranteed the the memory map
returned by GetMemoryMap() is sorted?
Otherwise, it becomes non-trivial for the OS to ensure that all
Runtime regions are mapped adjacently.
I have seen lots of odd maps with the memmap shell command. I think that the answer is no as a result, but I'd like to know if someone knows for sure.
Thanks. Obvious next question: how are those OSes supposed to ensure
that adjacent regions are mapped adjacently in the virtual mapping
then? AFAICT the only way to do this 100% reliably is to sort the
memory map first, and then go and find adjacent meta-regions, and keep
those together.
--
Ard.
Post by Carsey, Jaben
Post by Yao, Jiewen
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 10:06 PM
To: Yao, Jiewen
Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Post by Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Yes. It seems we need some special handling for AArch64.
If 64KiB is minimal paging unit, I think we need check 64KiB PE section
alignment for AArch64.
Post by Yao, Jiewen
Post by Yao, Jiewen
I confess that I only validated IA32 and X64, and I did not take AArch64 into
account.
Post by Yao, Jiewen
Post by Yao, Jiewen
BTW: There is no 64KiB alignment requirement for AArch32, right? I cannot
find the word. So I just want to double confirm.
Post by Yao, Jiewen
No there is not. Only 64-bit ARM can execute with 64 KB page size.
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 9:42 PM
To: Yao, Jiewen
Jordan L; Kinney, Michael D; Zeng, Star; Zimmer, Vincent; Fleming, Matt
Post by Yao, Jiewen
Post by Yao, Jiewen
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Thanks for the sharing. Yes. I agree with you that this breaks backward
compatibility.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Right, I do not think we can boot Win7 or old Win8 with this feature
enabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Both UEFI OS and Firmware need support this UEFI2.5 Properties Table
feature. I believe it is known by UEFI forum, when it is added to UEFI spec,
and it is published.
Post by Yao, Jiewen
Post by Yao, Jiewen
Yes, but I don't think it is documented anywhere that the OS needs to map
all runtime regions adjacently even if it does not actually care about the
EFI_MEMORY_RO attributes. Essentially, the OS always need to map
adjacently to be compatible with UEFI 2.5, and the current AArch64 Linux
kernel crashes badly on any UEFI 2,5 implementation that has this feature
enabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
UEFI 2.5 properties table is optional feature. It can be enabled or
disabled.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
The benefit of this feature is that: a UEFI2.5 OS can do memory protection
based on UEFI memory map.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
But the old UEFI OS cannot get any benefit.
So a platform can made judgment based on its need, as well as the UEFI
2.5 OS availability.
Post by Yao, Jiewen
Post by Yao, Jiewen
Unfortunately, this makes it an opt-in setting, and system will ship with it
disabled by default, in order to prevent boot failures on older OSes. That is
not typically how you want to deploy a security feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
for AArch64, MdeModulePkg/Core/Dxe/Mem/Imem.h defines the
following
Post by Yao, Jiewen
Post by Yao, Jiewen
#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT
(SIZE_64KB)
Post by Yao, Jiewen
Post by Yao, Jiewen
and in CoreTerminateMemoryMap(), a final check is done that no Runtime
regions are aligned incorrectly.
Post by Yao, Jiewen
Post by Yao, Jiewen
Yet, with the Properties Table feature enabled, memory regions are split
without taking this into account. Strangely enough,
CoreTerminateMemoryMap () does not complain about this.
Post by Yao, Jiewen
Post by Yao, Jiewen
"""
All 4KiB memory pages allocated for use by runtime services (of types
EfiRuntimeServicesCode, EfiRuntimeServicesData and
Post by Yao, Jiewen
Post by Yao, Jiewen
EfiACPIMemoryNVS) must use identical ARM Memory Page Attributes (as
described in Table 8) within the same physical 64KiB page. Mixed attribute
mappings within a larger page are not allowed.
Post by Yao, Jiewen
Post by Yao, Jiewen
"""
So I suppose the Properties table feature should use 64 KB not 4 KB when
executing on AArch64. However, the documentation for the Properties Table
feature mentions 4 KB explicitly, so that should go into the errata as well.
Post by Yao, Jiewen
Post by Yao, Jiewen
Regards,
Ard.
Post by Yao, Jiewen
That is why we do not enable this PE/COFF 4K alignment in BaseTool as
standard configuration.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
So in other word, it is disabled by tool by default. A platform may also
## Publish PropertiesTable or not.
#
# If this PCD is TRUE, DxeCore publishs PropertiesTable.
# DxeCore evaluates if all runtime drivers has 4K aligned PE sections. If all
# PE sections in runtime drivers are 4K aligned, DxeCore sets BIT0 in
# PropertiesTable. Or DxeCore clears BIT0 in PropertiesTable.
# If this PCD is FALSE, DxeCore does not publish PropertiesTable.
#
# If PropertiesTable has BIT0 set, DxeCore uses below policy in UEFI
# 1) Use EfiRuntimeServicesCode for runtime driver PE image code
section and
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# use EfiRuntimeServicesData for runtime driver PE image header and
other section.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# 2) Set EfiRuntimeServicesCode to be EFI_MEMORY_RO.
# 3) Set EfiRuntimeServicesData to be EFI_MEMORY_XP.
# 4) Set EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to
be EFI_MEMORY_XP.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
#
# NOTE: Platform need gurantee this PCD is set correctly. Platform
should set
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# this PCD to be TURE if and only if all runtime driver has seperated
Code/Data
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
# section. If PE code/data sections are merged, the result is
unpredictable.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
#
gEfiMdeModulePkgTokenSpaceGuid.PropertiesTableEnable|TRUE|BOOLEAN
|0x00
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
00006e
Thank you
Yao Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 8:44 PM
To: Yao, Jiewen
Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: Re: BUG in properties table feature implementation
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old
Win7/Win8/Win8.1, and we have to disable it.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to
resolve this issue.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is adjacent, we
have to disable this feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
This is backwards: the feature should be implemented such that it cannot
be trivially broken by a well-behaving OS. Note that nothing in the
SetVirtualAddressMap () implementation suggests that the regions should be
adjacent.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in memory
than they are in the file.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
--
Ard.
Post by Yao, Jiewen
-----Original Message-----
Sent: Monday, June 29, 2015 6:46 PM
Laszlo Ersek; Justen, Jordan L; Kinney, Michael D; Zeng, Star
Subject: BUG in properties table feature implementation
Hello all,
I am running into another problem with the implementation of the UEFI
2.5 Properties Table feature. It splits PE/COFF images into separate but
adjacent memory regions, only to be able to assign different permissions to
.text and .data sections. This is working fine at boot time.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
However, at runtime, after calling virtual address map, this breaks
down completely. Since the virtual mapping supplied to
SetVirtualAddressMap() does not have to guarantee adjacency
between code and data regions (of which the OS does not know whether
they belong together or not), reapplying the relocations corrupts the memory
image and breaks the runtime services.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
For example, this region
0x00005eeb1000-0x00005eeb6fff [Runtime Code]
0x00005eeb7000-0x00005eec0fff [Runtime Data]
is mapped on AARCH64 as
EFI remap 0x000000005eeb1000 => 00000000440a1000
EFI remap 0x000000005eeb7000 => 00000000440b7000
which retains the relative alignment, but adds a 64 KB offset to the
second regions so that the regions can still be mapped with different
permissions when the OS is executing with a 64 KB page size.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
As far as I can tell, this is in accordance with the spec, and was working
fine until I tried to enable the properties table feature.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
With that enabled, the two above regions could actually describe one
single PE/COFF image in memory, and the 64 KB offset results in the
relocations to be applied incorrectly.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
I looked at PeCoffLoaderRelocateImageForRuntime () but to me, it is
not very obvious how to solve this. Obviously, our PE/COFF
implementation is not complete since it assumes file offset == memory
offset for sections, but this does not hold anymore for UEFI 2.5
I would also like to point out again that this is another result of the fact
that this series was pushed through with any review or testing outside of the
Intel firmware team. For features of this magnitude and complexity, more
scrutiny and testing is obviously required.
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Post by Yao, Jiewen
Kind regards,
Ard.
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Laszlo Ersek
2015-06-29 13:06:32 UTC
Permalink
Post by Ard Biesheuvel
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
If the SUSE kernel is using a patch for this, then I hope it was at
least *submitted* to lkml / linux-efi?
Post by Ard Biesheuvel
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is
adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it
cannot be trivially broken by a well-behaving OS. Note that nothing in
the SetVirtualAddressMap () implementation suggests that the regions
should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in
memory than they are in the file.
I agree. If there's a new requirement on the OS or boot loader with
regard to mapping UEFI memmap ranges, that should be spelled out in the
UEFI spec.

I tried to check, and at the moment the UEFI spec seems neither buggy
nor theoretically impossible to implement in the firmware. If the spec
is deemed complete at this point, then the relocation logic needs
improvement.

I did see Matt's question in the mantis ticket
<https://mantis.uefi.org/mantis/view.php?id=1224>, and Vincent's answer
that a new whitepaper would be released. Still that doesn't substitute
for clarity in the spec, or more complete implementation, in my opinion.

In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).

Two more questions:
- what's the reason for "PropertiesTableEnable" being just a boolean
PCD, not a feature one? Is it expected to be set dynamically (perhaps
based on processor features)?
- shouldn't it be called *Pcd*PropertiesTableEnable?

Thanks
Laszlo
Yao, Jiewen
2015-06-29 13:22:12 UTC
Permalink
The white paper is @https://firmware.intel.com/sites/default/files/resources/A_Tour_Beyond_BIOS_Memory_Practices_with_UEFI.pdf
We documented the OS limitation, like Win8, and we hope future OS can resolve it. (So did Win10)
(We also listed some other potential limitation on PE/COFF image parsing in existing firmware.)

I agree that it is better idea to clearly document the requirement in UEFI spec.

Answer last 2 questions:
- what's the reason for "PropertiesTableEnable" being just a boolean PCD, not a feature one? Is it expected to be set dynamically (perhaps based on processor features)?
"Feature PCD" is fixed at build time. We thought it might be enable/disable via setup option, based on platform choice.
"PCD" means it can be configured as static (fixed at build time) or it can be configured as dynamic (updatable at runtime).

- shouldn't it be called *Pcd*PropertiesTableEnable?
Yes. It seems we forget to add *Pcd* keyword. Thanks!

Thank you
Yao Jiewen

-----Original Message-----
From: Laszlo Ersek [mailto:***@redhat.com]
Sent: Monday, June 29, 2015 9:07 PM
To: Ard Biesheuvel; Yao, Jiewen
Cc: edk2-***@lists.sourceforge.net; Gao, Liming; Justen, Jordan L; Kinney, Michael D; Zeng, Star; Fleming, Matt
Subject: Re: BUG in properties table feature implementation
Post by Ard Biesheuvel
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
If the SUSE kernel is using a patch for this, then I hope it was at least *submitted* to lkml / linux-efi?
Post by Ard Biesheuvel
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is
adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it
cannot be trivially broken by a well-behaving OS. Note that nothing in
the SetVirtualAddressMap () implementation suggests that the regions
should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in
memory than they are in the file.
I agree. If there's a new requirement on the OS or boot loader with regard to mapping UEFI memmap ranges, that should be spelled out in the UEFI spec.

I tried to check, and at the moment the UEFI spec seems neither buggy nor theoretically impossible to implement in the firmware. If the spec is deemed complete at this point, then the relocation logic needs improvement.

I did see Matt's question in the mantis ticket <https://mantis.uefi.org/mantis/view.php?id=1224>, and Vincent's answer that a new whitepaper would be released. Still that doesn't substitute for clarity in the spec, or more complete implementation, in my opinion.

In any case, for OVMF, I think we'll need a small patch that disables this feature (if for nothing else, then to quell the noisy warnings about "the section alignment being != 4 KB"). I'm adding that to my queue (but anyone please feel free to do it while I'm offline).

Two more questions:
- what's the reason for "PropertiesTableEnable" being just a boolean PCD, not a feature one? Is it expected to be set dynamically (perhaps based on processor features)?
- shouldn't it be called *Pcd*PropertiesTableEnable?

Thanks
Laszlo
Zimmer, Vincent
2015-06-29 13:35:52 UTC
Permalink
Yes. We have received feedback on lack of clarity regarding many memory attributes in the UEFI & PI spec (e.g., capability versus settings, etc). I'll work w/ the UEFI Forum to clarify in upcoming errata on those documents.
Vincent

-----Original Message-----
From: Yao, Jiewen [mailto:***@intel.com]
Sent: Monday, June 29, 2015 6:22 AM
To: Laszlo Ersek; Ard Biesheuvel
Cc: Fleming, Matt; edk2-***@lists.sourceforge.net
Subject: Re: [edk2] BUG in properties table feature implementation

The white paper is @https://firmware.intel.com/sites/default/files/resources/A_Tour_Beyond_BIOS_Memory_Practices_with_UEFI.pdf
We documented the OS limitation, like Win8, and we hope future OS can resolve it. (So did Win10) (We also listed some other potential limitation on PE/COFF image parsing in existing firmware.)

I agree that it is better idea to clearly document the requirement in UEFI spec.

Answer last 2 questions:
- what's the reason for "PropertiesTableEnable" being just a boolean PCD, not a feature one? Is it expected to be set dynamically (perhaps based on processor features)?
"Feature PCD" is fixed at build time. We thought it might be enable/disable via setup option, based on platform choice.
"PCD" means it can be configured as static (fixed at build time) or it can be configured as dynamic (updatable at runtime).

- shouldn't it be called *Pcd*PropertiesTableEnable?
Yes. It seems we forget to add *Pcd* keyword. Thanks!

Thank you
Yao Jiewen

-----Original Message-----
From: Laszlo Ersek [mailto:***@redhat.com]
Sent: Monday, June 29, 2015 9:07 PM
To: Ard Biesheuvel; Yao, Jiewen
Cc: edk2-***@lists.sourceforge.net; Gao, Liming; Justen, Jordan L; Kinney, Michael D; Zeng, Star; Fleming, Matt
Subject: Re: BUG in properties table feature implementation
Post by Ard Biesheuvel
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
If the SUSE kernel is using a patch for this, then I hope it was at least *submitted* to lkml / linux-efi?
Post by Ard Biesheuvel
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is
adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it
cannot be trivially broken by a well-behaving OS. Note that nothing in
the SetVirtualAddressMap () implementation suggests that the regions
should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in
memory than they are in the file.
I agree. If there's a new requirement on the OS or boot loader with regard to mapping UEFI memmap ranges, that should be spelled out in the UEFI spec.

I tried to check, and at the moment the UEFI spec seems neither buggy nor theoretically impossible to implement in the firmware. If the spec is deemed complete at this point, then the relocation logic needs improvement.

I did see Matt's question in the mantis ticket <https://mantis.uefi.org/mantis/view.php?id=1224>, and Vincent's answer that a new whitepaper would be released. Still that doesn't substitute for clarity in the spec, or more complete implementation, in my opinion.

In any case, for OVMF, I think we'll need a small patch that disables this feature (if for nothing else, then to quell the noisy warnings about "the section alignment being != 4 KB"). I'm adding that to my queue (but anyone please feel free to do it while I'm offline).

Two more questions:
- what's the reason for "PropertiesTableEnable" being just a boolean PCD, not a feature one? Is it expected to be set dynamically (perhaps based on processor features)?
- shouldn't it be called *Pcd*PropertiesTableEnable?

Thanks
Laszlo
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors network devices and physical & virtual servers, alerts via email & sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Ard Biesheuvel
2015-06-29 14:16:19 UTC
Permalink
Post by Laszlo Ersek
Post by Ard Biesheuvel
Post by Yao, Jiewen
Hi Ard
Yes, your are right. We do observe similar odd behavior in old Win7/Win8/Win8.1, and we have to disable it.
Win8 and Win8.1 have OS patch to set adjacent virtual memory map, to resolve this issue.
I see this as a big problem with the feature, as it breaks backward
compatibility. IOW, you won't be able to boot Windows 7 on a UEFI 2.5
system unless you manually disable the feature (in the setup screen, I
suppose?)
Post by Yao, Jiewen
We also tested Win10, and Suse 11 GM. They are good.
Would you please share the information on which OS you are using?
I am using the upstream Linux kernel for AArch64. I am not using a
distribution.
If the SUSE kernel is using a patch for this, then I hope it was at
least *submitted* to lkml / linux-efi?
Not needed, probably. AArch64 is the only arch that remaps the EFI
memory regions with a 64 KB alignment, which is what causes the issue.
'Suse 11 GM' most likely means the x86_64 version.
Post by Laszlo Ersek
Post by Ard Biesheuvel
Post by Yao, Jiewen
All in all, if OS cannot guarantee the virtual memory map is
adjacent, we have to disable this feature.
This is backwards: the feature should be implemented such that it
cannot be trivially broken by a well-behaving OS. Note that nothing in
the SetVirtualAddressMap () implementation suggests that the regions
should be adjacent.
Perhaps it would have been better to introduce a new memory region
type EfiRuntimeServicesPecoffData, so the OS at least knows which
regions it should keep adjacent, (i.e., Code and PecoffData regions
should be kept together)
So does PE/COFF even allow the memory image to deviate from the file
image? If so, the correct way is to update the PE/COFF loader and the
relocation logic can deal with sections being laid out differently in
memory than they are in the file.
I agree. If there's a new requirement on the OS or boot loader with
regard to mapping UEFI memmap ranges, that should be spelled out in the
UEFI spec.
I tried to check, and at the moment the UEFI spec seems neither buggy
nor theoretically impossible to implement in the firmware. If the spec
is deemed complete at this point, then the relocation logic needs
improvement.
Well, it turns out (after looking at the PE/COFF spec), that a
section's offset with respect to ImageBase is not expected to change.
This means obviously that the relative offset between any two sections
is expected to remain the same as well.

Whether this would still allow a hack to work around it is anyone's
guess: my assessment for AArch64 would be that (since we are using the
large model, which makes all external references absolute), it would
be possible to move the .data section away from the .text section and
reapply the relocations with different adjustment values for each of
them. But not a road we want to go down, I suppose.

It would be nice if we could use old style mappings with the new style
feature enabled: now the PE/COFF images are just spread out over code
and data sections, and any information that they belong together is
lost. In my opinion (which is offered after the fact, of course),
retaining the 'code' region for the entire PE/COFF image, with some
annotation that marks it as a PE/COFF .text region followed by a date
region would have been friendlier to older OSes. That still doesn't
solve the problem how to pass the information about which subregion
can be mapped RO and which XP
--
Ard.
Post by Laszlo Ersek
I did see Matt's question in the mantis ticket
<https://mantis.uefi.org/mantis/view.php?id=1224>, and Vincent's answer
that a new whitepaper would be released. Still that doesn't substitute
for clarity in the spec, or more complete implementation, in my opinion.
In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).
- what's the reason for "PropertiesTableEnable" being just a boolean
PCD, not a feature one? Is it expected to be set dynamically (perhaps
based on processor features)?
- shouldn't it be called *Pcd*PropertiesTableEnable?
Thanks
Laszlo
Matt Fleming
2015-06-29 15:09:52 UTC
Permalink
Post by Laszlo Ersek
In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).
Is there any chance that we could wire up support in OVMF? What work is
required to support it?
--
Matt Fleming, Intel Open Source Technology Center
Ard Biesheuvel
2015-06-29 15:12:08 UTC
Permalink
Post by Matt Fleming
Post by Laszlo Ersek
In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).
Is there any chance that we could wire up support in OVMF? What work is
required to support it?
I think it would be fairly easy, actually, once Laszlo manages to
untangle the S3Save mess so that OVMF signals EndOfDxe correctly.
Then, it is mainly a matter of using the new build script that emits 4
KB aligned segments for .text and .data
--
Ard.
Ard Biesheuvel
2015-06-29 18:10:22 UTC
Permalink
Post by Ard Biesheuvel
Post by Matt Fleming
Post by Laszlo Ersek
In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).
Is there any chance that we could wire up support in OVMF? What work is
required to support it?
I think it would be fairly easy, actually, once Laszlo manages to
untangle the S3Save mess so that OVMF signals EndOfDxe correctly.
Then, it is mainly a matter of using the new build script that emits 4
KB aligned segments for .text and .data
This seems to do the job nicely:

----------8<------------
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index e5fc90d2e610..7f06b51f65cf 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -48,6 +48,9 @@ [BuildOptions]
INTEL:*_*_X64_GENFW_FLAGS = --keepexceptiontable
!endif

+[BuildOptions.X64.EDKII.DXE_RUNTIME_DRIVER]
+ GCC:*_*_*_DLINK_FLAGS =
--script=$(EDK_TOOLS_PATH)/Scripts/gcc-4K-align-ld-script
+
################################################################################
#
# SKU Identification section - list of all SKU IDs supported by this Platform.
----------8<------------

$ readelf -S Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb/DEBUG/EmuVariableFvbRuntimeDxe.dll

Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 1] .text PROGBITS 0000000000001000 00001000
0000000000004780 0000000000000000 AX 0 0 4096
...
[ 3] .data PROGBITS 0000000000006000 00006000
0000000000002740 0000000000000000 WA 0 0 4096
...


With Laszlo's 9 piece series applied to ensure that end of DXE gets
signalled, UEFI seems to do the right thing here. Here's a snippet of
my boot log (x86_64)

[ 0.000000] efi: mem22: type=6, attr=0x800000000000400f,
range=[0x0000000006daa000-0x0000000006db1000) (0MB)
[ 0.000000] efi: mem23: type=5, attr=0x800000000002000f,
range=[0x0000000006db1000-0x0000000006db6000) (0MB)
[ 0.000000] efi: mem24: type=6, attr=0x800000000000400f,
range=[0x0000000006db6000-0x0000000006dc0000) (0MB)
[ 0.000000] efi: mem25: type=6, attr=0x800000000000400f,
range=[0x0000000006dc0000-0x0000000006dc1000) (0MB)
[ 0.000000] efi: mem26: type=5, attr=0x800000000002000f,
range=[0x0000000006dc1000-0x0000000006dc5000) (0MB)
[ 0.000000] efi: mem27: type=6, attr=0x800000000000400f,
range=[0x0000000006dc5000-0x0000000006dce000) (0MB)
[ 0.000000] efi: mem28: type=6, attr=0x800000000000400f,
range=[0x0000000006dce000-0x0000000006dcf000) (0MB)
[ 0.000000] efi: mem29: type=5, attr=0x800000000002000f,
range=[0x0000000006dcf000-0x0000000006dd5000) (0MB)
[ 0.000000] efi: mem30: type=6, attr=0x800000000000400f,
range=[0x0000000006dd5000-0x0000000006e02000) (0MB)
[ 0.000000] efi: mem31: type=6, attr=0x800000000000400f,
range=[0x0000000006e02000-0x0000000006e03000) (0MB)
[ 0.000000] efi: mem32: type=5, attr=0x800000000002000f,
range=[0x0000000006e03000-0x0000000006e12000) (0MB)
[ 0.000000] efi: mem33: type=6, attr=0x800000000000400f,
range=[0x0000000006e12000-0x0000000006e1a000) (0MB)

so code and data regions are correctly marked as RO and XP, respectively.

However, further down I get

[ 0.034428] BUG: unable to handle kernel paging request at fffffffefe60d64d
[ 0.036000] IP: [<fffffffefe60d64d>] 0xfffffffefe60d64d
[ 0.036000] PGD 4c11067 PUD 601b063 PMD 6028063 PTE 0
[ 0.036000] Oops: 0010 [#1] SMP
[ 0.036000] Modules linked in:
[ 0.036000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted
3.13.0-55-generic #94-Ubuntu
[ 0.036000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS 0.0.0 02/06/2015
[ 0.036000] task: ffffffff81c15480 ti: ffffffff81c00000 task.ti:
ffffffff81c00000
[ 0.036000] RIP: 0010:[<fffffffefe60d64d>] [<fffffffefe60d64d>]
0xfffffffefe60d64d
[ 0.036000] RSP: 0000:ffffffff81c01d48 EFLAGS: 00000202
[ 0.036000] RAX: fffffffefe60d64d RBX: ffffffffffffffff RCX: ffffffff81c396e0
[ 0.036000] RDX: ffffffff81c01f00 RSI: ffffffff81c396e0 RDI: fffffffefe40a957
[ 0.036000] RBP: ffffffff81c01e00 R08: 0000000000000007 R09: 0000000000000000
[ 0.036000] R10: ffffea0000180e00 R11: ffffffff81d51ce0 R12: ffffffff81c01f00
[ 0.036000] R13: 0000000000000000 R14: 0000000000000007 R15: 000000000009c000
[ 0.036000] FS: 0000000000000000(0000) GS:ffff880006600000(0000)
knlGS:0000000000000000
[ 0.036000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 0.036000] CR2: fffffffefe60d64d CR3: 000000000009c000 CR4: 00000000000006b0
[ 0.036000] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 0.036000] DR3: 0000000000000000 DR6: 0000000000000000 DR7: 0000000000000000
[ 0.036000] Stack:
[ 0.036000] fffffffefe40aa08 ffffffff81c01da0 0000000007eb3893
0000000006db7000
[ 0.036000] 0000000006db7000 0000000006dba000 0000000007eed090
0000000000000078
[ 0.036000] 752ea16d07eede98 ffffffff81c01de0 0000000007eb3800
0000000007eed018
[ 0.036000] Call Trace:
[ 0.036000] [<ffffffff810624f1>] efi_call5+0x71/0xf0
[ 0.036000] [<ffffffff81061879>] ? virt_efi_set_variable+0x49/0x60
[ 0.036000] [<ffffffff81d51d4c>] efi_enter_virtual_mode+0x2fe/0x332
[ 0.036000] [<ffffffff81d34edc>] start_kernel+0x3a4/0x443
[ 0.036000] [<ffffffff81d34941>] ? repair_env_string+0x5c/0x5c
[ 0.036000] [<ffffffff81d34120>] ? early_idt_handlers+0x120/0x120
[ 0.036000] [<ffffffff81d345ee>] x86_64_start_reservations+0x2a/0x2c
[ 0.036000] [<ffffffff81d34733>] x86_64_start_kernel+0x143/0x152
[ 0.036000] Code: Bad RIP value.
[ 0.036000] RIP [<fffffffefe60d64d>] 0xfffffffefe60d64d
[ 0.036000] RSP <ffffffff81c01d48>
[ 0.036000] CR2: fffffffefe60d64d
[ 0.036000] ---[ end trace acf85ef8d4475d7c ]---
--
Ard.
Laszlo Ersek
2015-07-14 18:03:17 UTC
Permalink
Post by Ard Biesheuvel
Post by Ard Biesheuvel
Post by Matt Fleming
Post by Laszlo Ersek
In any case, for OVMF, I think we'll need a small patch that disables
this feature (if for nothing else, then to quell the noisy warnings
about "the section alignment being != 4 KB"). I'm adding that to my
queue (but anyone please feel free to do it while I'm offline).
Is there any chance that we could wire up support in OVMF? What work is
required to support it?
I think it would be fairly easy, actually, once Laszlo manages to
untangle the S3Save mess so that OVMF signals EndOfDxe correctly.
Then, it is mainly a matter of using the new build script that emits 4
KB aligned segments for .text and .data
----------8<------------
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index e5fc90d2e610..7f06b51f65cf 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -48,6 +48,9 @@ [BuildOptions]
INTEL:*_*_X64_GENFW_FLAGS = --keepexceptiontable
!endif
+[BuildOptions.X64.EDKII.DXE_RUNTIME_DRIVER]
+ GCC:*_*_*_DLINK_FLAGS =
--script=$(EDK_TOOLS_PATH)/Scripts/gcc-4K-align-ld-script
+
################################################################################
#
# SKU Identification section - list of all SKU IDs supported by this Platform.
----------8<------------
$ readelf -S Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb/DEBUG/EmuVariableFvbRuntimeDxe.dll
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 1] .text PROGBITS 0000000000001000 00001000
0000000000004780 0000000000000000 AX 0 0 4096
...
[ 3] .data PROGBITS 0000000000006000 00006000
0000000000002740 0000000000000000 WA 0 0 4096
...
With Laszlo's 9 piece series applied to ensure that end of DXE gets
signalled, UEFI seems to do the right thing here. Here's a snippet of
my boot log (x86_64)
[ 0.000000] efi: mem22: type=6, attr=0x800000000000400f,
range=[0x0000000006daa000-0x0000000006db1000) (0MB)
[ 0.000000] efi: mem23: type=5, attr=0x800000000002000f,
range=[0x0000000006db1000-0x0000000006db6000) (0MB)
[ 0.000000] efi: mem24: type=6, attr=0x800000000000400f,
range=[0x0000000006db6000-0x0000000006dc0000) (0MB)
[ 0.000000] efi: mem25: type=6, attr=0x800000000000400f,
range=[0x0000000006dc0000-0x0000000006dc1000) (0MB)
[ 0.000000] efi: mem26: type=5, attr=0x800000000002000f,
range=[0x0000000006dc1000-0x0000000006dc5000) (0MB)
[ 0.000000] efi: mem27: type=6, attr=0x800000000000400f,
range=[0x0000000006dc5000-0x0000000006dce000) (0MB)
[ 0.000000] efi: mem28: type=6, attr=0x800000000000400f,
range=[0x0000000006dce000-0x0000000006dcf000) (0MB)
[ 0.000000] efi: mem29: type=5, attr=0x800000000002000f,
range=[0x0000000006dcf000-0x0000000006dd5000) (0MB)
[ 0.000000] efi: mem30: type=6, attr=0x800000000000400f,
range=[0x0000000006dd5000-0x0000000006e02000) (0MB)
[ 0.000000] efi: mem31: type=6, attr=0x800000000000400f,
range=[0x0000000006e02000-0x0000000006e03000) (0MB)
[ 0.000000] efi: mem32: type=5, attr=0x800000000002000f,
range=[0x0000000006e03000-0x0000000006e12000) (0MB)
[ 0.000000] efi: mem33: type=6, attr=0x800000000000400f,
range=[0x0000000006e12000-0x0000000006e1a000) (0MB)
so code and data regions are correctly marked as RO and XP, respectively.
However, further down I get
[ 0.034428] BUG: unable to handle kernel paging request at fffffffefe60d64d
[ 0.036000] IP: [<fffffffefe60d64d>] 0xfffffffefe60d64d
[ 0.036000] PGD 4c11067 PUD 601b063 PMD 6028063 PTE 0
[ 0.036000] Oops: 0010 [#1] SMP
[ 0.036000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted
3.13.0-55-generic #94-Ubuntu
[ 0.036000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS 0.0.0 02/06/2015
ffffffff81c00000
[ 0.036000] RIP: 0010:[<fffffffefe60d64d>] [<fffffffefe60d64d>]
0xfffffffefe60d64d
[ 0.036000] RSP: 0000:ffffffff81c01d48 EFLAGS: 00000202
[ 0.036000] RAX: fffffffefe60d64d RBX: ffffffffffffffff RCX: ffffffff81c396e0
[ 0.036000] RDX: ffffffff81c01f00 RSI: ffffffff81c396e0 RDI: fffffffefe40a957
[ 0.036000] RBP: ffffffff81c01e00 R08: 0000000000000007 R09: 0000000000000000
[ 0.036000] R10: ffffea0000180e00 R11: ffffffff81d51ce0 R12: ffffffff81c01f00
[ 0.036000] R13: 0000000000000000 R14: 0000000000000007 R15: 000000000009c000
[ 0.036000] FS: 0000000000000000(0000) GS:ffff880006600000(0000)
knlGS:0000000000000000
[ 0.036000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 0.036000] CR2: fffffffefe60d64d CR3: 000000000009c000 CR4: 00000000000006b0
[ 0.036000] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 0.036000] DR3: 0000000000000000 DR6: 0000000000000000 DR7: 0000000000000000
[ 0.036000] fffffffefe40aa08 ffffffff81c01da0 0000000007eb3893
0000000006db7000
[ 0.036000] 0000000006db7000 0000000006dba000 0000000007eed090
0000000000000078
[ 0.036000] 752ea16d07eede98 ffffffff81c01de0 0000000007eb3800
0000000007eed018
[ 0.036000] [<ffffffff810624f1>] efi_call5+0x71/0xf0
[ 0.036000] [<ffffffff81061879>] ? virt_efi_set_variable+0x49/0x60
[ 0.036000] [<ffffffff81d51d4c>] efi_enter_virtual_mode+0x2fe/0x332
[ 0.036000] [<ffffffff81d34edc>] start_kernel+0x3a4/0x443
[ 0.036000] [<ffffffff81d34941>] ? repair_env_string+0x5c/0x5c
[ 0.036000] [<ffffffff81d34120>] ? early_idt_handlers+0x120/0x120
[ 0.036000] [<ffffffff81d345ee>] x86_64_start_reservations+0x2a/0x2c
[ 0.036000] [<ffffffff81d34733>] x86_64_start_kernel+0x143/0x152
[ 0.036000] Code: Bad RIP value.
[ 0.036000] RIP [<fffffffefe60d64d>] 0xfffffffefe60d64d
[ 0.036000] RSP <ffffffff81c01d48>
[ 0.036000] CR2: fffffffefe60d64d
[ 0.036000] ---[ end trace acf85ef8d4475d7c ]---
Right. Therefore, even though my new patch series

[PATCH v2 0/6] OvmfPkg: save S3 state at EndOfDxe

is on the list now, and your small patch above, applied on top, could
enable the feature for OVMF, I'd like it to be disabled by default.

There's a number of users employing OVMF with Windows 7 for GPU
passthru, for example.

A nice solution could be:
- apply my series named above (well, obviously, whatever you want to
do, you must commit my pending patches first! ;> )

- invent a new fw_cfg file name, and payload, that puts Gabriel's
recent QEMU feature to use:

81b2b810 "fw_cfg: insert fw_cfg file blobs via qemu cmdline"

Preferably, document this new file somewhere (outside of QEMU?)

- in PlatformPei, check this fw_cfg file, and set
PcdPropertiesTableEnable to TRUE dynamically. (Example:
SmbiosVersionInitialization().) That would be early enough for the
DXE core too see the fresh value.

- Submit Ard's patch re 4K alignment in the linker script for real.

Patches welcome. :)

Thanks
Laszlo

Continue reading on narkive:
Loading...