Commit cad27ef2 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Catalin Marinas

arm64: efi: split Image code and data into separate PE/COFF sections

To prevent unintended modifications to the kernel text (malicious or
otherwise) while running the EFI stub, describe the kernel image as
two separate sections: a .text section with read-execute permissions,
covering .text, .rodata and .init.text, and a .data section with
read-write permissions, covering .init.data, .data and .bss.

This relies on the firmware to actually take the section permission
flags into account, but this is something that is currently being
implemented in EDK2, which means we will likely start seeing it in
the wild between one and two years from now.
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent f1eb542f
...@@ -27,8 +27,8 @@ optional_header: ...@@ -27,8 +27,8 @@ optional_header:
.short PE_OPT_MAGIC_PE32PLUS // PE32+ format .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
.byte 0x02 // MajorLinkerVersion .byte 0x02 // MajorLinkerVersion
.byte 0x14 // MinorLinkerVersion .byte 0x14 // MinorLinkerVersion
.long _end - efi_header_end // SizeOfCode .long __initdata_begin - efi_header_end // SizeOfCode
.long 0 // SizeOfInitializedData .long __pecoff_data_size // SizeOfInitializedData
.long 0 // SizeOfUninitializedData .long 0 // SizeOfUninitializedData
.long __efistub_entry - _head // AddressOfEntryPoint .long __efistub_entry - _head // AddressOfEntryPoint
.long efi_header_end - _head // BaseOfCode .long efi_header_end - _head // BaseOfCode
...@@ -74,9 +74,9 @@ extra_header_fields: ...@@ -74,9 +74,9 @@ extra_header_fields:
// Section table // Section table
section_table: section_table:
.ascii ".text\0\0\0" .ascii ".text\0\0\0"
.long _end - efi_header_end // VirtualSize .long __initdata_begin - efi_header_end // VirtualSize
.long efi_header_end - _head // VirtualAddress .long efi_header_end - _head // VirtualAddress
.long _edata - efi_header_end // SizeOfRawData .long __initdata_begin - efi_header_end // SizeOfRawData
.long efi_header_end - _head // PointerToRawData .long efi_header_end - _head // PointerToRawData
.long 0 // PointerToRelocations .long 0 // PointerToRelocations
...@@ -84,7 +84,20 @@ section_table: ...@@ -84,7 +84,20 @@ section_table:
.short 0 // NumberOfRelocations .short 0 // NumberOfRelocations
.short 0 // NumberOfLineNumbers .short 0 // NumberOfLineNumbers
.long IMAGE_SCN_CNT_CODE | \ .long IMAGE_SCN_CNT_CODE | \
IMAGE_SCN_MEM_EXECUTE | \ IMAGE_SCN_MEM_READ | \
IMAGE_SCN_MEM_EXECUTE // Characteristics
.ascii ".data\0\0\0"
.long __pecoff_data_size // VirtualSize
.long __initdata_begin - _head // VirtualAddress
.long __pecoff_data_rawsize // SizeOfRawData
.long __initdata_begin - _head // PointerToRawData
.long 0 // PointerToRelocations
.long 0 // PointerToLineNumbers
.short 0 // NumberOfRelocations
.short 0 // NumberOfLineNumbers
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
IMAGE_SCN_MEM_READ | \ IMAGE_SCN_MEM_READ | \
IMAGE_SCN_MEM_WRITE // Characteristics IMAGE_SCN_MEM_WRITE // Characteristics
......
...@@ -213,6 +213,7 @@ SECTIONS ...@@ -213,6 +213,7 @@ SECTIONS
} }
PECOFF_EDATA_PADDING PECOFF_EDATA_PADDING
__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
_edata = .; _edata = .;
BSS_SECTION(0, 0, 0) BSS_SECTION(0, 0, 0)
...@@ -228,6 +229,7 @@ SECTIONS ...@@ -228,6 +229,7 @@ SECTIONS
. += RESERVED_TTBR0_SIZE; . += RESERVED_TTBR0_SIZE;
#endif #endif
__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
_end = .; _end = .;
STABS_DEBUG STABS_DEBUG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment