Skip to contentSkip to conversation

Various patches to improve Secure Boot support

PATCH In review Frediano Ziglio 3 participants 16 messages Jul 15 – Nov 17

lore
Share & tools
lore
#0 lore raw

v8 cover Various patches to improve Secure Boot support

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Frediano Ziglio (2):
Align relevant sections to 4KB
x86: Split .init section to satisfy UEFI CA memory mitigation

Roger Pau Monné (2):
x86/efi: discard multiboot and PVH support for PE binary x86/efi: avoid a relocation in efi_arch_post_exit_boot()

 docs/hypervisor-guide/x86/how-xen-boots.rst |  6 -----
 xen/arch/x86/boot/head.S                    |  8 +++----
 xen/arch/x86/efi/efi-boot.h                 |  7 ++++--
 xen/arch/x86/xen.lds.S                      | 25 ++++++++++++---------
 xen/tools/combine_two_binaries.py           |  2 +-
 5 files changed, 25 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v8 1/4 Align relevant sections to 4KB

Required by UEFI CA memory mitigation.

It is a requirement for NX_COMPAT so the PE can be loaded with W^X perms in the pagetables.

NX_COMPAT is a requirement from shim-review,
https://github.com/rhboot/shim-review#do-you-have-the-nx-bit-set-in-your-shim-if-so-is-your-entire-boot-stack-nx-compatible-and-what-testing-have-you-done-to-ensure-such-compatibility

Sections with different permissions must be in separate pages. In the case of debug sections they are contiguous and have the same permissions, including the immediately preceding .reloc section, so it's not an issue if they are not aligned to the page.
Before the .debug sections you could have the .reloc or the SBAT section, either are permission-compatible.

---
Changes since v1:
- Change subject.

Changes since v2:
- Improved commit message and subject.

Changes since v3:
- Added Acked-by;
- Improved commit message.

Changes since v4:
- Added missing comment;
- Added Acked-by.

---
 xen/arch/x86/xen.lds.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
xen/arch/x86/xen.lds.S +4 -2
index b9e888e596..8e63cf5bc2 100644
@@ -162,8 +162,8 @@ SECTIONS
        __note_gnu_build_id_end = .;
   } PHDR(note) PHDR(text)
 #elif defined(BUILD_ID_EFI)
