[PATCH v2 4/6] x86/rust: support MITIGATION_SLS

Miguel Ojeda posted 6 patches 1 year, 4 months ago
There is a newer version of this series
[PATCH v2 4/6] x86/rust: support MITIGATION_SLS
Posted by Miguel Ojeda 1 year, 4 months ago
Support `MITIGATION_SLS` by enabling the target features that Clang does.

Without this, `objtool` would complain if enabled for Rust, e.g.:

    rust/core.o: warning: objtool:
    _R...next_up+0x44: missing int3 after ret

These should be eventually enabled via `-Ctarget-feature` when `rustc`
starts recognizing them (or via a new dedicated flag) [1].

Link: https://github.com/rust-lang/rust/issues/116851 [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 scripts/generate_rust_target.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
index 44952f0a3aac..ba1bd455e160 100644
--- a/scripts/generate_rust_target.rs
+++ b/scripts/generate_rust_target.rs
@@ -173,6 +173,14 @@ fn main() {
             features += ",+retpoline-indirect-branches";
             features += ",+retpoline-indirect-calls";
         }
+        if cfg.has("MITIGATION_SLS") {
+            // The kernel uses `-mharden-sls=all`, which Clang maps to both these target features in
+            // `clang/lib/Driver/ToolChains/Arch/X86.cpp`. These should be eventually enabled via
+            // `-Ctarget-feature` when `rustc` starts recognizing them (or via a new dedicated
+            // flag); see https://github.com/rust-lang/rust/issues/116851.
+            features += ",+harden-sls-ijmp";
+            features += ",+harden-sls-ret";
+        }
         ts.push("features", features);
         ts.push("llvm-target", "x86_64-linux-gnu");
         ts.push("target-pointer-width", "64");
--
2.45.2
Re: [PATCH v2 4/6] x86/rust: support MITIGATION_SLS
Posted by Gary Guo 1 year, 4 months ago
On Wed, 24 Jul 2024 18:14:57 +0200
Miguel Ojeda <ojeda@kernel.org> wrote:

> Support `MITIGATION_SLS` by enabling the target features that Clang does.
> 
> Without this, `objtool` would complain if enabled for Rust, e.g.:
> 
>     rust/core.o: warning: objtool:
>     _R...next_up+0x44: missing int3 after ret
> 
> These should be eventually enabled via `-Ctarget-feature` when `rustc`
> starts recognizing them (or via a new dedicated flag) [1].
> 
> Link: https://github.com/rust-lang/rust/issues/116851 [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  scripts/generate_rust_target.rs | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
> index 44952f0a3aac..ba1bd455e160 100644
> --- a/scripts/generate_rust_target.rs
> +++ b/scripts/generate_rust_target.rs
> @@ -173,6 +173,14 @@ fn main() {
>              features += ",+retpoline-indirect-branches";
>              features += ",+retpoline-indirect-calls";
>          }
> +        if cfg.has("MITIGATION_SLS") {
> +            // The kernel uses `-mharden-sls=all`, which Clang maps to both these target features in
> +            // `clang/lib/Driver/ToolChains/Arch/X86.cpp`. These should be eventually enabled via
> +            // `-Ctarget-feature` when `rustc` starts recognizing them (or via a new dedicated
> +            // flag); see https://github.com/rust-lang/rust/issues/116851.
> +            features += ",+harden-sls-ijmp";
> +            features += ",+harden-sls-ret";
> +        }
>          ts.push("features", features);
>          ts.push("llvm-target", "x86_64-linux-gnu");
>          ts.push("target-pointer-width", "64");
> --
> 2.45.2