Skip to contentSkip to conversation

x86: Put trampoline in separate .init.trampoline section

PATCH Superseded Frediano Ziglio 1 participant 1 message Sep 11, 2024

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Put trampoline in separate .init.trampoline section

This change put the trampoline in a separate, not executable section. The trampoline contains a mix of code and data (data which is modified from C code during early start so must be writable). This is in preparation for W^X patch in order to satisfy UEFI CA memory mitigation requirements.
At the moment .init.text and .init.data in EFI mode are put together so they will be in the same final section as before this patch. Putting in a separate section (even in final executables) allows to easily disassembly that section.

---
Changes since last version:
- use completely separate section even on final executables (suggested by Jan Beulich).

---
 xen/arch/x86/boot/head.S | 6 ++++--
 xen/arch/x86/xen.lds.S   | 5 +++++
 2 files changed, 9 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +4 -2
index 12bbb97f33..61b7b8894c 100644
@@ -882,8 +882,10 @@ cmdline_parse_early:
 reloc:
         .incbin "reloc.bin"
 
+#include "x86_64.S"
+
+        .section .init.trampoline, "aw", @progbits
+        .align 4
 ENTRY(trampoline_start)
 #include "trampoline.S"
 ENTRY(trampoline_end)
-
-#include "x86_64.S"
xen/arch/x86/xen.lds.S +5 -0
index d48de67cfd..390870e463 100644
@@ -269,6 +269,11 @@ SECTIONS
        __ctors_end = .;
   } PHDR(text)
 
+  . = ALIGN(PAGE_SIZE);
+  DECL_SECTION(.init.trampoline) {
+       *(.init.trampoline)
+  } PHDR(text)
+
 #ifndef EFI
   /*
    * With --orphan-sections=warn (or =error) we need to handle certain linker
Signature · 1 line
2.34.1