diff mbox series

[v2,10/11] x86/efi: do not merge all .init sections

Message ID 20250401130840.72119-11-roger.pau@citrix.com (mailing list archive)
State New
Headers show
Series x86/EFI: prevent write-execute sections | expand

Commit Message

Roger Pau Monne April 1, 2025, 1:08 p.m. UTC
As a result of having no relocations against text sections, there's no need
for a single .init section that's read-write-execute, as .init.text is no
longer modified.

Remove the bodge and fallback to the layout used by ELF images with an
.init.text and .init.data section.

The resulting PE sections are:

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00193f6b  ffff82d040200000  ffff82d040200000  00000480  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .rodata       0008a010  ffff82d040400000  ffff82d040400000  00194400  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .buildid      00000035  ffff82d04048a010  ffff82d04048a010  0021e420  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .init.text    00049e70  ffff82d040600000  ffff82d040600000  0021e460  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .init.data    000560a8  ffff82d040800000  ffff82d040800000  002682e0  2**2
                  CONTENTS, ALLOC, LOAD, DATA
[...]

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v1:
 - Align .init.text.
 - Clarify commit message.
---
 xen/arch/x86/xen.lds.S | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Jan Beulich April 2, 2025, 10:28 a.m. UTC | #1
On 01.04.2025 15:08, Roger Pau Monne wrote:
> @@ -218,12 +214,15 @@ SECTIONS
>          */
>         *(.altinstr_replacement)
>  
> -#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
> -       . = ALIGN(SMP_CACHE_BYTES);
> -#else
>    } PHDR(text)
> -  DECL_SECTION(.init.data) {
> +#ifdef EFI
> +  /*
> +   * Align to prevent the data section from re-using the tail of an RX mapping
> +   * from the previous text section.
> +   */
> +  . = ALIGN(SECTION_ALIGN);

Does this need to be SECTION_ALIGN, growing image size by perhaps more than
1Mb (at least that's what I expect as an effect)? Wouldn't PAGE_SIZE suffice
for our purposes?

Jan

>  #endif
> +  DECL_SECTION(.init.data) {
>         *(.init.bss.stack_aligned)
>  
>         . = ALIGN(POINTER_ALIGN);
diff mbox series

Patch

diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 1191bf4e2ddd..852aa135a76c 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -201,11 +201,7 @@  SECTIONS
   __2M_init_start = .;         /* Start of 2M superpages, mapped RWX (boot only). */
   . = ALIGN(PAGE_SIZE);             /* Init code and data */
   __init_begin = .;
-#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
-  DECL_SECTION(.init) {
-#else
   DECL_SECTION(.init.text) {
-#endif
        _sinittext = .;
        *(.init.text)
        *(.text.startup)
@@ -218,12 +214,15 @@  SECTIONS
         */
        *(.altinstr_replacement)
 
-#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
-       . = ALIGN(SMP_CACHE_BYTES);
-#else
   } PHDR(text)
-  DECL_SECTION(.init.data) {
+#ifdef EFI
+  /*
+   * Align to prevent the data section from re-using the tail of an RX mapping
+   * from the previous text section.
+   */
+  . = ALIGN(SECTION_ALIGN);
 #endif
+  DECL_SECTION(.init.data) {
        *(.init.bss.stack_aligned)
 
        . = ALIGN(POINTER_ALIGN);