[PATCH 2/3] arm64: Re-enable kernel BTI for compatible linkers
Nick Desaulniers
ndesaulniers at google.com
Thu Nov 19 15:22:22 PST 2026
On Thu, Nov 19, 2026 at 8:58 AM Ard Biesheuvel <ardb+git at google.com> wrote:
>
> From: Ard Biesheuvel <ardb at kernel.org>
>
> The compiler is permitted to omit BTI landing pads from static functions
> that never have their address taken, but are only called directly, even
> if those calls originate from other code sections. This causes problems
> for calls from .init.text into .text if those sections are placed far
> apart, as veneers involving indirect calls will be used in that case.
>
> Now that .text and .init.text are combined, this can no longer happen,
> and so we can re-enable kernel mode BTI under two conditions:
>
> - live patch is disabled - it also needs BTI landings pads on functions
> with static linkage inside vmlinux that were never exported (and
> therefore never had their address taken)
>
> - landings pads are emitted even in pathological cases where the size of
> vmlinux's .text segment exceeds the range of a direct branch, and the
> linker needs to emit landing pads at the callee end so that the
> veneers can call them without causing a BTI fault.
>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
> arch/arm64/Kconfig | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 1075bc661833..f0fb2d7ff130 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -2202,18 +2202,23 @@ config ARM64_BTI
> BTI, such binaries can still run, but you get no additional
> enforcement of branch destinations.
>
> +config LD_HAS_BTI_STUBS
> + # A linker may need to insert a veneer when a call to a function with
> + # static linkage in the same compilation unit but in a different
> + # section is out of range for a direct branch instruction. Such a
> + # veneer performs an indirect call, and thus requires a landing pad
> + # under BTI, which the static function may lack. Only recent linkers
> + # are guaranteed to emit those landing pads correctly in all cases.
> + def_bool (LD_IS_BFD && LD_VERSION >= 24200) || \
> + (LD_IS_LLD && LLD_VERSION >= 200000)
A bit of a rock fetching quest (sorry), but it would make it easier
for reviewers to verify these version checks if you had git trailers
linking to commits (or bug reports) for these linkers with the
relevant fix. I don't think that necessitates a v2, if the
maintainers you're expecting to pick up this series are kind enough to
manually re-add them (unless b4 can pick up `Link:` trailers like
that).
> +
> config ARM64_BTI_KERNEL
> bool "Use Branch Target Identification for kernel"
> default y
> depends on ARM64_BTI
> depends on ARM64_PTR_AUTH_KERNEL
> depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI
> - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697
> - depends on !CC_IS_GCC || GCC_VERSION >= 100100
> - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671
> - depends on !CC_IS_GCC
> - # https://github.com/llvm/llvm-project/issues/215547
> - depends on !CC_IS_CLANG || CLANG_VERSION < 210000
> + depends on !LIVEPATCH && LD_HAS_BTI_STUBS
> depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_ARGS)
> help
> Build the kernel with Branch Target Identification annotations
> --
> 2.56.1.708.g77570a6a1d-goog
>
--
Thanks,
~Nick Desaulniers
More information about the linux-arm-kernel
mailing list