From: Ard Biesheuvel <ardb+git@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org,
Ard Biesheuvel <ardb@kernel.org>,
Mark Brown <broonie@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH 2/3] arm64: Re-enable kernel BTI for compatible linkers
Date: Thu, 19 Nov 2026 17:58:28 +0100 [thread overview]
Message-ID: <20261119165825.1793558-7-ardb+git@google.com> (raw)
In-Reply-To: <20261119165825.1793558-5-ardb+git@google.com>
From: Ard Biesheuvel <ardb@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@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)
+
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
next prev parent reply other threads:[~2026-11-19 16:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:58 [PATCH 0/3] arm64: Combine module .init.text with .text Ard Biesheuvel
2026-11-19 16:58 ` [PATCH 1/3] arm64: module: Keep executable init sections in the core text region Ard Biesheuvel
2026-11-19 16:58 ` Ard Biesheuvel [this message]
2026-11-19 16:58 ` [PATCH 3/3] arm64: module: Revert separate init PLT and init ftrace trampoline Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119165825.1793558-7-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jpoimboe@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=ndesaulniers@google.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox