]> git.ipfire.org Git - thirdparty/linux.git/commit
arm64: Use static call trampolines when kCFI is enabled
authorArd Biesheuvel <ardb@kernel.org>
Tue, 31 Mar 2026 11:04:23 +0000 (13:04 +0200)
committerCatalin Marinas <catalin.marinas@arm.com>
Wed, 1 Apr 2026 14:29:59 +0000 (15:29 +0100)
commit54ac9ff8f1196afc49d644a1625e0af1c9fcf7f5
tree58b6db80c4eba930c883cb655e5d27397453cad2
parent8c6e9b60f5c7985a9fe41320556a92d7a33451df
arm64: Use static call trampolines when kCFI is enabled

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>
arch/arm64/Kconfig
arch/arm64/include/asm/static_call.h [new file with mode: 0644]
arch/arm64/kernel/Makefile
arch/arm64/kernel/static_call.c [new file with mode: 0644]
arch/arm64/kernel/vmlinux.lds.S