Skip to content

Commit 1a6f744

Browse files
author
Peter Zijlstra
committed
x86/retpoline: Create a retpoline thunk array
Stick all the retpolines in a single symbol and have the individual thunks as inner labels, this should guarantee thunk order and layout. Previously there were 16 (or rather 15 without rsp) separate symbols and a toolchain might reasonably expect it could displace them however it liked, with disregard for their relative position. However, now they're part of a larger symbol. Any change to their relative position would disrupt this larger _array symbol and thus not be sound. This is the same reasoning used for data symbols. On their own there is no guarantee about their relative position wrt to one aonther, but we're still able to do arrays because an array as a whole is a single larger symbol. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Tested-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6fda8a3 commit 1a6f744

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <asm/msr-index.h>
1313
#include <asm/unwind_hints.h>
1414

15+
#define RETPOLINE_THUNK_SIZE 32
16+
1517
/*
1618
* Fill the CPU return stack buffer.
1719
*
@@ -120,11 +122,15 @@
120122

121123
#ifdef CONFIG_RETPOLINE
122124

125+
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];
126+
123127
#define GEN(reg) \
124-
extern asmlinkage void __x86_indirect_thunk_ ## reg (void);
128+
extern retpoline_thunk_t __x86_indirect_thunk_ ## reg;
125129
#include <asm/GEN-for-each-reg.h>
126130
#undef GEN
127131

132+
extern retpoline_thunk_t __x86_indirect_thunk_array[];
133+
128134
#ifdef CONFIG_X86_64
129135

130136
/*

arch/x86/lib/retpoline.S

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828

2929
.macro THUNK reg
3030

31-
.align 32
32-
33-
SYM_FUNC_START(__x86_indirect_thunk_\reg)
31+
.align RETPOLINE_THUNK_SIZE
32+
SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL)
33+
UNWIND_HINT_EMPTY
3434

3535
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
3636
__stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \
3737
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_AMD
3838

39-
SYM_FUNC_END(__x86_indirect_thunk_\reg)
40-
4139
.endm
4240

4341
/*
@@ -55,10 +53,16 @@ SYM_FUNC_END(__x86_indirect_thunk_\reg)
5553
#define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym)
5654
#define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg)
5755

56+
.align RETPOLINE_THUNK_SIZE
57+
SYM_CODE_START(__x86_indirect_thunk_array)
58+
5859
#define GEN(reg) THUNK reg
5960
#include <asm/GEN-for-each-reg.h>
6061
#undef GEN
6162

63+
.align RETPOLINE_THUNK_SIZE
64+
SYM_CODE_END(__x86_indirect_thunk_array)
65+
6266
#define GEN(reg) EXPORT_THUNK(reg)
6367
#include <asm/GEN-for-each-reg.h>
6468
#undef GEN

0 commit comments

Comments
 (0)