mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	David Kaplan <david.kaplan@amd.com>,
	x86@kernel.org, Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [tip: x86/bugs] Revert "x86/retpoline: Ensure default return thunk isn't used at runtime"
Date: Fri, 4 Oct 2024 21:37:55 +0200	[thread overview]
Message-ID: <20241004193755.GV18071@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <169770844376.3135.9436969789797102205.tip-bot2@tip-bot2>

On Thu, Oct 19, 2023 at 09:40:43AM -0000, tip-bot2 for Borislav Petkov (AMD) wrote:
> The following commit has been merged into the x86/bugs branch of tip:
> 
> Commit-ID:     08ec7e82c1e3ebcd79ab8d2d0d11faad0f07e71c
> Gitweb:        https://git.kernel.org/tip/08ec7e82c1e3ebcd79ab8d2d0d11faad0f07e71c
> Author:        Borislav Petkov (AMD) <bp@alien8.de>
> AuthorDate:    Thu, 19 Oct 2023 11:04:27 +02:00
> Committer:     Borislav Petkov (AMD) <bp@alien8.de>
> CommitterDate: Thu, 19 Oct 2023 11:08:22 +02:00
> 
> Revert "x86/retpoline: Ensure default return thunk isn't used at runtime"
> 
> This reverts commit 91174087dcc7565d8bf0d576544e42d5b1de6f39.
> 
> It turns out that raising an undefined opcode exception due to unpatched
> return thunks is not visible to users in every possible scenario (not
> being able to catch dmesg, slow console, etc.).
> 
> Thus, it is not very friendly to them when the box explodes without even
> saying why.

This is what we have __bug_table for...

Turns out asm/bug.h doesn't currently have nice helpers for __ASSMEBLY__
so I botched it a bit...

---
diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S
index d9feadffa972..003379049924 100644
--- a/arch/x86/entry/entry.S
+++ b/arch/x86/entry/entry.S
@@ -10,8 +10,6 @@
 #include <asm/segment.h>
 #include <asm/cache.h>
 
-#include "calling.h"
-
 .pushsection .noinstr.text, "ax"
 
 SYM_FUNC_START(entry_ibpb)
@@ -45,4 +43,3 @@ EXPORT_SYMBOL_GPL(mds_verw_sel);
 
 .popsection
 
-THUNK warn_thunk_thunk, __warn_thunk
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index ff5f1ecc7d1e..547cde3db276 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -387,8 +387,6 @@ extern void clear_bhb_loop(void);
 
 extern void (*x86_return_thunk)(void);
 
-extern void __warn_thunk(void);
-
 #ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING
 extern void call_depth_return_thunk(void);
 
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index d1915427b4ff..b86048f31a0c 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -3025,8 +3025,3 @@ ssize_t cpu_show_reg_file_data_sampling(struct device *dev, struct device_attrib
 	return cpu_show_common(dev, attr, buf, X86_BUG_RFDS);
 }
 #endif
-
-void __warn_thunk(void)
-{
-	WARN_ONCE(1, "Unpatched return thunk in use. This should not happen!\n");
-}
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index 391059b2c6fb..469bf27287a1 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -12,9 +12,39 @@
 #include <asm/percpu.h>
 #include <asm/frame.h>
 #include <asm/nops.h>
+#include <linux/objtool.h>
 
-	.section .text..__x86.indirect_thunk
+// this should probably go in asm/bug.h
+
+#ifdef CONFIG_X86_32
+#define __BUG_REL(val)	.long	val
+#else
+#define __BUG_REL(val)	.long	val - .
+#endif
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __BUG_VERBOSE()						\
+	__BUG_REL(0) ;						\
+	.word 0 ;
+#else
+#define __BUG_VERBOSE()
+#endif
 
+#define _BUG_FLAGS(flags)					\
+	1: ;							\
+	.pushsection __bug_table, "aw" ;			\
+	2: __BUG_REL(1b) ;					\
+	__BUG_VERBOSE() ;					\
+	.word flags ;						\
+	.org 2b+(6+6*IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) ;	\
+	.popsection
+
+#define WARN_ONCE						\
+	_BUG_FLAGS(3) ;						\
+	ALTERNATIVE "", "ud2", X86_FEATURE_ALWAYS ;		\
+	REACHABLE
+
+	.section .text..__x86.indirect_thunk
 
 .macro POLINE reg
 	ANNOTATE_INTRA_FUNCTION_CALL
