x86: Put trampoline in separate .init.trampoline section
PATCH v2 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).
Changes since v1:
- remove useless align.
--- xen/arch/x86/boot/head.S | 5 +++-- xen/arch/x86/xen.lds.S | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +3 -2
@@ -882,8 +882,9 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" +#include "x86_64.S" + + .section .init.trampoline, "aw", @progbits ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end) - -#include "x86_64.S"
xen/arch/x86/xen.lds.S +5 -0
@@ -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
xen/arch/x86/boot/head.S cmdline_parse_early: · line 890
Quoted 12 lines · Frediano Ziglio
xen/arch/x86/boot/head.S +3
-0@@ -882,8 +882,9 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" +#include "x86_64.S" + + .section .init.trampoline, "aw", @progbits ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end)
Hmm, nice - this turns out rather easier than I first thought.
xen/arch/x86/xen.lds.S SECTIONS · line 272
Quoted 7 lines
xen/arch/x86/xen.lds.S +1
-0@@ -269,6 +269,11 @@ SECTIONS __ctors_end = .; } PHDR(text) + . = ALIGN(PAGE_SIZE);
Why? There's no special alignment right now.
xen/arch/x86/xen.lds.S SECTIONS · line 277
Quoted 5 lines
xen/arch/x86/xen.lds.S +4
-0+ DECL_SECTION(.init.trampoline) { + *(.init.trampoline) + } PHDR(text) + #ifndef EFI
If this is to be a separate section also for ELF, I think that wants mentioning explicitly. "Easily disassemble" is too vague a reason for my taste.
Jan
Quoted 23 lines · Jan Beulich
xen/arch/x86/boot/head.S cmdline_parse_early: · line 890
Quoted 12 lines · Frediano Ziglio
xen/arch/x86/boot/head.S +3
-0@@ -882,8 +882,9 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" +#include "x86_64.S" + + .section .init.trampoline, "aw", @progbits ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end)Hmm, nice - this turns out rather easier than I first thought.
Quoted 6 lines
xen/arch/x86/xen.lds.S +0
-0@@ -269,6 +269,11 @@ SECTIONS __ctors_end = .; } PHDR(text)
Quoted 4 lines
xen/arch/x86/xen.lds.S SECTIONS · line 272
Quoted 1 line
xen/arch/x86/xen.lds.S +1
-0+ . = ALIGN(PAGE_SIZE);Why? There's no special alignment right now.
UEFI CA Memory Mitigation requirements, I'll remove from this commit.
Quoted 9 lines
xen/arch/x86/xen.lds.S SECTIONS · line 277
Quoted 5 lines
xen/arch/x86/xen.lds.S +4
-0+ DECL_SECTION(.init.trampoline) { + *(.init.trampoline) + } PHDR(text) + #ifndef EFIIf this is to be a separate section also for ELF, I think that wants mentioning explicitly. "Easily disassemble" is too vague a reason for my taste.
It's not clear if either you changed your mind on that reason or if the commit message is not clear. I'm assuming the latter, I'll improve the commit message.
Not clear why you specify "ELF" in the above sentence, I mean, why should it matter if it applies to EFI and/or ELF? And why having it different from ELF to EFI?
Quoted 2 lines
Jan
Frediano
Quoted 12 lines · Frediano Ziglio
Quoted 10 lines · Jan Beulich
xen/arch/x86/xen.lds.S SECTIONS · line 277
Quoted 5 lines · Frediano Ziglio
xen/arch/x86/xen.lds.S +4
-0+ DECL_SECTION(.init.trampoline) { + *(.init.trampoline) + } PHDR(text) + #ifndef EFIIf this is to be a separate section also for ELF, I think that wants mentioning explicitly. "Easily disassemble" is too vague a reason for my taste.
Quoted 6 lines
It's not clear if either you changed your mind on that reason or if the commit message is not clear. I'm assuming the latter, I'll improve the commit message.
Not clear why you specify "ELF" in the above sentence, I mean, why should it matter if it applies to EFI and/or ELF? And why having it different from ELF to EFI?
Why do we fold sections at all? We could keep them all separate, leading to a big section table with -f{function,data}-sections. If you want to change something, you need to clarify why the change is being made, for every part that is affected. We don't have a need for the separate section in ELF, so it becoming one without at least saying so (and ideally also why) it might look like an oversight / mistake to someone later stumbling across that commit.
Jan