Skip to content

Commit 095b830

Browse files
Peter Zijlstrabp3tk0v
authored andcommitted
x86/alternative: Make custom return thunk unconditional
There is infrastructure to rewrite return thunks to point to any random thunk one desires, unwrap that from CALL_THUNKS, which up to now was the sole user of that. [ bp: Make the thunks visible on 32-bit and add ifdeffery for the 32-bit builds. ] Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230814121148.775293785@infradead.org
1 parent 4ae68b2 commit 095b830

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,18 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
341341
extern retpoline_thunk_t __x86_indirect_call_thunk_array[];
342342
extern retpoline_thunk_t __x86_indirect_jump_thunk_array[];
343343

344+
#ifdef CONFIG_RETHUNK
344345
extern void __x86_return_thunk(void);
346+
#else
347+
static inline void __x86_return_thunk(void) {}
348+
#endif
349+
345350
extern void zen_untrain_ret(void);
346351
extern void srso_untrain_ret(void);
347352
extern void srso_untrain_ret_alias(void);
348353
extern void entry_ibpb(void);
349354

350-
#ifdef CONFIG_CALL_THUNKS
351355
extern void (*x86_return_thunk)(void);
352-
#else
353-
#define x86_return_thunk (&__x86_return_thunk)
354-
#endif
355356

356357
#ifdef CONFIG_CALL_DEPTH_TRACKING
357358
extern void __x86_return_skl(void);

arch/x86/kernel/alternative.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,6 @@ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end)
687687

688688
#ifdef CONFIG_RETHUNK
689689

690-
#ifdef CONFIG_CALL_THUNKS
691-
void (*x86_return_thunk)(void) __ro_after_init = &__x86_return_thunk;
692-
#endif
693-
694690
/*
695691
* Rewrite the compiler generated return thunk tail-calls.
696692
*

arch/x86/kernel/cpu/bugs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ EXPORT_SYMBOL_GPL(x86_pred_cmd);
6363

6464
static DEFINE_MUTEX(spec_ctrl_mutex);
6565

66+
void (*x86_return_thunk)(void) __ro_after_init = &__x86_return_thunk;
67+
6668
/* Update SPEC_CTRL MSR and its cached copy unconditionally */
6769
static void update_spec_ctrl(u64 val)
6870
{

0 commit comments

Comments
 (0)