You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SRSO] ld.lld fails with "at least one side of the expression must be absolute" after SRSO mitigation #1907
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
With LTO enabled, I additionally see:
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
113499: ffffffff81d04104 6 FUNC GLOBAL DEFAULT 1 srso_safe_ret_alias
148347: ffffffff81c00000 10 FUNC GLOBAL DEFAULT 1 srso_untrain_ret_alias
is what's expected. I suspect that . = srso_untrain_ret_alias | (1 << 2) | (1 << 8) | (1 << 14) | (1 << 20); is trying to place srso_safe_ret_alias0x104104 bytes after srso_untrain_ret_alias.
Or rather than deal with symbols in the linker script, I think srso_safe_ret_alias is in its own section (.text.__x86.rethunk_safe) and so is srso_untrain_ret_alias (.text.__x86.rethunk_untrain). Maybe it's easier to specify alignment between these two sections in linkerscript.
I'm thinking this might work. 0x104104 is the magic constant ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)). I don't yet understand why 0x14 is necessary (some kind of function or symbol alignment, perhaps).
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e76813230192..4715c7a4cc31 100644
--- a/arch/x86/kernel/vmlinux.lds.S+++ b/arch/x86/kernel/vmlinux.lds.S@@ -146,15 +146,6 @@ SECTIONS
#endif
ENTRY_TEXT
--#ifdef CONFIG_CPU_SRSO- /*- * See the comment above srso_untrain_ret_alias()'s- * definition.- */- . = srso_untrain_ret_alias | (1 << 2) | (1 << 8) | (1 << 14) | (1 << 20);- *(.text.__x86.rethunk_safe)-#endif
ALIGN_ENTRY_TEXT_END
*(.gnu.warning)
@@ -532,9 +523,14 @@ INIT_PER_CPU(irq_stack_backing_store);
* GNU ld cannot do XOR so do: (A | B) - (A & B) in order to compute the XOR
* of the two function addresses:
*/
+#ifdef CONFIG_LD_IS_BFD
. = ASSERT(((srso_untrain_ret_alias | srso_safe_ret_alias) -
(srso_untrain_ret_alias & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
"SRSO function pair won't alias");
+#else+. = ASSERT(srso_untrain_ret_alias ^ srso_safe_ret_alias == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),+ "SRSO function pair won't alias");+#endif
#endif
#endif /* CONFIG_X86_64 */
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index 2cff585f22f2..f1ae299db60b 100644
--- a/arch/x86/lib/retpoline.S+++ b/arch/x86/lib/retpoline.S@@ -157,8 +157,7 @@ SYM_START(srso_untrain_ret_alias, SYM_L_GLOBAL, SYM_A_NONE)
jmp __x86_return_thunk
SYM_FUNC_END(srso_untrain_ret_alias)
__EXPORT_THUNK(srso_untrain_ret_alias)
-- .section .text.__x86.rethunk_safe+.fill (. - srso_untrain_ret_alias + 0x104104 - 0x14), 1, 0xcc
#endif
/* Needs a definition for the __x86_return_thunk alternative below. */
The idea is rather than try to have the linker place one section relative to another, have the assembler place the symbols a specific distance apart.
I'll need to bisect lld to see when this starts working.
Another problem with my approach is that I suspect the original patch is trying to keep srso_safe_ret_alias on one side of ENTRY_TEXT; if ENTRY_TEXT is larger than .text.__x86.rethunk_untrain + 0x104104 that seems like a problem.
Not sure if helps, but: The ^ and ^= operators where added in the release/17.x branch w/ llvm/llvm-project@fae9610.
@nickdesaulniers: With your changes to retpoline.S do we really need to check for CONFIG_LD_IS_BFD? The original ASSERT() should still work, although with ABSOLUTE():
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 8f06ab08f51e..d4c5040410de 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -509,8 +509,8 @@ INIT_PER_CPU(irq_stack_backing_store);
* GNU ld cannot do XOR so do: (A | B) - (A & B) in order to compute the XOR
* of the two function addresses:
*/
-. = ASSERT(((srso_untrain_ret_alias | srso_safe_ret_alias) -
- (srso_untrain_ret_alias & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
+. = ASSERT(((ABSOLUTE(srso_untrain_ret_alias) | srso_safe_ret_alias) -
+ (ABSOLUTE(srso_untrain_ret_alias) & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
"SRSO function pair won't alias");
#endif
@sinkap is reporting that maybe isn't working for older releases of lld though. I checked out release/11.x and built lld, and could reproduce:
Not sure if helps, but: The ^ and ^= operators where added in the release/17.x branch w/ llvm/llvm-project@fae9610.
Yes, thank you; you've saved me a bisection.
@nickdesaulniers: With your changes to retpoline.S do we really need to check for CONFIG_LD_IS_BFD? The original ASSERT() should still work, although with ABSOLUTE():
Ah, nice! That BFD condition is itself a workaround since (as the commit you linked to points out) BFD only gained xor support very very recently.
Good find. I'll keep an eye on how that's progressing to see if we need something to land sooner than that.
I browsed that series and I don't see how this issue would disappear, the code in arch/x86/kernel/vmlinux.lds.S is largely untouched from what I can tell.
For the record, our matrix will go super red, as stable released the patches at the same time as mainline.
I was not able to apply that series with b4 shazam for some reason, patch 11 does not apply cleanly... but I was able to grab it from Peter's repo and yeah, this issue is still present:
$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 defconfig vmlinux
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
# Turn on CONFIG_LTO_CLANG_THIN in menuconfig
$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 defconfig menuconfig vmlinux
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:35: unable to move location counter backward for: .text
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:203: at least one side of the expression must be absolute
ld.lld: error: ./arch/x86/kernel/vmlinux.lds:204: at least one side of the expression must be absolute
ld.lld: error: SRSO function pair won't alias
Activity
nickdesaulniers commentedon Aug 8, 2023
cc @MaskRay
nickdesaulniers commentedon Aug 8, 2023
Edit: looks like we need to keep a specific distance (of 0x104104 B) between these two symbols:
nickdesaulniers commentedon Aug 8, 2023
Boris on IRC says:
is what's expected. I suspect that
. = srso_untrain_ret_alias | (1 << 2) | (1 << 8) | (1 << 14) | (1 << 20);is trying to placesrso_safe_ret_alias0x104104bytes aftersrso_untrain_ret_alias.nickdesaulniers commentedon Aug 8, 2023
I think we can do the padding in assembler.
Or rather than deal with symbols in the linker script, I think
srso_safe_ret_aliasis in its own section (.text.__x86.rethunk_safe) and so issrso_untrain_ret_alias(.text.__x86.rethunk_untrain). Maybe it's easier to specify alignment between these two sections in linkerscript.nickdesaulniers commentedon Aug 9, 2023
I'm thinking this might work.
0x104104is the magic constant((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)). I don't yet understand why0x14is necessary (some kind of function or symbol alignment, perhaps).The idea is rather than try to have the linker place one section relative to another, have the assembler place the symbols a specific distance apart.
nickdesaulniers commentedon Aug 9, 2023
#1907 (comment) works for me, boots, and is 0x104104 apart in both cases.
Besides fixing those awful hex magic constants, another concern is this comment:
arch/x86/lib/retpoline.S:139
uh, under defconfig maybe, but under CONFIG_LTO_CLANG_THIN=y I don't think so.
Also,
SYM_START(srso_safe_ret_alias, SYM_L_GLOBAL, SYM_A_NONE)->SYM_FUNC_START_NOALIGN(srso_safe_ret_alias)By grace of god that works for gcc 12.2 and binutils 2.40.
@sinkap is reporting that maybe isn't working for older releases of lld though. I checked out release/11.x and built lld, and could reproduce:
I'll need to bisect lld to see when this starts working.
Another problem with my approach is that I suspect the original patch is trying to keep
srso_safe_ret_aliason one side ofENTRY_TEXT; ifENTRY_TEXTis larger than.text.__x86.rethunk_untrain+0x104104that seems like a problem.q66 commentedon Aug 9, 2023
i get the same error on lld 16:
main/linux-lts/stable: temporarily disable amd srso mitigation
thyrc commentedon Aug 9, 2023
Not sure if helps, but: The ^ and ^= operators where added in the release/17.x branch w/ llvm/llvm-project@fae9610.
@nickdesaulniers: With your changes to retpoline.S do we really need to check for CONFIG_LD_IS_BFD? The original ASSERT() should still work, although with ABSOLUTE():
I got
Edit: Insert diff
q66 commentedon Aug 9, 2023
there is also a large patchset overhauling this code: https://lore.kernel.org/lkml/[email protected]/
besides other things this removes
CONFIG_CPU_SRSOentirely, i wonder what effect it has on the buildnickdesaulniers commentedon Aug 9, 2023
Yes, thank you; you've saved me a bisection.
Ah, nice! That BFD condition is itself a workaround since (as the commit you linked to points out) BFD only gained xor support very very recently.
Good find. I'll keep an eye on how that's progressing to see if we need something to land sooner than that.
nathanchance commentedon Aug 9, 2023
I browsed that series and I don't see how this issue would disappear, the code in
arch/x86/kernel/vmlinux.lds.Sis largely untouched from what I can tell.For the record, our matrix will go super red, as stable released the patches at the same time as mainline.
nathanchance commentedon Aug 9, 2023
I was not able to apply that series with
b4 shazamfor some reason, patch 11 does not apply cleanly... but I was able to grab it from Peter's repo and yeah, this issue is still present:63 remaining items
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
Linux 5.15.127
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker
x86/srso: Fix build breakage with the LLVM linker