Skip to content

Commit 8c03af3

Browse files
author
Peter Zijlstra
committed
x86,retpoline: Be sure to emit INT3 after JMP *%\reg
Both AMD and Intel recommend using INT3 after an indirect JMP. Make sure to emit one when rewriting the retpoline JMP irrespective of compiler SLS options or even CONFIG_SLS. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent bc12b70 commit 8c03af3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

arch/x86/kernel/alternative.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,15 @@ static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
453453
return ret;
454454
i += ret;
455455

456+
/*
457+
* The compiler is supposed to EMIT an INT3 after every unconditional
458+
* JMP instruction due to AMD BTC. However, if the compiler is too old
459+
* or SLS isn't enabled, we still need an INT3 after indirect JMPs
460+
* even on Intel.
461+
*/
462+
if (op == JMP32_INSN_OPCODE && i < insn->length)
463+
bytes[i++] = INT3_INSN_OPCODE;
464+
456465
for (; i < insn->length;)
457466
bytes[i++] = BYTES_NOP1;
458467

arch/x86/net/bpf_jit_comp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip)
419419
OPTIMIZER_HIDE_VAR(reg);
420420
emit_jump(&prog, &__x86_indirect_thunk_array[reg], ip);
421421
} else {
422-
EMIT2(0xFF, 0xE0 + reg);
422+
EMIT2(0xFF, 0xE0 + reg); /* jmp *%\reg */
423+
if (IS_ENABLED(CONFIG_RETPOLINE) || IS_ENABLED(CONFIG_SLS))
424+
EMIT1(0xCC); /* int3 */
423425
}
424426

425427
*pprog = prog;

0 commit comments

Comments
 (0)