From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221432; b=2Q2NjabDkB48/5hU4b6EUBEtp/LOSgyPbV3XHEEeO4sa7nsm+w54WK9QPsEuW5NpeKZ+ ROO8+F+B2nXl06iSja/en/Iw95GwOVGiS4axsB/zpyzQVh2qyH0mF/i7H/Z08jwy+O3BC Fk3TAm1w9HuwjtMrCU71kH+s1cNwDNJuPseNS3APxLNO0gHCYHLbhIbttQvXwsuvT4Xaw 4mM55/HIHXdjqmWmvIRzv0XxwmKVXRe1XuTg76BcYiOoy7JcdUQ2nYJU6AOuVEKp3/piw e6kkcyCKKeYrIORDc+NdHzNYpJH6nYOpYcSYoHOfRv2HWFEFDeHlUCWrE9EgdD/iyPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221432; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=9moMM4nuLB4oZ8zL4S5jAcFiNh6XabV3k/peTsCqvXM=; b=tQ3Gko0q8lxUcck+RMyftqZ7tNr0hCgDBFK6imrSBJaxAkOsi7DagI8nbMoCV/QUB3i5 MyoGMA93eePwNDohhP64AKHwTX8d9EtjobpUCODLYzADqAh6io9Job+CtWJ+hwpBo5Kdh V5HIj5Jc3x6K1UP3NZRUnWFs/PGp5YRkh9bot9Zltcj+RMcWtksG0KL0l2Z+L7BKqbXm0 GyO7HovvkmIgPl/CKcJtbHWLDfNhGXrdkwK0d/yZXergmDNs77iWK290AHJQwO2YAFmM7 avg9rhICR1u8NO1E6rpEua2UwyuuJPLK55cPcVwz338eaNXa9n6lHTzZ27GRZiA1uXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UkNtoYtF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CBD5606A322 for ; Wed, 2 Dec 2026 14:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UkNtoYtF Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6A771F000C1; Wed, 2 Dec 2026 14:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221432; bh=9moMM4nuLB4oZ8zL4S5jAcFiNh6XabV3k/peTsCqvXM=; h=Subject:To:Cc:From:Date; b=UkNtoYtFSA/lOYLW0TBwiWIW4mke7hrDir8nWjxSlyHh4Yjo8OaE7GXbg25V7LH// 8QTyVz9mgZGZsyUih6vevwBCmb1ILMUvfpolwUB971CdflhurjJx+MGeV6gMTGwsBE TxFOZfn+frLP6njfZFEKon3LucaJDbSxaYoIC8lE= Subject: FAILED: patch "[PATCH] x86/rust: use `-Zindirect-branch-cs-prefix` for RETPOLINE" failed to apply to 7.3-stable tree To: ojeda@kernel.org,bp@alien8.de,kent.overstreet@linux.dev Cc: From: Date: Wed, 02 Dec 2026 14:47:30 +0100 Message-ID: <2026120230-lifter-vowel-c965@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 7.3-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.3.y git checkout FETCH_HEAD git cherry-pick -x 1eaa31fa41125db78a50abef7f0a35aa22af40d0 # git commit -s git send-email --to '' --in-reply-to '2026120230-lifter-vowel-c965@gregkh' --subject-prefix 'PATCH 7.3.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 1eaa31fa41125db78a50abef7f0a35aa22af40d0 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 18 Oct 2026 19:54:57 +0200 Subject: [PATCH] x86/rust: use `-Zindirect-branch-cs-prefix` for RETPOLINE builds The C compiler is asked to add a `cs` prefix to the `call` and `jmp` instructions that go through the indirect thunks for the `r8`-`r15` registers, which makes them 6 bytes long instead of 5. That gives `patch_retpoline()` enough room to inline them, e.g. as `lfence; call *%r11` for `spectre_v2=retpoline,lfence`. However, Rust code does not get the prefix, e.g. for a `CONFIG_MITIGATION_RETPOLINE=y` build: $ objdump -dr rust/kernel.o ... e2b: e8 00 00 00 00 call e30 <...> e2c: R_X86_64_PLT32 __x86_indirect_thunk_r11-0x4 Moreover, since commit 4a1e02b15ac1 ("x86,retpoline: Optimize patch_retpoline()"), `emit_indirect()` assumes there is enough room for the inlined sequence -- e.g. with `spectre_v2=retpoline,lfence`, the kernel warns and dies while patching a site inside `core`: WARNING: arch/x86/kernel/alternative.c:736 at apply_retpolines+0x2ee/0x400, CPU#0: swapper/0/0 ... Call Trace: ? _RNvMs6_NtNtCshS2CUL9MEDn_4core3fmt8buildersNtB5_9DebugList21finish_non_exhaustive+0x5b/0xd0 ... alternative_instructions+0x1d/0x60 arch_cpu_finalize_init+0x5a/0xb0 start_kernel+0x1f4/0x280 Similarly, paranoid FineIBT rewrites each kCFI call site into a fixed 20-byte sequence, i.e. the 14 bytes of the kCFI check plus a 6-byte call. For a 5-byte call, that overwrites the first byte of the next instruction, corrupting Rust code: SMP alternatives: Using paranoid FineIBT CFI ... Oops: double fault: 0000 [#1] ... RIP: 0010:_RNvNtCsdVypMZsLRAh_4core3fmt5write+0x1e9/0x210 Code: ... b8 68 81 16 9f 41 3b 43 f5 2e 4d 8d 5b f0 75 fd 41 ff e3 c0 eb 02 b0 01 ... ... Kernel panic - not syncing: Fatal exception in interrupt Non-paranoid FineIBT is not affected, since it only rewrites the kCFI check and leaves the call itself to `apply_retpolines()`. We added support for `-Zindirect-branch-cs-prefix` [1][2] in Rust 1.91.0 [3]. Thus pass it for `RETPOLINE` builds when possible, which makes all sites indeed get the prefix: e3c: 2e e8 00 00 00 00 cs call e42 <...> e3e: R_X86_64_PLT32 __x86_indirect_thunk_r11-0x4 The kernel above boots fine with `spectre_v2=retpoline,lfence`, inlining the Rust sites as well. For older Rust compilers, set the LLVM module flag instead, which has the same code-generation effect. This means that every Rust version that the kernel supports gets the prefix, that the kernel boots fine with `spectre_v2=retpoline,lfence`, and that paranoid FineIBT no longer corrupts. In addition, add it to our target modifier workaround for `rustdoc`. Cc: stable@vger.kernel.org # 6.18.y+ Link: https://github.com/rust-lang/rust/issues/116852 [1] Link: https://github.com/rust-lang/compiler-team/issues/899 [2] Link: https://github.com/rust-lang/rust/pull/140740 [3] Reported-by: Kent Overstreet Acked-by: Borislav Petkov Link: https://patch.msgid.link/20261018175457.87803-1-ojeda@kernel.org Signed-off-by: Miguel Ojeda diff --git a/arch/x86/Makefile b/arch/x86/Makefile index b7e08519b8c1..83b07961b850 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -21,6 +21,7 @@ RETPOLINE_CFLAGS := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := -mretpoline endif RETPOLINE_CFLAGS += $(CONFIG_CC_OPT_INDIRECT_BRANCH_CS_PREFIX) +RETPOLINE_RUSTFLAGS += $(if $(call rustc-min-version,109100),-Zindirect-branch-cs-prefix,-Zllvm_module_flag=indirect_branch_cs_prefix:u32:1:override) ifdef CONFIG_MITIGATION_RETHUNK RETHUNK_CFLAGS := -mfunction-return=thunk-extern diff --git a/rust/Makefile b/rust/Makefile index 0165626decbe..6dceabbf02c8 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -167,7 +167,7 @@ pin_init-flags := \ rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18) # Similarly, for doctests (https://github.com/rust-lang/rust/issues/146465). -doctests_modifiers_workaround := $(rustdoc_modifiers_workaround)$(if $(call rustc-min-version,109100),$(comma)sanitizer) +doctests_modifiers_workaround := $(rustdoc_modifiers_workaround)$(if $(call rustc-min-version,109100),$(comma)sanitizer$(comma)indirect-branch-cs-prefix) quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $< cmd_rustdoc = \