Skip to content

Commit 62be60f

Browse files
Peter Zijlstragregkh
authored andcommitted
x86/its: FineIBT-paranoid vs ITS
commit e52c1dc upstream. FineIBT-paranoid was using the retpoline bytes for the paranoid check, disabling retpolines, because all parts that have IBT also have eIBRS and thus don't need no stinking retpolines. Except... ITS needs the retpolines for indirect calls must not be in the first half of a cacheline :-/ So what was the paranoid call sequence: <fineibt_paranoid_start>: 0: 41 ba 78 56 34 12 mov $0x12345678, %r10d 6: 45 3b 53 f7 cmp -0x9(%r11), %r10d a: 4d 8d 5b <f0> lea -0x10(%r11), %r11 e: 75 fd jne d <fineibt_paranoid_start+0xd> 10: 41 ff d3 call *%r11 13: 90 nop Now becomes: <fineibt_paranoid_start>: 0: 41 ba 78 56 34 12 mov $0x12345678, %r10d 6: 45 3b 53 f7 cmp -0x9(%r11), %r10d a: 4d 8d 5b f0 lea -0x10(%r11), %r11 e: 2e e8 XX XX XX XX cs call __x86_indirect_paranoid_thunk_r11 Where the paranoid_thunk looks like: 1d: <ea> (bad) __x86_indirect_paranoid_thunk_r11: 1e: 75 fd jne 1d __x86_indirect_its_thunk_r11: 20: 41 ff eb jmp *%r11 23: cc int3 [ dhansen: remove initialization to false ] Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> [ Just a portion of the original commit, in order to fix a build issue in stable kernels due to backports ] Tested-by: Holger Hoffstätte <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 36ae9d4 commit 62be60f

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

arch/x86/include/asm/alternative.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/stringify.h>
77
#include <linux/objtool.h>
88
#include <asm/asm.h>
9+
#include <asm/bug.h>
910

1011
#define ALT_FLAGS_SHIFT 16
1112

@@ -129,10 +130,17 @@ static __always_inline int x86_call_depth_emit_accounting(u8 **pprog,
129130
extern void its_init_mod(struct module *mod);
130131
extern void its_fini_mod(struct module *mod);
131132
extern void its_free_mod(struct module *mod);
133+
extern u8 *its_static_thunk(int reg);
132134
#else /* CONFIG_MITIGATION_ITS */
133135
static inline void its_init_mod(struct module *mod) { }
134136
static inline void its_fini_mod(struct module *mod) { }
135137
static inline void its_free_mod(struct module *mod) { }
138+
static inline u8 *its_static_thunk(int reg)
139+
{
140+
WARN_ONCE(1, "ITS not compiled in");
141+
142+
return NULL;
143+
}
136144
#endif
137145

138146
#if defined(CONFIG_MITIGATION_RETHUNK) && defined(CONFIG_OBJTOOL)

arch/x86/kernel/alternative.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ static void *its_allocate_thunk(int reg)
248248
return thunk;
249249
}
250250

251+
u8 *its_static_thunk(int reg)
252+
{
253+
u8 *thunk = __x86_indirect_its_thunk_array[reg];
254+
255+
return thunk;
256+
}
257+
251258
#endif
252259

253260
/*

arch/x86/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip)
657657

658658
if (cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS)) {
659659
OPTIMIZER_HIDE_VAR(reg);
660-
emit_jump(&prog, &__x86_indirect_its_thunk_array[reg], ip);
660+
emit_jump(&prog, its_static_thunk(reg), ip);
661661
} else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
662662
EMIT_LFENCE();
663663
EMIT2(0xFF, 0xE0 + reg);

0 commit comments

Comments
 (0)