From: Ard Biesheuvel <ardb+git@google.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Kees Cook <keescook@chromium.org>,
Brian Gerst <brgerst@gmail.com>,
Kevin Loughlin <kevinloughlin@google.com>
Subject: [PATCH v4 4/7] x86/boot: Disable UBSAN in early boot code
Date: Thu, 5 Dec 2024 12:28:09 +0100 [thread overview]
Message-ID: <20241205112804.3416920-13-ardb+git@google.com> (raw)
In-Reply-To: <20241205112804.3416920-9-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
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>
---
arch/x86/coco/sev/shared.c | 7 ++++---
arch/x86/include/asm/init.h | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
index afb7ffc355fe..96023bd978cc 100644
--- a/arch/x86/coco/sev/shared.c
+++ b/arch/x86/coco/sev/shared.c
@@ -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;
diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h
index 14d72727d7ee..0e82ebc5d1e1 100644
--- a/arch/x86/include/asm/init.h
+++ b/arch/x86/include/asm/init.h
@@ -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 */
--
2.47.0.338.g60cca15819-goog
next prev parent reply other threads:[~2024-12-05 11:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 11:28 [PATCH v4 0/7] x86: Rid .head.text of all abs references Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 1/7] x86/sev: Avoid WARN()s and panic()s in early boot code Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2025-01-06 15:23 ` [PATCH v4 1/7] " Tom Lendacky
2025-01-07 11:12 ` [tip: x86/boot] x86/sev: Don't hang but terminate on failure to remap SVSM CA tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 2/7] x86/boot/64: Determine VA/PA offset before entering C code Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 3/7] x86/boot/64: Avoid intentional absolute symbol references in .head.text Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` Ard Biesheuvel [this message]
2024-12-05 12:28 ` [tip: x86/boot] x86/boot: Disable UBSAN in early boot code tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 5/7] x86/kernel: Move ENTRY_TEXT to the start of the image Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 6/7] x86/boot: Move .head.text into its own output section Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-12-05 11:28 ` [PATCH v4 7/7] x86/boot: Reject absolute references in .head.text Ard Biesheuvel
2024-12-05 12:28 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-12-31 10:01 ` [PATCH v4 0/7] x86: Rid .head.text of all abs references Borislav Petkov
2024-12-31 10:12 ` Ard Biesheuvel
2024-12-31 10:35 ` Borislav Petkov
2024-12-31 19:29 ` Ard Biesheuvel
2025-01-01 2:43 ` Nathan Chancellor
2025-01-01 8:01 ` Ard Biesheuvel
2025-01-01 10:39 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241205112804.3416920-13-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=keescook@chromium.org \
--cc=kevinloughlin@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox