mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
Implement arm64 support for the 'unoptimized' static call variety, which routes all calls through a trampoline that performs a tail call to the chosen function, and wire it up for use when kCFI is enabled. This works around an issue with kCFI and generic static calls, where the prototypes of default handlers such as __static_call_nop() and __static_call_ret0() don't match the expected prototype of the call site, resulting in kCFI false positives [0]. Since static call targets may be located in modules loaded out of direct branching range, this needs an ADRP/LDR pair to load the branch target into R16 and a branch-to-register (BR) instruction to perform an indirect call. Unlike on x86, there is no pressing need on arm64 to avoid indirect calls at all cost, but hiding it from the compiler as is done here does have some benefits: - the literal is located in .rodata, which gives us the same robustness advantage that code patching does; - no D-cache pollution from fetching hash values from .text sections. From an execution speed PoV, this is unlikely to make any difference at all. Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Kees Cook <kees@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Will McVicker <willmcvicker@google.com> Reported-by: Carlos Llamas <cmllamas@google.com> Closes: https://lore.kernel.org/all/20260311225822.1565895-1-cmllamas@google.com/ [0] Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Will Deacon <will@kernel.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
24 lines
679 B
C
24 lines
679 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/static_call.h>
|
|
#include <linux/memory.h>
|
|
#include <asm/text-patching.h>
|
|
|
|
void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
|
|
{
|
|
u64 literal;
|
|
int ret;
|
|
|
|
if (!func)
|
|
func = __static_call_return0;
|
|
|
|
/* decode the instructions to discover the literal address */
|
|
literal = ALIGN_DOWN((u64)tramp + 4, SZ_4K) +
|
|
aarch64_insn_adrp_get_offset(le32_to_cpup(tramp + 4)) +
|
|
8 * aarch64_insn_decode_immediate(AARCH64_INSN_IMM_12,
|
|
le32_to_cpup(tramp + 8));
|
|
|
|
ret = aarch64_insn_write_literal_u64((void *)literal, (u64)func);
|
|
WARN_ON_ONCE(ret);
|
|
}
|
|
EXPORT_SYMBOL_GPL(arch_static_call_transform);
|