@@ -37,9 +67,15 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL)
 	UNWIND_HINT_UNDEFINED
 	ANNOTATE_NOENDBR
 
+#ifdef CONFIG_X86_32
 	ALTERNATIVE_2 __stringify(RETPOLINE \reg), \
 		      __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg; int3), X86_FEATURE_RETPOLINE_LFENCE, \
 		      __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), ALT_NOT(X86_FEATURE_RETPOLINE)
+#else
+	WARN_ONCE
+	ANNOTATE_RETPOLINE_SAFE
+	jmp *%\reg
+#endif
 
 .endm
 
@@ -382,16 +418,15 @@ SYM_FUNC_END(call_depth_return_thunk)
 SYM_CODE_START(__x86_return_thunk)
 	UNWIND_HINT_FUNC
 	ANNOTATE_NOENDBR
-#if defined(CONFIG_MITIGATION_UNRET_ENTRY) || \
-    defined(CONFIG_MITIGATION_SRSO) || \
-    defined(CONFIG_MITIGATION_CALL_DEPTH_TRACKING)
-	ALTERNATIVE __stringify(ANNOTATE_UNRET_SAFE; ret), \
-		   "jmp warn_thunk_thunk", X86_FEATURE_ALWAYS
-#else
+
+#ifdef CONFIG_X86_64
+	WARN_ONCE
+#endif
+
 	ANNOTATE_UNRET_SAFE
 	ret
-#endif
 	int3