-  /* Workaround bug in binutils < 2.36 */
-  . = ALIGN(32);
+  /* Align to satisfy UEFI CA memory mitigation. */
+  . = ALIGN(PAGE_SIZE);
   DECL_SECTION(.buildid) {
        __note_gnu_build_id_start = .;
        *(.buildid)
@@ -330,6 +330,8 @@ SECTIONS
   __2M_rwdata_end = ALIGN(SECTION_ALIGN);
 
 #ifdef EFI
+  /* Align to satisfy UEFI CA memory mitigation. */
+  . = ALIGN(PAGE_SIZE);
   .reloc ALIGN(4) : {
     __base_relocs_start = .;
     *(.reloc)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v8 2/4 x86/efi: discard multiboot and PVH support for PE binary

In reply to Frediano Ziglio

From: Roger Pau Monné <[email protected]>

Multiboot and PVH booting are not supported for PE, hence discards them in the linker script when doing a PE build.

That removes some relocations that otherwise appear due to the usage of the start and __efi64_mb2_start symbols in the multiboot2 header.

Section discarding is not done updating DISCARD_SECTIONS definition as the change is specific for x86.

No functional change intended.

---
Changes since v1:
- improve commit message;
- change section orders to avoid changing code order in final executable;
- merge 2 commits;
- removed deprecated documentation section.

Changes since v2:
- Update commit message, join 2 sentences together.

Changes since v3:
- Added Acked-by.

Changes since v4:
- more clear subject;
- removed more code/data from EFI output;
- removed Acked-by.

Changes since v5:
- simplify section exclusion using more wildcard;
- exclude more multiboot functions.

Changes since v7:
- added Reviewed-by.

Changes since v8:
- added Acked-by.

---
 docs/hypervisor-guide/x86/how-xen-boots.rst | 6 ------
 xen/arch/x86/boot/head.S                    | 8 ++++----
 xen/arch/x86/xen.lds.S                      | 7 +++++++
 xen/tools/combine_two_binaries.py           | 2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)
docs/hypervisor-guide/x86/how-xen-boots.rst +0 -6
index 8b3229005c..b6d852050a 100644
@@ -82,12 +82,6 @@ When a PEI-capable toolchain is found, the objects are linked together and a
 PE32+ binary is created.  It can be run directly from the EFI shell, and has
 ``efi_start`` as its entry symbol.
 
-.. note::
-
-   xen.efi does contain all MB1/MB2/PVH tags included in the rest of the
-   build.  However, entry via anything other than the EFI64 protocol is
-   unsupported, and won't work.
-
 
 Boot
 ----
xen/arch/x86/boot/head.S +4 -4
index 68b963ce6f..981f262b5e 100644
@@ -126,7 +126,7 @@ multiboot2_header:
         .size multiboot2_header, . - multiboot2_header
         .type multiboot2_header, @object
 
-        .section .init.rodata, "a", @progbits
+        .section .init.rodata.multiboot, "a", @progbits
 
 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
 .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
@@ -137,8 +137,7 @@ multiboot2_header:
 .Lno_nx_msg:   .asciz "ERR: Not an NX-capable CPU!"
 #endif
 
-        .section .init.data, "aw", @progbits
-        .subsection 1 /* Put data here after the page tables (in x86_64.S). */
+        .section .init.data.multiboot, "aw", @progbits
         .align 4
 
         .word   0
@@ -154,7 +153,7 @@ vga_text_buffer:
 efi_platform:
         .byte   0
 
-        .section .init.text, "ax", @progbits
+        .section .init.multiboot, "ax", @progbits
 
 early_error: /* Here to improve the disassembly. */
 
@@ -712,6 +711,7 @@ trampoline_setup:
         /* Jump into the relocated trampoline. */
         lret
 
+        .section .init.text, "ax", @progbits
 ENTRY(trampoline_start)
 #include "trampoline.S"
 ENTRY(trampoline_end)
xen/arch/x86/xen.lds.S +7 -0
index 8e63cf5bc2..4ed1d2bec1 100644
@@ -57,6 +57,10 @@ SECTIONS
   __image_base__ = .;
 #else
   . = __image_base__;
+  /DISCARD/ : {
+    *(.text.header)
+    *(.init.*multiboot)
+  }
 #endif
 
 #if 0
@@ -195,6 +199,7 @@ SECTIONS
   DECL_SECTION(.init.text) {
 #endif
        _sinittext = .;
+       *(.init.multiboot)
        *(.init.text)
        *(.text.startup)
        _einittext = .;
@@ -220,6 +225,7 @@ SECTIONS
        *(.init.rodata.cf_clobber)
        __initdata_cf_clobber_end = .;
 
+       *(.init.rodata.multiboot)
        *(.init.rodata)
        *(.init.rodata.*)
 
@@ -234,6 +240,7 @@ SECTIONS
        *(.initcall1.init)
        __initcall_end = .;
 
+       *(.init.data.multiboot)
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
xen/tools/combine_two_binaries.py +1 -1
index 581e57cbc0..5f0433dcad 100755
@@ -33,7 +33,7 @@ parser.add_argument('--map', dest='mapfile',
 parser.add_argument('--exports', dest='exports',
                     help='Symbols to export')
 parser.add_argument('--section-header', dest='section_header',
-                    default='.section .init.text, "ax", @progbits',
+                    default='.section .init.multiboot, "ax", @progbits',
                     help='Section header declaration')
 parser.add_argument('-v', '--verbose',
                     action='store_true')
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v8 2/4] x86/efi: discard multiboot and PVH support for PE binary

xen/arch/x86/xen.lds.S SECTIONS · line 64

Quoted 11 lines · Frediano Ziglio
xen/arch/x86/xen.lds.S +4 -0
@@ -57,6 +57,10 @@ SECTIONS
   __image_base__ = .;
 #else
   . = __image_base__;
+  /DISCARD/ : {
+    *(.text.header)
+    *(.init.*multiboot)
+  }
 #endif

This has caused fallout: GNU ld 2.47 now warns (once per .xen.efi.[012])

ld: .xen.efi.<N>: stripping non-representable symbol 'start_pa' (value 0x7d2fc0000000)

This is because "start", from which "start_pa" is derived, has disappeared with the discarding of .text.header.

Question is why we (still) have "start_pa" in xen.efi: I can't spot any reference. The sole reference is xen-syms' entry point. The patch below addresses this, but I wonder whether I overlook anything.

Jan

x86: restrict start_pa to xen.gz

With "start" (living in .text.header) now being discarded, "start_pa" obtains a bogus value (which also cannot be represented in the COFF symbol table). As the symbol is solely used for xen.gz's entry point, limit its definition to the non-EFI linking process.

Fixes 9f8ebe9f46ce ("x86/efi: Discard multiboot and PVH entrypoints in xen.efi")
xen/arch/x86/xen.lds.S +1 -2
@@ -55,6 +55,7 @@ SECTIONS
 #if !defined(EFI)
   . = __XEN_VIRT_START;
   __image_base__ = .;
+  start_pa = ABSOLUTE(start - __XEN_VIRT_START);
 #else
   . = __image_base__;
   /DISCARD/ : {
@@ -74,8 +75,6 @@ SECTIONS
   __2M_text_start = .;         /* Start of 2M superpages, mapped RX. */
 #endif
 
-  start_pa = ABSOLUTE(start - __XEN_VIRT_START);
-
   . = __XEN_VIRT_START + XEN_IMG_OFFSET;
   _start = .;
   DECL_SECTION(.text) {
Reviewed-by
#4 lore raw

Re: [PATCH v8 2/4] x86/efi: discard multiboot and PVH support for PE binary

Quoted 14 lines · Jan Beulich

xen/arch/x86/xen.lds.S SECTIONS · line 64

Quoted 11 lines · Frediano Ziglio
xen/arch/x86/xen.lds.S +4 -0
@@ -57,6 +57,10 @@ SECTIONS
   __image_base__ = .;
 #else
   . = __image_base__;
+  /DISCARD/ : {
+    *(.text.header)
+    *(.init.*multiboot)
+  }
 #endif

This has caused fallout: GNU ld 2.47 now warns (once per .xen.efi.[012])

Quoted 4 lines

ld: .xen.efi.<N>: stripping non-representable symbol 'start_pa' (value 0x7d2fc0000000)

This is because "start", from which "start_pa" is derived, has disappeared with the discarding of .text.header.

Oh.  I'd found this, but wrongly attributed it to a different part of the series and left it on the todo list.

Quoted 4 lines

Question is why we (still) have "start_pa" in xen.efi: I can't spot any reference. The sole reference is xen-syms' entry point. The patch below addresses this, but I wonder whether I overlook anything.

0b280404c84

It looks as if it should have been ELF-only all along.

I have to admit that I can't quite remember why we have this, but that it was part of making shim function.  Nov 2017 was from the point in time where we had no viable Meltdown solution other than shim-ing all PV guests.

Quoted 8 lines

Jan

x86: restrict start_pa to xen.gz

With "start" (living in .text.header) now being discarded, "start_pa" obtains a bogus value (which also cannot be represented in the COFF symbol table). As the symbol is solely used for xen.gz's entry point,

xen-syms.

xen.gz does not contain xen-syms's e_entry.  It is set to loadbase from the mkelf32 command line.

Quoted 4 lines

limit its definition to the non-EFI linking process.

Fixes 9f8ebe9f46ce ("x86/efi: Discard multiboot and PVH entrypoints in xen.efi")

With the commit message adjusted, and probably an extra fixes tag,

Quoted 21 lines
xen/arch/x86/xen.lds.S +1 -2
@@ -55,6 +55,7 @@ SECTIONS
 #if !defined(EFI)
   . = __XEN_VIRT_START;
   __image_base__ = .;
+  start_pa = ABSOLUTE(start - __XEN_VIRT_START);
 #else
   . = __image_base__;
   /DISCARD/ : {
@@ -74,8 +75,6 @@ SECTIONS
   __2M_text_start = .;         /* Start of 2M superpages, mapped RX. */
 #endif
 
-  start_pa = ABSOLUTE(start - __XEN_VIRT_START);
-
   . = __XEN_VIRT_START + XEN_IMG_OFFSET;
   _start = .;
   DECL_SECTION(.text) {
#5 lore raw

PATCH v8 3/4 x86/efi: avoid a relocation in efi_arch_post_exit_boot()

In reply to Frediano Ziglio

From: Roger Pau Monné <[email protected]>

Instead of using the absolute __start_xen address, calculate it as an offset from the current instruction pointer. The relocation would be problematic if the generated PE binary had .init.text as a standalone section with just read and execute permissions.

Removing this relocation is necessary to make it safe to split .init.

No functional change intended.

---
Changes since v1:
- Improve commit message.

Changes since v3:
- Added Acked-by.

Changes since v6:
- remove spurious quote.

---
 xen/arch/x86/efi/efi-boot.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/efi/efi-boot.h +5 -2
index d738b839ee..b983f054b5 100644
@@ -270,7 +270,9 @@ static void __init noreturn efi_arch_post_exit_boot(void)
 
                    /* Jump to higher mappings. */
                    "mov    stack_start(%%rip), %%rsp\n\t"
-                   "movabs $__start_xen, %[rip]\n\t"
+                   "lea    __start_xen(%%rip), %[rip]\n\t"
+                   "add    %[offset], %[rip]\n\t"
+
                    "push   %[cs]\n\t"
                    "push   %[rip]\n\t"
                    "lretq"
@@ -278,7 +280,8 @@ static void __init noreturn efi_arch_post_exit_boot(void)
                      [cr4] "+&r" (cr4)
                    : [cr3] "r" (idle_pg_table),
                      [cs] "i" (__HYPERVISOR_CS),
-                     [ds] "r" (__HYPERVISOR_DS)
+                     [ds] "r" (__HYPERVISOR_DS),
+                     [offset] "r" (__XEN_VIRT_START - xen_phys_start)
                    : "memory" );
     unreachable();
 }
Signature · 1 line
2.43.0
#6 lore raw

PATCH v8 4/4 x86: Split .init section to satisfy UEFI CA memory mitigation

In reply to Frediano Ziglio

Currently .init section is both writeable and executable, split data and code to have 2 sections satisfying W^X rule.

It is a requirement for NX_COMPAT so the PE can be loaded with W^X perms in the pagetables.

NX_COMPAT is a requirement from shim-review,
https://github.com/rhboot/shim-review#do-you-have-the-nx-bit-set-in-your-shim-if-so-is-your-entire-boot-stack-nx-compatible-and-what-testing-have-you-done-to-ensure-such-compatibility

---
Change since v1:
- update comment style.

Changes since v3:
- Added Acked-by.

Changes since v4:
- Added Acked-by.

---
 xen/arch/x86/xen.lds.S | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
xen/arch/x86/xen.lds.S +4 -8
index 4ed1d2bec1..e26e37db13 100644
@@ -193,11 +193,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.multiboot)
        *(.init.text)
@@ -210,12 +206,12 @@ 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 satisfy UEFI CA memory mitigation. */
+  . = ALIGN(SECTION_ALIGN);
 #endif
+  DECL_SECTION(.init.data) {
        *(.init.bss.stack_aligned)
        *(.init.data.page_aligned)
 
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v8 4/4] x86: Split .init section to satisfy UEFI CA memory mitigation

Quoted 6 lines · Frediano Ziglio

Currently .init section is both writeable and executable, split data and code to have 2 sections satisfying W^X rule.

It is a requirement for NX_COMPAT so the PE can be loaded with W^X perms in the pagetables.

Quoted 6 lines

NX_COMPAT is a requirement from shim-review,
https://github.com/rhboot/shim-review#do-you-have-the-nx-bit-set-in-your-shim-if-so-is-your-entire-boot-stack-nx-compatible-and-what-testing-have-you-done-to-ensure-such-compatibility

This patch cannot be taken yet.

It is reverting 1308f0170c1 while there are still relocations into .init.text.  It needs to wait until the trampoline has been sorted.

Also I note that the check for this case in mkreloc (added in that commit) only works on older toolchains.

Quoted 36 lines

---
Change since v1:
- update comment style.

Changes since v3:
- Added Acked-by.

Changes since v4:
- Added Acked-by.

---
 xen/arch/x86/xen.lds.S | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
xen/arch/x86/xen.lds.S +0 -7
index 4ed1d2bec1..e26e37db13 100644
@@ -193,11 +193,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.multiboot)
        *(.init.text)
@@ -210,12 +206,12 @@ SECTIONS
         */
        *(.altinstr_replacement)
 
-#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
-       . = ALIGN(SMP_CACHE_BYTES);
-#else

xen/arch/x86/xen.lds.S SECTIONS · line 217

Quoted 10 lines
xen/arch/x86/xen.lds.S +4 -1
   } PHDR(text)
-  DECL_SECTION(.init.data) {
+#ifdef EFI
+  /* Align to satisfy UEFI CA memory mitigation. */
+  . = ALIGN(SECTION_ALIGN);
 #endif
+  DECL_SECTION(.init.data) {
        *(.init.bss.stack_aligned)
        *(.init.data.page_aligned)
 

Stack alignment is greater than page alignment, there's no need for an ALIGN() at all.

Even if there was a need, it should have been PAGE_ALIGN and not SECTION_ALIGN.  We don't care about the boundary between .init and .init.data in the runtime image being 2M when we're freeing both sections.

~Andrew

#8 lore raw
In reply to Frediano Ziglio
Quoted 28 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Quoted 5 lines

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Forgive me asking, but why did this warrant another re-submission? We've got enough traffic on the list already.

Jan

#9 lore raw
Quoted 33 lines · Jan Beulich
Quoted 31 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Quoted 7 lines
Quoted 2 lines

Changes since v7:
- added Acked-by, all commit are now acked.

Forgive me asking, but why did this warrant another re-submission? We've got enough traffic on the list already.

Jan

Because there was an update and because nothing was merged.

Frediano

#10 lore raw
Quoted 34 lines · Frediano Ziglio
Quoted 33 lines · Jan Beulich
Quoted 31 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Changes since v7:
- added Acked-by, all commit are now acked.

Forgive me asking, but why did this warrant another re-submission? We've got enough traffic on the list already.

Because there was an update and because nothing was merged.

The tree isn't fully open yet, so things not having been merged yet isn't an indication of a problem. Andrew did indicate he'd like to massage some of the commit messages, so talk to him if you still find things uncommitted a little while after the tree is fully open again.

Jan

#11 lore raw
In reply to Frediano Ziglio
Quoted 43 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Frediano Ziglio (2):
Align relevant sections to 4KB
x86: Split .init section to satisfy UEFI CA memory mitigation

Roger Pau Monné (2):
x86/efi: discard multiboot and PVH support for PE binary x86/efi: avoid a relocation in efi_arch_post_exit_boot()

Quoted 7 lines
 docs/hypervisor-guide/x86/how-xen-boots.rst |  6 -----
 xen/arch/x86/boot/head.S                    |  8 +++----
 xen/arch/x86/efi/efi-boot.h                 |  7 ++++--
 xen/arch/x86/xen.lds.S                      | 25 ++++++++++++---------
 xen/tools/combine_two_binaries.py           |  2 +-
 5 files changed, 25 insertions(+), 23 deletions(-)

Ping

Frediano

#12 lore raw
Quoted 53 lines · Frediano Ziglio
Quoted 43 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Frediano Ziglio (2):
Align relevant sections to 4KB
x86: Split .init section to satisfy UEFI CA memory mitigation

Roger Pau Monné (2):
x86/efi: discard multiboot and PVH support for PE binary x86/efi: avoid a relocation in efi_arch_post_exit_boot()

Quoted 7 lines
 docs/hypervisor-guide/x86/how-xen-boots.rst |  6 -----
 xen/arch/x86/boot/head.S                    |  8 +++----
 xen/arch/x86/efi/efi-boot.h                 |  7 ++++--
 xen/arch/x86/xen.lds.S                      | 25 ++++++++++++---------
 xen/tools/combine_two_binaries.py           |  2 +-
 5 files changed, 25 insertions(+), 23 deletions(-)
Quoted 2 lines

Ping

Ping

Frediano

#13 lore raw
Quoted 53 lines · Frediano Ziglio
Quoted 52 lines · Frediano Ziglio
Quoted 49 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Frediano Ziglio (2):
Align relevant sections to 4KB
x86: Split .init section to satisfy UEFI CA memory mitigation

Roger Pau Monné (2):
x86/efi: discard multiboot and PVH support for PE binary x86/efi: avoid a relocation in efi_arch_post_exit_boot()

 docs/hypervisor-guide/x86/how-xen-boots.rst |  6 -----
 xen/arch/x86/boot/head.S                    |  8 +++----
 xen/arch/x86/efi/efi-boot.h                 |  7 ++++--
 xen/arch/x86/xen.lds.S                      | 25 ++++++++++++---------
 xen/tools/combine_two_binaries.py           |  2 +-
 5 files changed, 25 insertions(+), 23 deletions(-)
Quoted 3 lines
Quoted 1 line

Ping

Ping

Andrew had indicated to me (apparently not to you?) that he'd like to massage the descriptions some while committing. Hence why I refrained from putting any of this in.

Jan

#14 lore raw
Quoted 57 lines · Jan Beulich
Quoted 55 lines · Frediano Ziglio
Quoted 53 lines · Frediano Ziglio
Quoted 43 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Changes since v1:
- improved some comments;
- merged 2 pacthes removing multiboot support in x86 PE;
- removed a patch dealing with SBAT;
- other minor changes (see single patches).

Changes since v2:
- improved some comments.

Changes since v3:
- Added Acked-by;
- Improve commit message.

Changes since v4:
- Messages updates;
- Clean some dependencies cause by code removal;
- Add small commit to remove a possibly unused string.

Changes since v5:
- removed merged commit;
- remove more code/data from xen.efi output.

Changes since v6:
- fix commit message.

Changes since v7:
- added Acked-by, all commit are now acked.

Frediano Ziglio (2):
Align relevant sections to 4KB
x86: Split .init section to satisfy UEFI CA memory mitigation

Roger Pau Monné (2):
x86/efi: discard multiboot and PVH support for PE binary x86/efi: avoid a relocation in efi_arch_post_exit_boot()

Quoted 6 lines
 docs/hypervisor-guide/x86/how-xen-boots.rst |  6 -----
 xen/arch/x86/boot/head.S                    |  8 +++----
 xen/arch/x86/efi/efi-boot.h                 |  7 ++++--
 xen/arch/x86/xen.lds.S                      | 25 ++++++++++++---------
 xen/tools/combine_two_binaries.py           |  2 +-
 5 files changed, 25 insertions(+), 23 deletions(-)

Ping

Quoted 7 lines
Quoted 1 line

Ping

Andrew had indicated to me (apparently not to you?) that he'd like to massage the descriptions some while committing. Hence why I refrained from putting any of this in.

Jan

I understand maybe we want better comments and explaining what's missing/improvable could take more time than updating them directly, but how many months does this require?
Especially after the changes had different acks.

Frediano

#15 lore raw
In reply to Frediano Ziglio
Quoted 5 lines · Frediano Ziglio

These patches improve support for Secure boot.
UEFI CA memory mitigation requires memory pages to be not executable and writable at the same time. So changing permissions and splitting some section is required.
Remove multiboot pieces from EFI executable.

Here is a hopefully coherent write-up.

There is a project(?) named "UEFI CA memory mitigation" (a terrible name), to get the firmware ecosystem to stop mapping all pages as RWX. Elsewhere, this is known as W^X.  i.e. pages may be RW or RX but not RWX.   Confusingly, shim itself simply refers to this as "NX", or in some cases "NX_COMPAT", despite the characteristic being only one part of the problem.

Microsoft have signing requirements on PE binaries.  Section 17 is the relevant one here:

https://techcommunity.microsoft.com/blog/hardware-dev-center/updated-microsoft-uefi-signing-requirements/1062916

While for our usecase it is shim signed by Microsoft, shim is required to apply the same restrictions to what it loads.  i.e. Xen.

From MSFT, requirements are:
 * Sections must have page alignment
 * Sections must not both the MEM_WRITE and MEM_EXECUTE flags
 * The binary must set IMAGE_DLLCHARACTERISTICS_NX_COMPAT

In practice, it looks like shim doesn't actually check and reject section alignment issues.  It simply forces RW- or R-X over [section.base, roundup(section.length, 4k)) and lets you keep any broken pieces.  I don't see a check that section.base is appropriately aligned, nor any logic to set read-only on sections which are neither writeable nor executable.

Therefore, what this means for Xen:
 * Sections with differing permissions must not share a page
 * The binary must set IMAGE_DLLCHARACTERISTICS_NX_COMPAT

However, because Xen explicit undoes the relocation performed by the loader, it must write to every section containing a relocation while on the pagetables subject to restricted permissions.  Therefore we gain the further restrictions:

* Xen must have no relocations in executable sections.

This series contains _some_ work towards making Xen compliant with these restrictions.

Further work is needed for the trampoline.  In the Xenserver patchqueue it's moved into .data, but I would prefer to avoid this upstream.  My plan is to copy into place and _then_ relocate it, rather than the current behaviour of relocating it while in place in Xen _then_ copying it into place.

For the series, I will be adjusting commit message along the lines of ^, and get it committed.

~Andrew