From: Ard Biesheuvel <ardb+git@google.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
Nathan Chancellor <nathan@kernel.org>
Subject: [RFC PATCH 2/2] x86/sev: Disable jump tables in SEV startup code
Date: Mon, 27 Jan 2025 12:43:37 +0100 [thread overview]
Message-ID: <20250127114334.1045857-6-ardb+git@google.com> (raw)
In-Reply-To: <20250127114334.1045857-4-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
When retpolines and IBT are both disabled, the compiler is free to use
jump tables to optimize switch instructions. However, these are emitted
by Clang as absolute references into .rodata, e.g.,
jmp *-0x7dfffe90(,%r9,8)
R_X86_64_32S .rodata+0x170
Given that this code will execute before that address in .rodata has even
been mapped, it is guaranteed to crash a SEV-SNP guest in a way that is
difficult to diagnose.
So disable jump tables when building this code. It would be better if we
could attach this annotation to the __head macro but this appears to be
impossible.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/coco/sev/Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/coco/sev/Makefile b/arch/x86/coco/sev/Makefile
index 08de37559307..dcb06dc8b5ae 100644
--- a/arch/x86/coco/sev/Makefile
+++ b/arch/x86/coco/sev/Makefile
@@ -2,6 +2,10 @@
obj-y += core.o
+# jump tables are emitted using absolute references in non-PIC code
+# so they cannot be used in the early SEV startup code
+CFLAGS_core.o += -fno-jump-tables
+
ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_core.o = -pg
endif
--
2.48.1.262.g85cc9f2d1e-goog
next prev parent reply other threads:[~2025-01-27 11:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-27 11:43 [RFC PATCH 0/2] Fix more head.text bugs and improve diagnostic Ard Biesheuvel
2025-01-27 11:43 ` [RFC PATCH 1/2] x86/relocs: Improve diagnostic for rejected absolute references Ard Biesheuvel
2025-01-27 16:57 ` Linus Torvalds
2025-01-27 22:01 ` Ard Biesheuvel
2025-02-03 9:40 ` Ingo Molnar
2025-02-03 10:00 ` Ard Biesheuvel
2025-02-22 12:01 ` Ingo Molnar
2025-02-22 12:03 ` Ingo Molnar
2025-02-22 13:47 ` Ard Biesheuvel
2025-02-22 13:49 ` Ingo Molnar
2025-01-27 11:43 ` Ard Biesheuvel [this message]
2025-01-27 17:09 ` [RFC PATCH 2/2] x86/sev: Disable jump tables in SEV startup code Linus Torvalds
2025-01-27 22:15 ` Ard Biesheuvel
2025-01-27 22:28 ` Ard Biesheuvel
2025-01-28 22:22 ` [tip: x86/urgent] " tip-bot2 for Ard Biesheuvel
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=20250127114334.1045857-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=nathan@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=torvalds@linux-foundation.org \
--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