+
 SYM_CODE_END(__x86_return_thunk)
 EXPORT_SYMBOL(__x86_return_thunk)
 


  reply	other threads:[~2024-10-04 19:38 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 17:10 [PATCH 0/3] Ensure default return thunk isn't used at runtime David Kaplan
2023-10-10 17:10 ` [PATCH 1/3] Revert "x86/retpoline: Remove .text..__x86.return_thunk section" David Kaplan
2023-10-10 17:48   ` Peter Zijlstra
2023-10-10 19:57     ` Josh Poimboeuf
2023-10-10 20:04       ` Borislav Petkov
2023-10-10 20:19         ` Josh Poimboeuf
2023-10-10 20:40           ` Kaplan, David
2023-10-10 21:22           ` Josh Poimboeuf
2023-10-11  7:41             ` Peter Zijlstra
2023-10-11  9:34               ` Borislav Petkov
2023-10-11 16:28               ` Josh Poimboeuf
2023-10-11 22:35                 ` Peter Zijlstra
2023-10-11 22:42                   ` Ingo Molnar
2023-10-12  2:27                   ` Josh Poimboeuf
2023-10-12  2:47                     ` [PATCH v2] objtool: Fix return thunk patching in retpolines Josh Poimboeuf
2023-10-12  6:25                       ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-10-12  8:16                       ` [PATCH v2] " Peter Zijlstra
2023-10-12 17:50                       ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-10-20 11:37                       ` tip-bot2 for Josh Poimboeuf
2023-10-12  8:16                     ` [PATCH 1/3] Revert "x86/retpoline: Remove .text..__x86.return_thunk section" Peter Zijlstra
2023-10-10 17:10 ` [PATCH 2/3] x86/vdso: Run objtool on vdso32-setup David Kaplan
2023-10-12 17:50   ` [tip: x86/bugs] x86/vdso: Run objtool on vdso32-setup.o tip-bot2 for David Kaplan
2023-10-20 11:37   ` tip-bot2 for David Kaplan
2023-10-10 17:10 ` [PATCH 3/3] x86/retpoline: Ensure default return thunk isn't used at runtime David Kaplan
2023-10-10 19:36   ` Josh Poimboeuf
2023-10-10 20:14     ` Kaplan, David
2023-10-10 20:41       ` Josh Poimboeuf
2023-10-12 14:10         ` [PATCH -v2] " Borislav Petkov
2023-10-12 17:11           ` Josh Poimboeuf
2023-10-12 17:50           ` [tip: x86/bugs] " tip-bot2 for David Kaplan
2023-10-16 21:10             ` Nathan Chancellor
2023-10-16 21:29               ` Borislav Petkov
2023-10-16 21:48                 ` Nathan Chancellor
2023-10-17  4:31                   ` Kaplan, David
2023-10-17  5:28                     ` Josh Poimboeuf
2023-10-17 13:54                       ` Kaplan, David
2023-10-17 15:24                       ` Nick Desaulniers
2023-10-17 15:26                         ` Marco Elver
2023-10-17 15:32                       ` Nathan Chancellor
2023-10-17 16:59                         ` [PATCH] x86/srso: Fix panic in return thunk during boot Josh Poimboeuf
2023-10-17 17:52                           ` [tip: x86/bugs] x86/retpoline: Make sure there are no unconverted return thunks due to KCSAN tip-bot2 for Josh Poimboeuf
2023-10-20 11:37                           ` tip-bot2 for Josh Poimboeuf
2023-10-18 13:23             ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Borislav Petkov
2023-10-18 13:38               ` Ingo Molnar
2023-10-18 15:12                 ` Borislav Petkov
2023-10-18 15:54                   ` Josh Poimboeuf
2023-10-18 17:55                     ` Borislav Petkov
2023-10-18 18:14                       ` Josh Poimboeuf
2023-10-18 18:22                         ` Borislav Petkov
2023-10-18 18:39                           ` Josh Poimboeuf
2023-10-18 18:44                             ` Borislav Petkov
2023-10-18 19:14                               ` Josh Poimboeuf
2023-10-18 20:04                                 ` Borislav Petkov
2023-10-18 20:37                       ` Borislav Petkov
2023-10-19  6:35                         ` Josh Poimboeuf
2023-10-19  6:59                           ` Josh Poimboeuf
2023-10-19 14:15                             ` Borislav Petkov
2023-10-19 14:21                               ` Kaplan, David
2023-10-19 14:39                                 ` Borislav Petkov
2023-10-19 15:20                                   ` Josh Poimboeuf
2023-10-24 20:19                                     ` Borislav Petkov
2024-01-03 18:46                                       ` Borislav Petkov
2024-01-04 13:12                                         ` Borislav Petkov
2024-01-04 13:24                                           ` [PATCH -v2] " Borislav Petkov
2024-01-04 13:26                                             ` Borislav Petkov
2024-02-07 17:50                                               ` Josh Poimboeuf
2024-02-07 18:53                                                 ` Borislav Petkov
2024-02-07 19:49                                                   ` Josh Poimboeuf
2024-02-12 10:43                                                     ` Borislav Petkov
2024-04-03 17:10                                                       ` Klara Modin
2024-04-03 17:30                                                         ` Borislav Petkov
2024-04-03 20:26                                                           ` Klara Modin
2024-04-03 20:41                                                             ` Borislav Petkov
2024-04-03 22:25                                                               ` Klara Modin
2024-04-04 14:44                                                                 ` Borislav Petkov
2024-04-16  9:27                                                         ` Borislav Petkov
2024-04-17  3:59                                                           ` Klara Modin
2024-04-17 16:20                                                         ` [tip: x86/urgent] x86/retpolines: Enable the default thunk warning only on relevant configs tip-bot2 for Borislav Petkov (AMD)
2023-10-19  7:43                         ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Peter Zijlstra
2023-10-19  9:40                       ` [tip: x86/bugs] Revert "x86/retpoline: Remove .text..__x86.return_thunk section" tip-bot2 for Borislav Petkov (AMD)
2023-10-19  9:40                       ` [tip: x86/bugs] Revert "x86/retpoline: Ensure default return thunk isn't used at runtime" tip-bot2 for Borislav Petkov (AMD)
2024-10-04 19:37                         ` Peter Zijlstra [this message]
2024-02-12 14:13   ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime tip-bot2 for Josh Poimboeuf
2024-02-15  3:20     ` Nathan Chancellor
2024-02-15  8:30       ` Nikolay Borisov
2024-02-15 15:53       ` Borislav Petkov
2024-02-16  5:42         ` Josh Poimboeuf
2024-02-16 21:27           ` Borislav Petkov
2024-02-20  5:57             ` [PATCH] x86/vdso: Fix rethunk patching for vdso-image-{32,64}.o Josh Poimboeuf
2024-02-20 12:31       ` [tip: x86/core] " tip-bot2 for Josh Poimboeuf
2023-10-10 17:52 ` [PATCH 0/3] Ensure default return thunk isn't used at runtime Peter Zijlstra
2023-10-20 11:28 ` Subject: [PATCH] x86/retpoline: Document some thunk handling aspects (was: Re: [PATCH 0/3] Ensure default return thunk isn't used at runtime) Borislav Petkov
2023-10-20 11:37 ` [tip: x86/bugs] x86/retpoline: Document some thunk handling aspects tip-bot2 for Borislav Petkov (AMD)

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=20241004193755.GV18071@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@alien8.de \
    --cc=david.kaplan@amd.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.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

Powered by JetHome