Skip to content

Commit 99da5bf

Browse files
LennySzubowiczardbiesheuvel
authored andcommitted
efi/x86: Memory protection on EfiGcdMemoryTypeMoreReliable
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 <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 05e75ac commit 99da5bf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start,
300300
return EFI_SUCCESS;
301301

302302
/*
303-
* Don't modify memory region attributes, they are
303+
* Don't modify memory region attributes, if they are
304304
* already suitable, to lower the possibility to
305305
* encounter firmware bugs.
306306
*/
@@ -315,11 +315,13 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start,
315315
next = desc.base_address + desc.length;
316316

317317
/*
318-
* Only system memory is suitable for trampoline/kernel image placement,
319-
* so only this type of memory needs its attributes to be modified.
318+
* Only system memory and more reliable memory are suitable for
319+
* trampoline/kernel image placement. So only those memory types
320+
* may need to have attributes modified.
320321
*/
321322

322-
if (desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory ||
323+
if ((desc.gcd_memory_type != EfiGcdMemoryTypeSystemMemory &&
324+
desc.gcd_memory_type != EfiGcdMemoryTypeMoreReliable) ||
323325
(desc.attributes & (EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0)
324326
continue;
325327

0 commit comments

Comments
 (0)