-
Notifications
You must be signed in to change notification settings - Fork 14.1k
-Zharden-sls flag (target modifier) added to enable mitigation against straight line speculation (SLS) #136597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
azhogin
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
azhogin:azhogin/sls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Test harden-sls flag | ||
|
|
||
| #![feature(core_intrinsics)] | ||
| //@ revisions: NONE ALL RET IJMP | ||
| //@ assembly-output: emit-asm | ||
| //@ compile-flags: -Copt-level=3 -Cunsafe-allow-abi-mismatch=harden-sls | ||
| //@ [NONE] compile-flags: -Zharden-sls=none | ||
| //@ [ALL] compile-flags: -Zharden-sls=all | ||
| //@ [RET] compile-flags: -Zharden-sls=return | ||
| //@ [IJMP] compile-flags: -Zharden-sls=indirect-jmp | ||
| //@ only-x86_64 | ||
| #![crate_type = "lib"] | ||
|
|
||
| #[no_mangle] | ||
| pub fn double_return(a: i32, b: i32) -> i32 { | ||
| // CHECK-LABEL: double_return: | ||
| // CHECK: jle | ||
| // CHECK-NOT: int3 | ||
| // CHECK: retq | ||
| // RET-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // IJMP-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| // CHECK: retq | ||
| // RET-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // IJMP-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| if a > 0 { | ||
| unsafe { std::intrinsics::unchecked_div(a, b) } | ||
| } else { | ||
| unsafe { std::intrinsics::unchecked_div(b, a) } | ||
| } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub fn indirect_branch(a: i32, b: i32, i: i32) -> i32 { | ||
| // CHECK-LABEL: indirect_branch: | ||
| // CHECK: jmpq * | ||
| // RET-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| // IJMP-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // CHECK: retq | ||
| // RET-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // IJMP-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| // CHECK: retq | ||
| // RET-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // IJMP-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| match i { | ||
| 0 => unsafe { std::intrinsics::unchecked_div(a, b) }, | ||
| 1 => unsafe { std::intrinsics::unchecked_div(b, a) }, | ||
| 2 => unsafe { std::intrinsics::unchecked_div(b, a) + 2 }, | ||
| 3 => unsafe { std::intrinsics::unchecked_div(b, a) + 3 }, | ||
| 4 => unsafe { std::intrinsics::unchecked_div(b, a) + 4 }, | ||
| 5 => unsafe { std::intrinsics::unchecked_div(b, a) + 5 }, | ||
| 6 => unsafe { std::intrinsics::unchecked_div(b, a) + 6 }, | ||
| _ => panic!(""), | ||
| } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub fn bar(ptr: fn()) { | ||
| // CHECK-LABEL: bar: | ||
| // CHECK: jmpq * | ||
| // RET-NOT: int3 | ||
| // NONE-NOT: int3 | ||
| // IJMP-NEXT: int3 | ||
| // ALL-NEXT: int3 | ||
| // CHECK-NOT: ret | ||
| ptr() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // ignore-tidy-linelength | ||
| // Test that the `harden-sls-ijmp`, `harden-sls-ret` target features is (not) emitted when | ||
| // the `harden-sls=[none|all|return|indirect-jmp]` flag is (not) set. | ||
|
|
||
| //@ add-minicore | ||
| //@ revisions: none all return indirect_jmp | ||
| //@ needs-llvm-components: x86 | ||
| //@ compile-flags: --target x86_64-unknown-linux-gnu | ||
| //@ [none] compile-flags: -Zharden-sls=none | ||
| //@ [all] compile-flags: -Zharden-sls=all | ||
| //@ [return] compile-flags: -Zharden-sls=return | ||
| //@ [indirect_jmp] compile-flags: -Zharden-sls=indirect-jmp | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[no_mangle] | ||
| pub fn foo() { | ||
| // CHECK: @foo() unnamed_addr #0 | ||
|
|
||
| // none-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ijmp{{.*}} } | ||
| // none-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ret{{.*}} } | ||
|
|
||
| // all: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ijmp,+harden-sls-ret{{.*}} } | ||
|
|
||
| // return-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ijmp{{.*}} } | ||
| // return: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ret{{.*}} } | ||
|
|
||
| // indirect_jmp-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ret{{.*}} } | ||
| // indirect_jmp: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+harden-sls-ijmp{{.*}} } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think we were unclear. We don't want to change all instances of the "forbidden target feature" warning into hard errors, we just want this new instance of it to be a hard error.
The reason these are currently a warning is because of backwards compatibly where previous stable compilers allowed these features to be specified. However,
harden-slsis a new feature and so there isn't a backwards compatibility requirement. As such, it makes sense to treat invalid uses as a hard error rather than an ignorable warning.This probably means there needs to be a new level of
Stabilitythat generates an error instead of a warning and then you can use that instead ofStability::Forbidden.