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

[PATCH 1/2] x86/head: check base address alignment


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 2 May 2023 11:22:23 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DLYLxraJZq+IGvhK6ipB1M7FD/OD6TDsXKINBErQQ+o=; b=PpUcnT3/eM9DD4GHTPL4ILidlRrtk3Am01eCYUuGtdy2ko7DBDLG0lFmMhLGUYv1a+bMBGq+y64Gtu9YJpO8r/DyRuVDlO9oPLlKM+ZpzQuLSzYzOjwgclB/x2f0FguAj67U31caVNWmipJz+lsbTO9wpElesbbq85ReafMmWWMq3iyj+dGSGAbK5gRlgtA5xMFUnV1PGh6FwIWlzxvPcnCQg17XbelIQGJoXCGChLGk45N7MQO498GhJk9CwSmgMwjJlm+n5wqZD7KSPHL3Yn1cvwDIV5S6aGD8S3w3qKgNqu6EURyfRZJv/P0097VMGwm3D0tVXcS7uhu3CaMgMg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B0U0ilJDWosDcWjLN/xie8ZJzC7K/4HzRPuDd6ViGpiN2hFMsqob9BUPIP5qNRl1Yfz0NhuN5gVNlBnyMXkB8Yh7TISkYZcQQIu2+clV2Xq/0bmcZlGZt6HZFzzT71o4cQhH0/LY8WCwgBYi+AXKF7sGdk3iXRXKTFANP6HeNimrmkmQFfSdkcnnp0b3jE7nu2lVz7HECJvGUXQIgJnegi1IvB/RkuELgZxGBAexSttGK8cEQ57cNVAfQfuJJ8wXiyt4ITnQnjzoRrsiuQjmYdSH74crbYc1y4VXMx/bRiXx3I0XiDJ54/Kvpt3u2DrmmPceMTqKQKSsuzyu7ELv8g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 02 May 2023 09:23:00 +0000
  • Ironport-data: A9a23:4m+MZa3wP7j/nkcxJ/bD5fVwkn2cJEfYwER7XKvMYLTBsI5bp2EEm jQeCGzQOqyLYWP0fooibYi2/UNXvZTcm4Q1QQZopC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS+XuDgNyo4GlD5gFmP6gS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfG2tBy OE8dykxbzPYm+3s6ZyddPlAr5F2RCXrFNt3VnBI6xj8VKxjbbWdBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxqsi6Kk1IZPLvFabI5fvSQQspYhACAr 3/u9GXlGBAKcteYzFJp91r13r6ezHugBNh6+LuQ1681rhqa4HQqCzoSW0qnu8O/qhS5cocKQ 6AT0m90xUQoz2S7Q9+4UxCmrXqsuh8HR8EWA+A88BuKyKff/0CeHGdsZjxLZcEitcQ2bSc3z VLPlNTsbRRwtJWFRHTb8a2bxQ5eIgAQJG4GICMBEw0M5oC5pJlp102RCNF+DKSyk9v5Xynqx CyHpzQ/gLNVitMX06K8/hbMhDfESoX1czPZLz7/BgqNhj6Vrqb/D2B0wTA3Ncp9Ebs=
  • Ironport-hdrordr: A9a23:0SmS46NZuixqWsBcT7r155DYdb4zR+YMi2TDGXoBLSC9E/bo4/ xG+c5xuyMc5wxwZJheo6H+BEDtexLhHP1OkPss1MmZLWvbUQKTRekJ0WKI+UyCJ8SRzJ856U 9qG5IOduEZZTJB4foTi2ODfOrJD7O8nZyAtKPm6zNIcCkvUqdn6m5Ce3Om+o8dfng2OXL8fq DslfauYlCbCAQqh7+Adx44dtmGncTPiJXlJTYeHnccmXGzpALt0qf+Dx+bmjwDUzZDqI1SjV TtokjC/6C+tPP+7RfZ2wbonvJrseqk8MJHGMuPzu4KLTn24zzYHbhJavm5pTUop+Pq0nYG+e O82CsIDoBI8nbMeWPwmxf3xAX69z4r5xbZuCWlqEqmm9X9WDU5T/VMnphYdByx0TtcgO1B
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 found a broken firmware where the loader would end up loading
Xen at a non 2M aligned region, 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.

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>
---
 xen/arch/x86/boot/head.S | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 0fb7dd3029f2..ff73c1d274c4 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -121,6 +121,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!"
+.Lbag_alg_msg: .asciz "ERR: Xen must be loaded at a 2Mb boundary!"
 
         .section .init.data, "aw", @progbits
         .align 4
@@ -146,6 +147,9 @@ bad_cpu:
 not_multiboot:
         add     $sym_offs(.Lbad_ldr_msg),%esi   # Error message
         jmp     .Lget_vtb
+not_aligned:
+        add     $sym_offs(.Lbag_alg_msg),%esi   # Error message
+        jmp     .Lget_vtb
 .Lmb2_no_st:
         /*
          * Here we are on EFI platform. vga_text_buffer was zapped earlier
@@ -670,6 +674,11 @@ trampoline_setup:
         cmp     %edi, %eax
         jb      1b
 
+        /* Check that the image base is aligned. */
+        lea     sym_esi(_start), %eax
+        and     $(1 << L2_PAGETABLE_SHIFT) - 1, %eax
+        jnz     not_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 ^      */
-- 
2.40.0




 


Rackspace

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