rust: KASAN+RETHUNK requires rustc 1.83.0
Alice Ryhl
reviewerPATCH 1/1 rust: KASAN+RETHUNK requires rustc 1.83.0
When enabling both KASAN and RETHUNK, objtool emits the following warnings:
rust/core.o: warning: objtool: asan.module_ctor+0x13: 'naked' return found in MITIGATION_RETHUNK build
rust/core.o: warning: objtool: asan.module_dtor+0x13: 'naked' return found in MITIGATION_RETHUNK buildThis is caused by the -Zfunction-return=thunk-extern flag in rustc not properly informing LLVM about the mitigation, which means that the KASAN functions asan.module_ctor and asan.module_dtor are generated without the rethunk mitigation.
The other mitigations that we enabled for Rust (SLS, RETPOLINE) do not have the same bug, as they're being applied through the target-feature functionality instead.
This is being fixed for rustc 1.83.0, so update Kconfig to reject this configuration on older compilers.
--- init/Kconfig | 1 + 1 file changed, 1 insertion(+)
init/Kconfig +1 -0
@@ -1950,6 +1950,7 @@ config RUST select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG depends on !CALL_PADDING || RUSTC_VERSION >= 108100 depends on !KASAN_SW_TAGS + depends on !(MITIGATION_RETHUNK && KASAN) || RUSTC_VERSION >= 108300 help Enables Rust support in the kernel.
Signature · 1 line
2.46.0.792.g87dc391469-goog
Quoted 3 lines · Alice Ryhl
This is caused by the -Zfunction-return=thunk-extern flag in rustc not properly informing LLVM about the mitigation, which means that the KASAN
"...not informing LLVM about the mitigation at the module level (it does so at the function level only currently, which covers most cases, but both are required)" or similar?
Quoted 2 lines
This is being fixed for rustc 1.83.0, so update
Kconfigto reject this configuration on older compilers.
Yeah, let's go with 1.83.0 as we said -- we can modify it if needed later on. I think the PR is fairly straightforward so it should probably land in that version unless there is an unknown unknown.
Thanks Alice, looks good to me.
I will take this one soon.
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 9 lines · Miguel Ojeda
Quoted 3 lines · Alice Ryhl
This is caused by the -Zfunction-return=thunk-extern flag in rustc not properly informing LLVM about the mitigation, which means that the KASAN
"...not informing LLVM about the mitigation at the module level (it does so at the function level only currently, which covers most cases, but both are required)" or similar?
That phrasing SGTM.
Quoted 10 lines
Quoted 2 lines
This is being fixed for rustc 1.83.0, so update
Kconfigto reject this configuration on older compilers.Yeah, let's go with 1.83.0 as we said -- we can modify it if needed later on. I think the PR is fairly straightforward so it should probably land in that version unless there is an unknown unknown.
Thanks Alice, looks good to me.
I will take this one soon.
Thanks!
Alice
Miguel Ojeda
AppliedQuoted 16 lines · Alice Ryhl
When enabling both KASAN and RETHUNK, objtool emits the following warnings:
rust/core.o: warning: objtool: asan.module_ctor+0x13: 'naked' return found in MITIGATION_RETHUNK build rust/core.o: warning: objtool: asan.module_dtor+0x13: 'naked' return found in MITIGATION_RETHUNK buildThis is caused by the -Zfunction-return=thunk-extern flag in rustc not properly informing LLVM about the mitigation, which means that the KASAN functions asan.module_ctor and asan.module_dtor are generated without the rethunk mitigation.
The other mitigations that we enabled for Rust (SLS, RETPOLINE) do not have the same bug, as they're being applied through the target-feature functionality instead.
Quoted 8 lines
This is being fixed for rustc 1.83.0, so update
Kconfigto reject this configuration on older compilers.Fixes d7868550d573 ("x86/rust: support MITIGATION_RETHUNK")Reported-by Miguel Ojeda <[email protected]>Closes https://lore.kernel.org/all/CANiq72myZL4_poCMuNFevtpYYc0V0embjSuKb7y=C+m3vVA_8g@mail.gmail.com/ open hereSigned-off-by Alice Ryhl <[email protected]>
Applied to rust-fixes -- thanks!
Cheers,
Miguel