]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/boot: Disable UBSAN in early boot code
authorArd Biesheuvel <ardb@kernel.org>
Thu, 5 Dec 2024 11:28:09 +0000 (12:28 +0100)
committerIngo Molnar <mingo@kernel.org>
Thu, 5 Dec 2024 12:18:54 +0000 (13:18 +0100)
The early boot code runs from a 1:1 mapping of memory, and may execute
before the kernel virtual mapping is even up. This means absolute symbol
references cannot be permitted in this code.

UBSAN injects references to global data structures into the code, and
without -fPIC, those references are emitted as absolute references to
kernel virtual addresses. Accessing those will fault before the kernel
virtual mapping is up, so UBSAN needs to be disabled in early boot code.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20241205112804.3416920-13-ardb+git@google.com
arch/x86/coco/sev/shared.c
arch/x86/include/asm/init.h

index afb7ffc355fee372c3b6eb8f015b917649972ec1..96023bd978cc1ef3bfbff73faeb8706de4bc0ee8 100644 (file)
@@ -498,7 +498,7 @@ static const struct snp_cpuid_table *snp_cpuid_get_table(void)
  *
  * Return: XSAVE area size on success, 0 otherwise.
  */
-static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
+static u32 __head snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
 {
        const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
        u64 xfeatures_found = 0;
@@ -576,8 +576,9 @@ static void snp_cpuid_hv(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpui
                sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV);
 }
 
-static int snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
-                                struct cpuid_leaf *leaf)
+static int __head
+snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
+                     struct cpuid_leaf *leaf)
 {
        struct cpuid_leaf leaf_hv = *leaf;
 
index 14d72727d7eecf68e88426fa6eee7988fe570cb3..0e82ebc5d1e1907f5b4c756e197388f15bb99e96 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef _ASM_X86_INIT_H
 #define _ASM_X86_INIT_H
 
-#define __head __section(".head.text")
+#define __head __section(".head.text") __no_sanitize_undefined
 
 struct x86_mapping_info {
        void *(*alloc_pgt_page)(void *); /* allocate buf for page table */