[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen stable-4.17] x86/head: check base address alignment



commit e5f9987d5f63ecc3cc9884c614aca699a41e7ca7
Author:     Roger Pau Monné <roger.pau@xxxxxxxxxx>
AuthorDate: Tue Sep 5 08:46:28 2023 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Sep 5 08:46:28 2023 +0200

    x86/head: check base address alignment
    
    Ensure that the base address is 2M aligned, or else the page table
    entries created would be corrupt as reserved bits on the PDE end up
    set.
    
    We have encountered a broken firmware where grub2 would end up loading
    Xen at a non 2M aligned region when using the multiboot2 protocol, and
    that caused a very difficult to debug triple fault.
    
    If the alignment is not as required by the page tables print an error
    message and stop the boot.  Also add a build time check that the
    calculation of symbol offsets don't break alignment of passed
    addresses.
    
    The check could be performed earlier, but so far the alignment is
    required by the page tables, and hence feels more natural that the
    check lives near to the piece of code that requires it.
    
    Note that when booted as an EFI application from the PE entry point
    the alignment check is already performed by
    efi_arch_load_addr_check(), and hence there's no need to add another
    check at the point where page tables get built in
    efi_arch_memory_setup().
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: 0946068e7faea22868c577d7afa54ba4970ff520
    master date: 2023-05-03 13:36:25 +0200
---
 xen/arch/x86/boot/head.S | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 245c859dd7..6bc64c9e86 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -1,3 +1,4 @@
+#include <xen/lib.h>
 #include <xen/multiboot.h>
 #include <xen/multiboot2.h>
 #include <public/xen.h>
@@ -121,6 +122,7 @@ multiboot2_header:
 .Lbad_ldr_nst: .asciz "ERR: EFI SystemTable is not provided by bootloader!"
 .Lbad_ldr_nih: .asciz "ERR: EFI ImageHandle is not provided by bootloader!"
 .Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!"
+.Lbad_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
 
         .section .init.data, "aw", @progbits
         .align 4
@@ -146,6 +148,9 @@ bad_cpu:
 not_multiboot:
         mov     $sym_offs(.Lbad_ldr_msg), %ecx
         jmp     .Lget_vtb
+.Lnot_aligned:
+        mov     $sym_offs(.Lbad_alg_msg), %ecx
+        jmp     .Lget_vtb
 .Lmb2_no_st:
         /*
          * Here we are on EFI platform. vga_text_buffer was zapped earlier
@@ -673,6 +678,15 @@ trampoline_setup:
         cmp     %edi, %eax
         jb      1b
 
+        .if !IS_ALIGNED(sym_offs(0), 1 << L2_PAGETABLE_SHIFT)
+        .error "Symbol offset calculation breaks alignment"
+        .endif
+
+        /* Check that the image base is aligned. */
+        lea     sym_esi(_start), %eax
+        test    $(1 << L2_PAGETABLE_SHIFT) - 1, %eax
+        jnz     .Lnot_aligned
+
         /* Map Xen into the higher mappings using 2M superpages. */
         lea     _PAGE_PSE + PAGE_HYPERVISOR_RWX + sym_esi(_start), %eax
         mov     $sym_offs(_start),   %ecx   /* %eax = PTE to write ^      */
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.17



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.