x86/retpoline,kprobes: Skip optprobe check for indirect jumps with retpolines and IBT
authorPetr Pavlu <petr.pavlu@suse.com>
Tue, 11 Jul 2023 09:19:52 +0000 (11:19 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 14 Aug 2023 09:46:51 +0000 (11:46 +0200)
commit833fd800bf56b74d39d71d3f5936dffb3e0409c6
treee159f0bdbe8bdf91f369946d376b9978d15ad021
parent79cd2a11224eab86d6673fe8a11d2046ae9d2757
x86/retpoline,kprobes: Skip optprobe check for indirect jumps with retpolines and IBT

The kprobes optimization check can_optimize() calls
insn_is_indirect_jump() to detect indirect jump instructions in
a target function. If any is found, creating an optprobe is disallowed
in the function because the jump could be from a jump table and could
potentially land in the middle of the target optprobe.

With retpolines, insn_is_indirect_jump() additionally looks for calls to
indirect thunks which the compiler potentially used to replace original
jumps. This extra check is however unnecessary because jump tables are
disabled when the kernel is built with retpolines. The same is currently
the case with IBT.

Based on this observation, remove the logic to look for calls to
indirect thunks and skip the check for indirect jumps altogether if the
kernel is built with retpolines or IBT. Remove subsequently the symbols
__indirect_thunk_start and __indirect_thunk_end which are no longer
needed.

Dropping this logic indirectly fixes a problem where the range
[__indirect_thunk_start, __indirect_thunk_end] wrongly included also the
return thunk. It caused that machines which used the return thunk as
a mitigation and didn't have it patched by any alternative ended up not
being able to use optprobes in any regular function.

Fixes: 0b53c374b9ef ("x86/retpoline: Use -mfunction-return")
Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Suggested-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20230711091952.27944-3-petr.pavlu@suse.com
arch/x86/include/asm/nospec-branch.h
arch/x86/kernel/kprobes/opt.c
arch/x86/kernel/vmlinux.lds.S
tools/perf/util/thread-stack.c