[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/2] x86/head: check base address alignment
- To: xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Tue, 2 May 2023 16:59:19 +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=UN0wmpmoxxOBfT7pEjwKaFozddVpe6jQy1KrqXoAqWg=; b=KVR4zCHGoqwdPbQgxyo4P7iflX9oP+UT/8atSEFBpJSeN+SpdrqgxDrMOL/p5isydOvxBTKaRRLuXBgG/KPYMBOemcglpSZoSP9OsOMM4P+uzzPTvCyGRb3dZAFQ9IPhYDpjkcrZVovLgRk5gUeoDvstuaP7W68COEOr6UjUMrWwiHyBi4KBmONdU0uD9vJGRcIVVDsPhmAehZH/t8G92ynOfce7kp1Ftip7EMjfPz2gbsl+Dkcy67Hjz1CCF6Yb17i+C9CeXOyn84GpA0VxEgGtch9vrOG4P4QqoIGysgttzDYurs46Vjd07WKX7zPVohFtLTqGPzzAgXbOJJbjkw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UbwtbursVbivaWSRocTQd0LWVyUWKuLyvPfQVNEviZ6tSY6nT+/kH5mJeb0qXZX5RLXPdIFsUULjMnxQIZ7WXr0LamjxGdt3KDVfAH7kEhWgm0nOXE1+zknbftxwRn9vEXDhAo+yYHpX1ZlrOkgSo0bPKsQ+DcoGi9mWCF9mbcABrdLUSi8MUtp955nkqN0vxWB5iQ7lqydQUiLNybGZ7lUN7WWwb5TJtJQdrgjmWwqWj46fHdWUhD7kLOybNdgJS5kqACiwo/ofOMEn4EHo2mh8C8CV4HlJqIFkbmdmfgpqZVF/u217myAxVwkOGe037NSBnx8QF7dIO2jfqYlTRg==
- 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 15:00:43 +0000
- Ironport-data: A9a23:kFtgX64nnShQk6lwj2MnBgxRtBjGchMFZxGqfqrLsTDasY5as4F+v mIfCG+HM/uNamPweYggaI6z9UwH7ceAxtFgSAA4qCk8Hi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraCYnsrLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+7ZwehBtC5gZlPa0T5geE/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5mt sAHOis3NUm5p9mb6r+ZdPBSuZwjFZy+VG8fkikIITDxK98DGMiGZpqQoNhS0XE3m9xEGuvYa 4wBcz1zYR/cYhpJfFAKFJY5m+TujX76G9FagAvN+exrvC6OkUooiOSF3Nn9I7RmQe1PmUmVv CTe9nnRCRAGLt2PjzGC9xpAg8eWxX2gBNJCTuHQGvhCukK+lisRNj8taBiFnumV0HGXX4tDJ BlBksYphe1onKCxdfHtUhv9rHOasxo0X9tLD/Z8+AyL0rDT4QuSGi4DVDEpQN4sudIyRDcq/ kSUhN6vDjtq2JWKTVqN+7HSqim9URX5NkcHbC4ACA4aud/qpdhrigqVF44/VqmoktfyBDf8h SiQqzQzjKkSishN0Lin+VfAgHSnoZ2hohMJ2zg7l1mNtmtRDLNJraTxtwWzASpoRGpBcmS8g Q==
- Ironport-hdrordr: A9a23:LIa61q+QX2xnH6lGeZRuk+G/dr1zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYVYqN03IV+rwWpVoJkmsj6KdgLNhRotKOTOLhILGFvAH0WKP+V3d8mjFh5dgPM RbAtdD4aPLfD9HZK/BiWHXcurIguP3iJxA7d2us0uFJjsaDp2IgT0JaTpyRSZNNXR77NcCZd OhDo0tnUvSRV0nKuCAQlUVVenKoNPG0LrgfB49HhYirCWekD+y77b+Mh6AmjMTSSlGz7sO+X XM11WR3NTvj9iLjjvnk0PD5ZVfn9XsjvNFGcy3k8AQbhn8lwqyY4xlerua+BQ4uvum5loGmM TF5z0gI8NwwXXMeXzdm2qm5yDQlBIVr1Pyw16RhnXu5eT/WTIBEsJEwaZUaAHQ5UYMtMx1lP sj5RPTi7NnSTf72Ajt7dnBUB9n0mKyvHoZiOYWy1hSS5EXZrN9pZEWuGlVDJADNiTn751PKp gnMOjsoNJtNX+KZXHQuWdihPSqQ3QIBx+DBnMPv8SEugIm6ExR/g89/ogyj30A/JUyR91v/O LfKJllk7lIU4s/cb99LP1pe7r3NkX9BTb3dE6CK1XuE68Kf1jXrYTs3bkz7Oa2PLQV0ZoJno jbWl8wjx99R6vXM7zM4HR3yGGOfI3kNg6dj/22pqIJ9YEUfYCbcRFqEzsV4o+dS/Z2OLyvZx /8AuMQPxbZFxqfJW945XyBZ3BsEwhubCRsgKdcZ7uvmLO9FmS4jJ2sTN/jYJzQLB0DZkTTRl M+YRmbHrQz0qnsYA61vCTs
- 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 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>
---
Changes since v1:
- Use test instead of and instruction.
- Add a build time check for sym_offs correctness.
- Reword part of the commit message.
---
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 0fb7dd3029f2..b9c9447df9df 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!"
+.Lbag_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:
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 +675,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 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
|