]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
efi/x86: Memory protection on EfiGcdMemoryTypeMoreReliable
authorLenny Szubowicz <lszubowi@redhat.com>
Tue, 16 Sep 2025 19:38:53 +0000 (15:38 -0400)
committerArd Biesheuvel <ardb@kernel.org>
Mon, 29 Sep 2025 15:13:39 +0000 (17:13 +0200)
Check for needed memory protection changes on EFI DXE GCD memory space
descriptors with type EfiGcdMemoryTypeMoreReliable in addition to
EfiGcdMemoryTypeSystemMemory.

This fixes a fault on entry into the decompressed kernel from the
EFI stub that occurs when the memory allocated for the decompressed
kernel is more reliable memory, has NX/XP set, and the kernel needs
to use the EFI DXE protocol to adjust memory protections.

The memory descriptors returned by the DXE protocol
GetMemorySpaceDescriptor() service use a different GCD memory type
to distinguish more reliable memory ranges from their conventional
counterparts. This is in contrast to the EFI memory descriptors
returned by the EFI GetMemoryMap() service which use the
EFI_MEMORY_MORE_RELIABLE memory attributes flag to identify
EFI_CONVENTIONAL_MEMORY type regions that have this additional
property.

Signed-off-by: Lenny Szubowicz <lszubowi@redhat.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/x86-stub.c

index cafc90d4caafa6033a1b80f2d2b0a8893b60c2cd..0f60a12401c2c8daecb37623f927b3a0d20ccd73 100644 (file)
@@ -300,7 +300,7 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start,
                return EFI_SUCCESS;
 
        /*
-        * Don't modify memory region attributes, they are
+        * Don't modify memory region attributes, if they are
         * already suitable, to lower the possibility to
         * encounter firmware bugs.
         */
@@ -315,11 +315,13 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start,
                next = desc.base_address + desc.length;
 
                /*
-                * Only system memory is suitable for trampoline/kernel image placement,
-                * so only this type of memory needs its attributes to be modified.
+                * Only system memory and more reliable memory are suitable for
+                * trampoline/kernel image placement. So only those memory types
+                * may need to have attributes modified.
                 */
 
-               if (desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory ||
+               if ((desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory &&
+                    desc.gcd_memory_type != EfiGcdMemoryTypeMoreReliable) ||
                    (desc.attributes & (EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0)
                        continue;